postfix/service-install.sh

raw link view readme
1 yum install firewalld -y
2 systemctl start firewalld
3 systemctl enable firewalld
4 firewall-cmd --permanent --zone=public --add-interface=eth0
5 firewall-cmd --permanent --add-service=dns --zone=public
6 firewall-cmd --permanent --add-service=smtp --zone=public
7 firewall-cmd --reload
8
9 yum install -y bind bind-utils
10
11 sed -i.original "s/listen-on port 53 { 127.0.0.1; };/listen-on port 53 { 127.0.0.1; 10.18.0.5; };/" /etc/named.conf
12 sed -i "s/allow-query { localhost; };/allow-query { localhost; 10.18.0.0\/16; };\n forwarders {\n 168.63.129.16;\n 8.8.8.8;\n 8.8.4.4;\n };/" /etc/named.conf
13 sed -i "s/listen-on-v6 port.*/listen-on-v6 port 53 { none; };/" /etc/named.conf
14 sed -i "/dnssec/d" /etc/named.conf
15
16 sed -i "s/PEERDNS=.*/PEERDNS=no/" /etc/sysconfig/network-scripts/ifcfg-eth0
17 sed -i "s/nameserver.*/nameserver 127.0.0.1/" /etc/resolv.conf
18
19 cat >> /etc/named.conf << EOF
20 zone "lab.example.net." IN {
21 type master;
22 file "db.lab.example.net";
23 allow-transfer { none; };
24 };
25 EOF
26
27 echo "10.18.0.5 ns1.lab.example.net" >> /etc/hosts
28
29 cat > /var/named/db.lab.example.net <<\EOF
30 $TTL 3H
31 $ORIGIN lab.example.net.
32 @ IN SOA ns1.lab.example.net root.lab.example.net (2
33 1D
34 1H
35 1W
36 3H)
37 @ NS ns1.lab.example.net.
38 ns1 A 10.18.0.5
39 alpha A 10.18.0.5
40 beta A 10.18.0.6
41 @ MX 10 alpha
42 EOF
43
44 systemctl restart named
45 systemctl enable named
46
47 yum install postfix -y
48
49 cp /etc/postfix/main.cf /etc/postfix/main.cf.$(date +%F)
50 postconf -e inet_protocols=ipv4
51 postconf -e inet_interfaces=all
52 postconf -e 'mydestination=lab.example.net, $myhostname, localhost.$mydomain, localhost'
53 postconf -e 'mydomain=lab.example.net'
54 postconf -e 'myorigin=$mydomain'
55
56 # ddos protection
57 #+ cf. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security_Guide/sect-Security_Guide-Server_Security-Securing_Postfix.html
58 #+ cf. http://security-24-7.com/hardening-guide-for-postfix-2-x/
59 postconf -e "default_process_limit = 100"
60 postconf -e "smtpd_client_connection_count_limit = 10"
61 postconf -e "smtpd_client_connection_rate_limit = 30"
62 postconf -e "queue_minfree = 20971520"
63 postconf -e "header_size_limit = 51200"
64 postconf -e "message_size_limit = 10485760"
65 postconf -e "smtpd_recipient_limit = 100"
66
67 systemctl restart postfix
68
69 sed -i "s/^#root.*/root: dbetz/" /etc/aliases
70 newaliases
71
72 #+ to read mail
73 yum install mailx -y
74