-
Notifications
You must be signed in to change notification settings - Fork 0
/
iptables.sh
113 lines (85 loc) · 3.42 KB
/
iptables.sh
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# select tables you use
#
FILTER="yes"
NAT="no"
MANGLE="no"
RAW="no"
SECURITY="no"
apply_filter_table(){
local IPTABLES="/sbin/iptables -t filter"
$IPTABLES -F
$IPTABLES -X
$IPTABLES -Z
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A INPUT -p icmp -s 192.168.11.0/24 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p tcp -s 192.168.11.0/24 --dport 22 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p udp -s 192.168.11.0/24 --dport 53 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p tcp -s 192.168.11.0/24 --dport 53 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p tcp -s 192.168.11.0/24 --dport 80 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p udp -s 192.168.11.0/24 --dport 161 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p tcp -s 192.168.11.0/24 --dport 443 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p tcp -s 192.168.11.0/24 --dport 2049 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A OUTPUT -p icmp -d 0.0.0.0/0 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -d 0.0.0.0/0 --dport 22 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -d 0.0.0.0/0 --dport 25 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p udp -d 0.0.0.0/0 --dport 53 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -d 0.0.0.0/0 --dport 53 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p udp -d 0.0.0.0/0 --dport 67 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -d 0.0.0.0/0 --dport 80 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p udp -d 0.0.0.0/0 --dport 123 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -d 0.0.0.0/0 --dport 123 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -d 0.0.0.0/0 --dport 443 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p udp -d 0.0.0.0/0 --dport 33434:33534 -m state --state NEW -j ACCEPT
}
apply_nat_table(){
local IPTABLES="/sbin/iptables -t nat"
$IPTABLES -F
$IPTABLES -X
$IPTABLES -Z
$IPTABLES -P PREROUTING ACCEPT
$IPTABLES -P POSTROUTING ACCEPT
$IPTABLES -P OUTPUT ACCEPT
}
apply_mangle_table(){
local IPTABLES="/sbin/iptables -t mangle"
$IPTABLES -F
$IPTABLES -X
$IPTABLES -Z
$IPTABLES -P PREROUTING ACCEPT
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P POSTROUTING ACCEPT
}
apply_raw_table(){
local IPTABLES="/sbin/iptables -t raw"
$IPTABLES -F
$IPTABLES -X
$IPTABLES -Z
$IPTABLES -P PREROUTING ACCEPT
$IPTABLES -P OUTPUT ACCEPT
}
apply_security_table(){
local IPTABLES="/sbin/iptables -t security"
$IPTABLES -F
$IPTABLES -X
$IPTABLES -Z
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P PREROUTING ACCEPT
$IPTABLES -P OUTPUT ACCEPT
}
#
# main
#
[ "x${FILTER}" == "xyes" ] && apply_filter_table
[ "x${NAT}" == "xyes" ] && apply_nat_table
[ "x${MANGLE}" == "xyes" ] && apply_mangle_table
[ "x${RAW}" == "xyes" ] && apply_raw_table
[ "x${SECURITY}" == "xyes" ] && apply_security_table
/usr/libexec/iptables/iptables.init save