6 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
7 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
8 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/optionsfw
/settings
)
9 IFACE
=`/bin/cat /var/ipfire/red/iface 2> /dev/null | /usr/bin/tr -d '\012'`
11 if [ -f /var
/ipfire
/red
/device
]; then
12 DEVICE
=`/bin/cat /var/ipfire/red/device 2> /dev/null | /usr/bin/tr -d '\012'`
16 /sbin
/iptables
--wait "$@"
20 # Flush all rules and delete all custom chains
29 iptables
-P INPUT DROP
30 iptables
-P FORWARD DROP
31 iptables
-P OUTPUT ACCEPT
33 # Empty LOG_DROP and LOG_REJECT chains
35 iptables
-A LOG_DROP
-m limit
--limit 10/minute
-j LOG
36 iptables
-A LOG_DROP
-j DROP
37 iptables
-N LOG_REJECT
38 iptables
-A LOG_REJECT
-m limit
--limit 10/minute
-j LOG
39 iptables
-A LOG_REJECT
-j REJECT
41 # This chain will log, then DROPs packets with certain bad combinations
42 # of flags might indicate a port-scan attempt (xmas, null, etc)
44 if [ "$DROPPORTSCAN" == "on" ]; then
45 iptables
-A PSCAN
-p tcp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_TCP Scan " -m comment
--comment "DROP_TCP PScan"
46 iptables
-A PSCAN
-p udp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_UDP Scan " -m comment
--comment "DROP_UDP PScan"
47 iptables
-A PSCAN
-p icmp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_ICMP Scan " -m comment
--comment "DROP_ICMP PScan"
48 iptables
-A PSCAN
-f -m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_FRAG Scan " -m comment
--comment "DROP_FRAG PScan"
50 iptables
-A PSCAN
-j DROP
-m comment
--comment "DROP_PScan"
52 # New tcp packets without SYN set - could well be an obscure type of port scan
53 # that's not covered above, may just be a broken windows machine
55 if [ "$DROPNEWNOTSYN" == "on" ]; then
56 iptables
-A NEWNOTSYN
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_NEWNOTSYN "
58 iptables
-A NEWNOTSYN
-j DROP
-m comment
--comment "DROP_NEWNOTSYN"
60 # Chain to contain all the rules relating to bad TCP flags
63 # Don't check loopback
64 iptables
-A BADTCP
-i lo
-j RETURN
66 # Disallow packets frequently used by port-scanners
67 # NMAP FIN/URG/PSH (XMAS scan)
68 iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
,URG
,PSH
-j PSCAN
70 iptables
-A BADTCP
-p tcp
--tcp-flags ALL SYN
,RST
,ACK
,FIN
,URG
-j PSCAN
72 iptables
-A BADTCP
-p tcp
--tcp-flags ALL ALL
-j PSCAN
74 iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
-j PSCAN
75 # SYN/RST (also catches xmas variants that set SYN+RST+...)
76 iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,RST SYN
,RST
-j PSCAN
77 # SYN/FIN (QueSO or nmap OS probe)
78 iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,FIN SYN
,FIN
-j PSCAN
80 iptables
-A BADTCP
-p tcp
--tcp-flags ALL NONE
-j PSCAN
82 iptables
-A BADTCP
-p tcp
! --syn -m conntrack
--ctstate NEW
-j NEWNOTSYN
84 iptables
-A INPUT
-p tcp
-j BADTCP
85 iptables
-A FORWARD
-p tcp
-j BADTCP
87 # Connection tracking chain
89 iptables
-A CONNTRACK
-m conntrack
--ctstate ESTABLISHED
,RELATED
-j ACCEPT
90 iptables
-A CONNTRACK
-m conntrack
--ctstate INVALID
-j DROP
92 # Fix for braindead ISP's
93 iptables
-A FORWARD
-p tcp
--tcp-flags SYN
,RST SYN
-j TCPMSS
--clamp-mss-to-pmtu
95 # CUSTOM chains, can be used by the users themselves
96 iptables
-N CUSTOMINPUT
97 iptables
-A INPUT
-j CUSTOMINPUT
98 iptables
-N CUSTOMFORWARD
99 iptables
-A FORWARD
-j CUSTOMFORWARD
100 iptables
-N CUSTOMOUTPUT
101 iptables
-A OUTPUT
-j CUSTOMOUTPUT
102 iptables
-t nat
-N CUSTOMPREROUTING
103 iptables
-t nat
-A PREROUTING
-j CUSTOMPREROUTING
104 iptables
-t nat
-N CUSTOMPOSTROUTING
105 iptables
-t nat
-A POSTROUTING
-j CUSTOMPOSTROUTING
107 # Guardian (IPS) chains
109 iptables
-A INPUT
-j GUARDIAN
110 iptables
-A FORWARD
-j GUARDIAN
112 # Block OpenVPN transfer networks
113 iptables
-N OVPNBLOCK
114 iptables
-A INPUT
-i tun
+ -j OVPNBLOCK
115 iptables
-A FORWARD
-i tun
+ -j OVPNBLOCK
116 iptables
-A FORWARD
-o tun
+ -j OVPNBLOCK
118 # OpenVPN transfer network translation
119 iptables
-t nat
-N OVPNNAT
120 iptables
-t nat
-A POSTROUTING
-j OVPNNAT
122 # IPTV chains for IGMPPROXY
123 iptables
-N IPTVINPUT
124 iptables
-A INPUT
-j IPTVINPUT
125 iptables
-N IPTVFORWARD
126 iptables
-A FORWARD
-j IPTVFORWARD
128 # Allow to ping the firewall.
129 iptables
-N ICMPINPUT
130 iptables
-A INPUT
-j ICMPINPUT
131 iptables
-A ICMPINPUT
-p icmp
--icmp-type 8 -j ACCEPT
133 # Accept everything on loopback
135 iptables
-A LOOPBACK
-i lo
-j ACCEPT
136 iptables
-A LOOPBACK
-o lo
-j ACCEPT
138 # Filter all packets with loopback addresses on non-loopback interfaces.
139 iptables
-A LOOPBACK
-s 127.0.0.0/8 -j DROP
140 iptables
-A LOOPBACK
-d 127.0.0.0/8 -j DROP
142 for i
in INPUT FORWARD OUTPUT
; do
143 iptables
-A ${i} -j LOOPBACK
146 # Accept everything connected
147 for i
in INPUT FORWARD OUTPUT
; do
148 iptables
-A ${i} -j CONNTRACK
152 iptables
-N DHCPINPUT
153 iptables
-A DHCPINPUT
-p udp
--sport 68 --dport 67 -j ACCEPT
154 iptables
-A DHCPINPUT
-p tcp
--sport 68 --dport 67 -j ACCEPT
156 iptables
-N DHCPOUTPUT
157 iptables
-A DHCPOUTPUT
-p udp
--sport 67 --dport 68 -j ACCEPT
158 iptables
-A DHCPOUTPUT
-p tcp
--sport 67 --dport 68 -j ACCEPT
160 # Allow DHCP on GREEN
161 iptables
-N DHCPGREENINPUT
162 iptables
-N DHCPGREENOUTPUT
163 if [ -n "${GREEN_DEV}" ]; then
164 iptables
-A INPUT
-i "${GREEN_DEV}" -j DHCPGREENINPUT
165 iptables
-A OUTPUT
-o "${GREEN_DEV}" -j DHCPGREENOUTPUT
168 # allow DHCP on BLUE to be turned on/off
169 iptables
-N DHCPBLUEINPUT
170 iptables
-N DHCPBLUEOUTPUT
171 if [ -n "${BLUE_DEV}" ]; then
172 iptables
-A INPUT
-i "${BLUE_DEV}" -j DHCPBLUEINPUT
173 iptables
-A OUTPUT
-o "${BLUE_DEV}" -j DHCPBLUEOUTPUT
176 # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything
177 iptables
-N IPSECINPUT
178 iptables
-N IPSECFORWARD
179 iptables
-N IPSECOUTPUT
180 iptables
-A INPUT
-j IPSECINPUT
181 iptables
-A FORWARD
-j IPSECFORWARD
182 iptables
-A OUTPUT
-j IPSECOUTPUT
183 iptables
-t nat
-N IPSECNAT
184 iptables
-t nat
-A POSTROUTING
-j IPSECNAT
186 # localhost and ethernet.
187 # Always allow accessing the web GUI from GREEN.
189 iptables
-A INPUT
-j GUIINPUT
190 iptables
-A GUIINPUT
-i "${GREEN_DEV}" -p tcp
--dport 444 -j ACCEPT
193 iptables
-N WIRELESSINPUT
194 iptables
-A INPUT
-m conntrack
--ctstate NEW
-j WIRELESSINPUT
195 iptables
-N WIRELESSFORWARD
196 iptables
-A FORWARD
-m conntrack
--ctstate NEW
-j WIRELESSFORWARD
199 iptables
-N OVPNINPUT
200 iptables
-A INPUT
-j OVPNINPUT
203 iptables
-N TOR_INPUT
204 iptables
-A INPUT
-j TOR_INPUT
206 # Jump into the actual firewall ruleset.
208 iptables
-A INPUT
-j INPUTFW
210 iptables
-N OUTGOINGFW
211 iptables
-A OUTPUT
-j OUTGOINGFW
213 iptables
-N FORWARDFW
214 iptables
-A FORWARD
-j FORWARDFW
217 iptables
-t nat
-N NAT_SOURCE
218 iptables
-t nat
-A POSTROUTING
-j NAT_SOURCE
220 # Custom prerouting chains (for transparent proxy)
221 iptables
-t nat
-N SQUID
222 iptables
-t nat
-A PREROUTING
-j SQUID
225 iptables
-t nat
-N NAT_DESTINATION
226 iptables
-t nat
-A PREROUTING
-j NAT_DESTINATION
227 iptables
-t nat
-A OUTPUT
-j NAT_DESTINATION
229 iptables
-t mangle
-N NAT_DESTINATION
230 iptables
-t mangle
-A PREROUTING
-j NAT_DESTINATION
232 iptables
-t nat
-N NAT_DESTINATION_FIX
233 iptables
-t nat
-A POSTROUTING
-j NAT_DESTINATION_FIX
235 iptables
-t nat
-A NAT_DESTINATION_FIX \
236 -m mark
--mark 1 -j SNAT
--to-source "${GREEN_ADDRESS}"
238 if [ -n "${BLUE_ADDRESS}" ]; then
239 iptables
-t nat
-A NAT_DESTINATION_FIX \
240 -m mark
--mark 2 -j SNAT
--to-source "${BLUE_ADDRESS}"
243 if [ -n "${ORANGE_ADDRESS}" ]; then
244 iptables
-t nat
-A NAT_DESTINATION_FIX \
245 -m mark
--mark 3 -j SNAT
--to-source "${ORANGE_ADDRESS}"
248 # upnp chain for our upnp daemon
249 iptables
-t nat
-N UPNPFW
250 iptables
-t nat
-A PREROUTING
-j UPNPFW
252 iptables
-A FORWARD
-m conntrack
--ctstate NEW
-j UPNPFW
254 # RED chain, used for the red interface
256 iptables
-A INPUT
-j REDINPUT
257 iptables
-N REDFORWARD
258 iptables
-A FORWARD
-j REDFORWARD
259 iptables
-t nat
-N REDNAT
260 iptables
-t nat
-A POSTROUTING
-j REDNAT
262 # Filter logging of incoming broadcasts.
263 iptables
-N BROADCAST_FILTER
264 iptables
-A INPUT
-j BROADCAST_FILTER
266 iptables
-A BROADCAST_FILTER
-i "${GREEN_DEV}" -d "${GREEN_BROADCAST}" -j DROP
268 if [ -n "${BLUE_DEV}" -a -n "${BLUE_BROADCAST}" ]; then
269 iptables
-A BROADCAST_FILTER
-i "${BLUE_DEV}" -d "${BLUE_BROADCAST}" -j DROP
272 if [ -n "${ORANGE_DEV}" -a -n "${ORANGE_BROADCAST}" ]; then
273 iptables
-A BROADCAST_FILTER
-i "${ORANGE_DEV}" -d "${ORANGE_BROADCAST}" -j DROP
276 # Apply OpenVPN firewall rules
277 /usr
/local
/bin
/openvpnctrl
--firewall-rules
280 /usr
/local
/bin
/wirelessctrl
284 iptables
-A INPUT
-j POLICYIN
285 iptables
-N POLICYFWD
286 iptables
-A FORWARD
-j POLICYFWD
287 iptables
-N POLICYOUT
288 iptables
-A OUTPUT
-j POLICYOUT
290 # Initialize firewall policies.
291 /usr
/sbin
/firewall-policy
293 # Install firewall rules for the red interface.
299 iptables
-F REDFORWARD
300 iptables
-t nat
-F REDNAT
302 # PPPoE / PPTP Device
303 if [ "$IFACE" != "" ]; then
305 if [ "$DEVICE" != "" ]; then
306 iptables
-A REDINPUT
-i $DEVICE -j ACCEPT
308 if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then
309 if [ "$RED_DEV" != "" ]; then
310 iptables
-A REDINPUT
-i $RED_DEV -j ACCEPT
316 if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then
317 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
318 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
322 if [ "$ORANGE_DEV" != "" ]; then
323 # This rule enables a host on ORANGE network to connect to the outside
324 # (only if we have a red connection)
325 if [ "$IFACE" != "" ]; then
326 iptables
-A REDFORWARD
-i $ORANGE_DEV -o $IFACE -j ACCEPT
330 if [ "$IFACE" != "" -a -f /var
/ipfire
/red
/active
]; then
332 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
333 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
334 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
336 if [ "$METHOD" == "DHCP" -a "$PROTOCOL" == "RFC1483" ]; then
337 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
338 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
341 # Outgoing masquerading (don't masqerade IPSEC (mark 50))
342 iptables
-t nat
-A REDNAT
-m mark
--mark 50 -o $IFACE -j RETURN
344 if [ "$IFACE" != "$GREEN_DEV" ]; then
345 iptables
-t nat
-A REDNAT
-o $IFACE -j MASQUERADE
351 /usr
/local
/bin
/firewallctrl
354 # See how we were called.
357 boot_mesg
"Loading firewall modules into the kernel"
358 modprobe iptable_nat || failed
=1
359 for i
in $
(find /lib
/modules
/$
(uname
-r) -name nf_conntrack
*); do
360 modprobe $
(basename $i | cut
-d.
-f1) || failed
=1
362 for i
in $
(find /lib
/modules
/$
(uname
-r) -name nf_nat
*); do
363 modprobe $
(basename $i | cut
-d.
-f1) || failed
=1
368 if [ -e /var
/ipfire
/main
/disable_nf_sip
]; then
370 rmmod nf_conntrack_sip
372 rmmod nf_conntrack_h323
375 boot_mesg
"Setting up firewall"
379 # run local firewall configuration, if present
380 if [ -x /etc
/sysconfig
/firewall.
local ]; then
381 /etc
/sysconfig
/firewall.
local start
385 boot_mesg
"Reloading firewall"
389 # run local firewall configuration, if present
390 if [ -x /etc
/sysconfig
/firewall.
local ]; then
391 /etc
/sysconfig
/firewall.
local reload
395 # run local firewall configuration, if present
396 if [ -x /etc
/sysconfig
/firewall.
local ]; then
397 /etc
/sysconfig
/firewall.
local stop
402 echo "Usage: $0 {start|reload|restart}"