-
Notifications
You must be signed in to change notification settings - Fork 0
/
iptables.sh.tftpl
93 lines (71 loc) · 2.13 KB
/
iptables.sh.tftpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -x
sleep 60
echo -e "nat conf start"
# Enable ip forwarding
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p
# Flush existing iptables rules
iptables -t nat -F
iptables -F
# Looping over vnets
for vnet in ${FW_VNET_CIDRS}
do
iptables -t nat -A POSTROUTING -s "$vnet" -o eth0 -j MASQUERADE
iptables -A FORWARD -s "$vnet" -o eth0 -j ACCEPT
iptables -A FORWARD -d "$vnet" -m state --state ESTABLISHED,RELATED -i eth0 -j ACCEPT
iptables -A INPUT -s "$vnet" -j ACCEPT
done
iptables -A INPUT -m state --state INVALID -j DROP
echo -e "nat conf end"
echo -e "install iptables persistent"
iptables_path="/etc/iptables"
if [ ! -d "$iptables_path" ]; then
mkdir -p "$iptables_path"
echo "Directory created: $iptables_path"
else
echo "Directory already exists: $iptables_path"
fi
/sbin/iptables-save > /etc/iptables/rules.v4
cat /etc/iptables/rules.v4
apt update
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | debconf-set-selections
apt install -y iptables-persistent
echo "/sbin/iptables-restore < /etc/iptables/rules.v4" >> /etc/rc.local
iptables -L
iptables -L -t nat
echo -e "nat Config done"
# DNS
echo -e "DNS Config start"
apt install -y bind9
cat << 'EOF' > /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
listen-on port 53 { any; };
auth-nxdomain no;
recursion yes;
allow-query-cache { localhost; 127.0.0.1; ${DNS_VNET_CIDRS};};
allow-recursion { localhost; 127.0.0.1; ${DNS_VNET_CIDRS};};
allow-query { 127.0.0.1; ${DNS_VNET_CIDRS};};
forwarders {
${DEFAULT_DNS};
};
forward first;
dnssec-validation ${DNSSEC_VALIDATION};
};
EOF
cat << 'EOF' > /etc/bind/named.conf.local
%{ for k,v in DNS_ZONES }
zone "${k}" IN {
type forward;
forward only;
forwarders { ${v}; };
};
%{ endfor ~}
EOF
service bind9 restart
echo $(systemctl status bind9)
echo -e "DNS Config done"
echo -e "Done!"