-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions.sh
executable file
·136 lines (110 loc) · 2.65 KB
/
functions.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
forward_to_outside()
{
proto=$1
port=$2
if [ "$3" ]
then
src_restrict="-i $OUTSIDE_IF -s $3"
dst_restrict="-o $OUTSIDE_IF -d $3"
else
src_restrict=$FROM_OUTSIDE
dst_restrict=$TO_OUTSIDE
fi
iptables -A FORWARD -p $proto --dport $port \
$FROM_INSIDE $dst_restrict \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A FORWARD -p $proto --sport $port \
$src_restrict $TO_INSIDE \
-m state --state ESTABLISHED -j ACCEPT
}
forward_to_inside()
{
proto=$1
port=$2
iptables -A FORWARD -p $proto --dport $port \
$FROM_OUTIDE $TO_INSIDE \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A FORWARD -p $proto --sport $port \
$FROM_INSIDE $TO_OUTSIDE \
-m state --state ESTABLISHED -j ACCEPT
}
accept_from_outside()
{
proto=$1
port=$2
iptables -A INPUT -p $proto --dport $port \
$FROM_OUTSIDE \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p $proto --sport $port \
$TO_OUTSIDE \
-m state --state ESTABLISHED -j ACCEPT
}
accept_from_inside()
{
proto=$1
port=$2
iptables -A INPUT -p $proto --dport $port \
$FROM_INSIDE \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p $proto --sport $port \
$TO_INSIDE \
-m state --state ESTABLISHED -j ACCEPT
}
accept_from_dmz()
{
proto=$1
port=$2
iptables -A INPUT -p $proto --dport $port \
$FROM_DMZ \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p $proto --sport $port \
$TO_DMZ \
-m state --state ESTABLISHED -j ACCEPT
}
allow_to_outside()
{
proto=$1
port=$2
iptables -A OUTPUT -p $proto --dport $port \
$TO_OUTSIDE \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p $proto --sport $port \
$FROM_OUTSIDE \
-m state --state ESTABLISHED -j ACCEPT
}
allow_to_inside()
{
proto=$1
port=$2
iptables -A OUTPUT -p $proto --dport $port \
$TO_INSIDE \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p $proto --sport $port \
$FROM_INSIDE \
-m state --state ESTABLISHED -j ACCEPT
}
forward_host_to_outside() # host [proto port]
{
host=$1
proto=$2
port=$3
if [ "$proto" ] && [ "$port" ]
then
out_dport_restrict="-p $proto --dport $port"
in_sport_restrict="-p $proto --sport $port"
else
out_dport_restrict=""
in_sport_restrict=""
fi
iptables -A FORWARD \
$out_dport_restrict \
-i $INSIDE_IF -s $host \
$TO_OUTSIDE \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A FORWARD \
$in_sport_restrict \
-o $INSIDE_IF -d $host \
$FROM_OUTSIDE \
-m state --state ESTABLISHED -j ACCEPT
}