]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/firewall
94b869dd6b9d7bea35cea0a6aec8d68e23bf3d9f
3 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
4 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
5 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/optionsfw
/settings
)
6 IFACE
=`/bin/cat /var/ipfire/red/iface 2> /dev/null | /usr/bin/tr -d '\012'`
8 if [ -f /var
/ipfire
/red
/device
]; then
9 DEVICE
=`/bin/cat /var/ipfire/red/device 2> /dev/null | /usr/bin/tr -d '\012'`
13 # Flush all rules and delete all custom chains
15 /sbin
/iptables
-t nat
-F
16 /sbin
/iptables
-t mangle
-F
18 /sbin
/iptables
-t nat
-X
19 /sbin
/iptables
-t mangle
-X
22 /sbin
/iptables
-P INPUT DROP
23 /sbin
/iptables
-P FORWARD DROP
24 /sbin
/iptables
-P OUTPUT ACCEPT
26 # Empty LOG_DROP and LOG_REJECT chains
27 /sbin
/iptables
-N LOG_DROP
28 /sbin
/iptables
-A LOG_DROP
-m limit
--limit 10/minute
-j LOG
29 /sbin
/iptables
-A LOG_DROP
-j DROP
30 /sbin
/iptables
-N LOG_REJECT
31 /sbin
/iptables
-A LOG_REJECT
-m limit
--limit 10/minute
-j LOG
32 /sbin
/iptables
-A LOG_REJECT
-j REJECT
34 # This chain will log, then DROPs packets with certain bad combinations
35 # of flags might indicate a port-scan attempt (xmas, null, etc)
36 /sbin
/iptables
-N PSCAN
37 if [ "$DROPPORTSCAN" == "on" ]; then
38 /sbin
/iptables
-A PSCAN
-p tcp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_TCP Scan " -m comment
--comment "DROP_TCP PScan"
39 /sbin
/iptables
-A PSCAN
-p udp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_UDP Scan " -m comment
--comment "DROP_UDP PScan"
40 /sbin
/iptables
-A PSCAN
-p icmp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_ICMP Scan " -m comment
--comment "DROP_ICMP PScan"
41 /sbin
/iptables
-A PSCAN
-f -m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_FRAG Scan " -m comment
--comment "DROP_FRAG PScan"
43 /sbin
/iptables
-A PSCAN
-j DROP
-m comment
--comment "DROP_PScan"
45 # New tcp packets without SYN set - could well be an obscure type of port scan
46 # that's not covered above, may just be a broken windows machine
47 /sbin
/iptables
-N NEWNOTSYN
48 if [ "$DROPNEWNOTSYN" == "on" ]; then
49 /sbin
/iptables
-A NEWNOTSYN
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_NEWNOTSYN "
51 /sbin
/iptables
-A NEWNOTSYN
-j DROP
-m comment
--comment "DROP_NEWNOTSYN"
53 # Chain to contain all the rules relating to bad TCP flags
54 /sbin
/iptables
-N BADTCP
57 /sbin
/iptables
-A BADTCP
-i lo
-j RETURN
59 # Disallow packets frequently used by port-scanners
61 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
,URG
,PSH
-j PSCAN
63 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL NONE
-j PSCAN
65 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
-j PSCAN
66 # SYN/RST (also catches xmas variants that set SYN+RST+...)
67 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,RST SYN
,RST
-j PSCAN
68 # SYN/FIN (QueSO or nmap OS probe)
69 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,FIN SYN
,FIN
-j PSCAN
71 /sbin
/iptables
-A BADTCP
-p tcp
! --syn -m state
--state NEW
-j NEWNOTSYN
73 /sbin
/iptables
-A INPUT
-j BADTCP
74 /sbin
/iptables
-A FORWARD
-j BADTCP
79 /sbin
/iptables
-F REDINPUT
80 /sbin
/iptables
-F REDFORWARD
81 /sbin
/iptables
-t nat
-F REDNAT
84 if [ "$IFACE" != "" ]; then
86 if [ "$DEVICE" != "" ]; then
87 /sbin
/iptables
-A REDINPUT
-i $DEVICE -j ACCEPT
89 if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then
90 if [ "$RED_DEV" != "" ]; then
91 /sbin
/iptables
-A REDINPUT
-i $RED_DEV -j ACCEPT
97 if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then
98 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
99 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
103 if [ "$ORANGE_DEV" != "" ]; then
104 # This rule enables a host on ORANGE network to connect to the outside
105 # (only if we have a red connection)
106 if [ "$IFACE" != "" ]; then
107 /sbin
/iptables
-A REDFORWARD
-i $ORANGE_DEV -o $IFACE -j ACCEPT
111 if [ "$IFACE" != "" -a -f /var
/ipfire
/red
/active
]; then
113 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
114 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
115 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
117 if [ "$METHOD" == "DHCP" -a "$PROTOCOL" == "RFC1483" ]; then
118 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
119 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
122 # Outgoing masquerading (don't masqerade IPSEC (mark 50))
123 /sbin
/iptables
-t nat
-A REDNAT
-m mark
--mark 50 -o $IFACE -j RETURN
124 /sbin
/iptables
-t nat
-A REDNAT
-o $IFACE -j MASQUERADE
129 # See how we were called.
134 # Limit Packets- helps reduce dos/syn attacks
135 # original do nothing line
136 #/sbin/iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -m limit --limit 10/sec
137 # the correct one, but the negative '!' do nothing...
138 #/sbin/iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN ! -m limit --limit 10/sec -j DROP
140 # Fix for braindead ISP's
141 /sbin
/iptables
-A FORWARD
-p tcp
--tcp-flags SYN
,RST SYN
-j TCPMSS
--clamp-mss-to-pmtu
143 # CUSTOM chains, can be used by the users themselves
144 /sbin
/iptables
-N CUSTOMINPUT
145 /sbin
/iptables
-A INPUT
-j CUSTOMINPUT
146 /sbin
/iptables
-N GUARDIAN
147 /sbin
/iptables
-A INPUT
-j GUARDIAN
148 /sbin
/iptables
-N OVPNBLOCK
149 /sbin
/iptables
-A FORWARD
-j OVPNBLOCK
150 /sbin
/iptables
-A FORWARD
-j GUARDIAN
151 /sbin
/iptables
-N CUSTOMFORWARD
152 /sbin
/iptables
-A FORWARD
-j CUSTOMFORWARD
153 /sbin
/iptables
-N CUSTOMOUTPUT
154 /sbin
/iptables
-A OUTPUT
-j OVPNBLOCK
155 /sbin
/iptables
-A OUTPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
156 /sbin
/iptables
-A OUTPUT
-j CUSTOMOUTPUT
157 /sbin
/iptables
-N OUTGOINGFW
158 /sbin
/iptables
-A OUTPUT
-j OUTGOINGFW
159 /sbin
/iptables
-t nat
-N CUSTOMPREROUTING
160 /sbin
/iptables
-t nat
-N OVPNNAT
161 /sbin
/iptables
-t nat
-A PREROUTING
-j CUSTOMPREROUTING
162 /sbin
/iptables
-t nat
-N CUSTOMPOSTROUTING
163 /sbin
/iptables
-t nat
-A POSTROUTING
-j CUSTOMPOSTROUTING
164 /sbin
/iptables
-t nat
-A POSTROUTING
-j OVPNNAT
166 # IPTV chains for IGMPPROXY
167 /sbin
/iptables
-N IPTVINPUT
168 /sbin
/iptables
-A INPUT
-j IPTVINPUT
169 /sbin
/iptables
-N IPTVFORWARD
170 /sbin
/iptables
-A FORWARD
-j IPTVFORWARD
172 # Filtering ovpn networks INPUT
173 /sbin
/iptables
-A INPUT
-j OVPNBLOCK
176 /sbin
/iptables
-N GUIINPUT
177 /sbin
/iptables
-A INPUT
-j GUIINPUT
178 /sbin
/iptables
-A GUIINPUT
-p icmp
--icmp-type 8 -j ACCEPT
180 # Accept everything connected
181 /sbin
/iptables
-A INPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
182 /sbin
/iptables
-A FORWARD
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
184 # Accept everything on lo
185 iptables
-A INPUT
-i lo
-m state
--state NEW
-j ACCEPT
186 iptables
-A OUTPUT
-o lo
-m state
--state NEW
-j ACCEPT
188 # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything
189 /sbin
/iptables
-N IPSECINPUT
190 /sbin
/iptables
-N IPSECFORWARD
191 /sbin
/iptables
-N IPSECOUTPUT
192 /sbin
/iptables
-N OPENSSLVIRTUAL
193 /sbin
/iptables
-A INPUT
-j IPSECINPUT
194 /sbin
/iptables
-A INPUT
-j OPENSSLVIRTUAL
-m comment
--comment "OPENSSLVIRTUAL INPUT"
195 /sbin
/iptables
-A FORWARD
-j IPSECFORWARD
196 /sbin
/iptables
-A FORWARD
-j OPENSSLVIRTUAL
-m comment
--comment "OPENSSLVIRTUAL FORWARD"
197 /sbin
/iptables
-A OUTPUT
-j IPSECOUTPUT
198 /sbin
/iptables
-t nat
-N IPSECNAT
199 /sbin
/iptables
-t nat
-A POSTROUTING
-j IPSECNAT
202 /sbin
/iptables
-N INPUTFW
203 /sbin
/iptables
-A INPUT
-m state
--state NEW
-j INPUTFW
205 # localhost and ethernet.
206 /sbin
/iptables
-A INPUT
-i lo
-m state
--state NEW
-j ACCEPT
207 /sbin
/iptables
-A INPUT
-s 127.0.0.0/8 -m state
--state NEW
-j DROP
# Loopback not on lo
208 /sbin
/iptables
-A INPUT
-d 127.0.0.0/8 -m state
--state NEW
-j DROP
209 /sbin
/iptables
-A FORWARD
-i lo
-m state
--state NEW
-j ACCEPT
210 /sbin
/iptables
-A FORWARD
-s 127.0.0.0/8 -m state
--state NEW
-j DROP
211 /sbin
/iptables
-A FORWARD
-d 127.0.0.0/8 -m state
--state NEW
-j DROP
212 /sbin
/iptables
-A INPUT
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
! -p icmp
214 # allow DHCP on BLUE to be turned on/off
215 /sbin
/iptables
-N DHCPBLUEINPUT
216 /sbin
/iptables
-A INPUT
-j DHCPBLUEINPUT
219 /sbin
/iptables
-N WIRELESSINPUT
220 /sbin
/iptables
-A INPUT
-m state
--state NEW
-j WIRELESSINPUT
221 /sbin
/iptables
-N WIRELESSFORWARD
222 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j WIRELESSFORWARD
225 /sbin
/iptables
-N FORWARDFW
226 /sbin
/iptables
-A FORWARD
-j FORWARDFW
228 # PORTFWACCESS chain, used for portforwarding
229 /sbin
/iptables
-N PORTFWACCESS
230 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j PORTFWACCESS
233 /sbin
/iptables
-N OPENSSLPHYSICAL
234 /sbin
/iptables
-A INPUT
-j OPENSSLPHYSICAL
236 # RED chain, used for the red interface
237 /sbin
/iptables
-N REDINPUT
238 /sbin
/iptables
-A INPUT
-j REDINPUT
239 /sbin
/iptables
-N REDFORWARD
240 /sbin
/iptables
-A FORWARD
-j REDFORWARD
241 /sbin
/iptables
-t nat
-N REDNAT
242 /sbin
/iptables
-t nat
-A POSTROUTING
-j REDNAT
246 # Custom prerouting chains (for transparent proxy and port forwarding)
247 /sbin
/iptables
-t nat
-N SQUID
248 /sbin
/iptables
-t nat
-A PREROUTING
-j SQUID
249 /sbin
/iptables
-t nat
-N NAT_DESTINATION
250 /sbin
/iptables
-t nat
-N NAT_SOURCE
251 /sbin
/iptables
-t nat
-A PREROUTING
-j NAT_DESTINATION
252 /sbin
/iptables
-t nat
-I POSTROUTING
3 -j NAT_SOURCE
256 # upnp chain for our upnp daemon
257 /sbin
/iptables
-t nat
-N UPNPFW
258 /sbin
/iptables
-t nat
-A PREROUTING
-j UPNPFW
259 /sbin
/iptables
-N UPNPFW
260 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j UPNPFW
262 # Postrouting rules (for port forwarding)
263 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 1 -j SNAT
--to-source $GREEN_ADDRESS
264 if [ "$BLUE_DEV" != "" ]; then
265 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 2 -j SNAT
--to-source $BLUE_ADDRESS
267 if [ "$ORANGE_DEV" != "" ]; then
268 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 3 -j SNAT
--to-source $ORANGE_ADDRESS
271 # run local firewall configuration, if present
272 if [ -x /etc
/sysconfig
/firewall.
local ]; then
273 /etc
/sysconfig
/firewall.
local start
276 /sbin
/iptables
-A INPUT
-j DROP
-m comment
--comment "DROP_INPUT"
278 if [ "$DROPINPUT" == "on" ]; then
279 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_INPUT"
281 if [ "$DROPFORWARD" == "on" ]; then
282 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_FORWARD"
284 /sbin
/iptables
-A FORWARD
-j DROP
-m comment
--comment "DROP_FORWARD"
287 /sbin
/iptables
-N POLICYIN
288 /sbin
/iptables
-A INPUT
-j POLICYIN
289 /sbin
/iptables
-N POLICYFWD
290 /sbin
/iptables
-A FORWARD
-j POLICYFWD
291 /sbin
/iptables
-N POLICYOUT
292 /sbin
/iptables
-A OUTPUT
-j POLICYOUT
294 /usr
/sbin
/firewall-policy
296 /sbin
/iptables
-A INPUT
-j DROP
-m comment
--comment "DROP_INPUT"
298 if [ "$DROPINPUT" == "on" ]; then
299 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_INPUT"
301 if [ "$DROPFORWARD" == "on" ]; then
302 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_FORWARD"
304 /sbin
/iptables
-A FORWARD
-j DROP
-m comment
--comment "DROP_FORWARD"
308 /usr
/local
/bin
/openvpnctrl
--create-chains-and-rules
312 # Accept everyting connected
313 /sbin
/iptables
-A INPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
315 # localhost and ethernet.
316 /sbin
/iptables
-A INPUT
-i lo
-j ACCEPT
317 /sbin
/iptables
-A INPUT
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
319 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
320 /sbin
/iptables
-A INPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
321 /sbin
/iptables
-A INPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
323 if [ "$PROTOCOL" == "RFC1483" -a "$METHOD" == "DHCP" ]; then
324 /sbin
/iptables
-A INPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
325 /sbin
/iptables
-A INPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
328 # run local firewall configuration, if present
329 if [ -x /etc
/sysconfig
/firewall.
local ]; then
330 /etc
/sysconfig
/firewall.
local stop
333 /sbin
/iptables
-A INPUT
-j DROP
-m comment
--comment "DROP_INPUT"
335 if [ "$DROPINPUT" == "on" ]; then
336 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_INPUT"
338 if [ "$DROPFORWARD" == "on" ]; then
339 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_FORWARD"
341 /sbin
/iptables
-A FORWARD
-j DROP
-m comment
--comment "DROP_FORWARD"
346 /usr
/local
/bin
/openvpnctrl
--delete-chains-and-rules
351 # run local firewall configuration, if present
352 if [ -x /etc
/sysconfig
/firewall.
local ]; then
353 /etc
/sysconfig
/firewall.
local reload
359 /usr
/local
/bin
/forwardfwctrl
360 /usr
/local
/bin
/openvpnctrl
-s > /dev
/null
2>&1
361 /usr
/local
/bin
/openvpnctrl
-sn2n > /dev
/null
2>&1
364 echo "Usage: $0 {start|stop|reload|restart}"