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
68 iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
,URG
,PSH
-j PSCAN
70 iptables
-A BADTCP
-p tcp
--tcp-flags ALL NONE
-j PSCAN
72 iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
-j PSCAN
73 # SYN/RST (also catches xmas variants that set SYN+RST+...)
74 iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,RST SYN
,RST
-j PSCAN
75 # SYN/FIN (QueSO or nmap OS probe)
76 iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,FIN SYN
,FIN
-j PSCAN
78 iptables
-A BADTCP
-p tcp
! --syn -m conntrack
--ctstate NEW
-j NEWNOTSYN
80 iptables
-A INPUT
-p tcp
-j BADTCP
81 iptables
-A FORWARD
-p tcp
-j BADTCP
83 # Connection tracking chain
85 iptables
-A CONNTRACK
-m conntrack
--ctstate ESTABLISHED
,RELATED
-j ACCEPT
87 # Fix for braindead ISP's
88 iptables
-A FORWARD
-p tcp
--tcp-flags SYN
,RST SYN
-j TCPMSS
--clamp-mss-to-pmtu
90 # CUSTOM chains, can be used by the users themselves
91 iptables
-N CUSTOMINPUT
92 iptables
-A INPUT
-j CUSTOMINPUT
93 iptables
-N CUSTOMFORWARD
94 iptables
-A FORWARD
-j CUSTOMFORWARD
95 iptables
-N CUSTOMOUTPUT
96 iptables
-A OUTPUT
-j CUSTOMOUTPUT
97 iptables
-t nat
-N CUSTOMPREROUTING
98 iptables
-t nat
-A PREROUTING
-j CUSTOMPREROUTING
99 iptables
-t nat
-N CUSTOMPOSTROUTING
100 iptables
-t nat
-A POSTROUTING
-j CUSTOMPOSTROUTING
102 # Guardian (IPS) chains
104 iptables
-A INPUT
-j GUARDIAN
105 iptables
-A FORWARD
-j GUARDIAN
107 # Block OpenVPN transfer networks
108 iptables
-N OVPNBLOCK
109 for i
in INPUT FORWARD
; do
110 iptables
-A ${i} -j OVPNBLOCK
113 # OpenVPN transfer network translation
114 iptables
-t nat
-N OVPNNAT
115 iptables
-t nat
-A POSTROUTING
-j OVPNNAT
117 # IPTV chains for IGMPPROXY
118 iptables
-N IPTVINPUT
119 iptables
-A INPUT
-j IPTVINPUT
120 iptables
-N IPTVFORWARD
121 iptables
-A FORWARD
-j IPTVFORWARD
125 iptables
-A INPUT
-j GUIINPUT
126 iptables
-A GUIINPUT
-p icmp
--icmp-type 8 -j ACCEPT
128 # Accept everything on loopback
130 iptables
-A LOOPBACK
-i lo
-j ACCEPT
131 iptables
-A LOOPBACK
-o lo
-j ACCEPT
133 # Filter all packets with loopback addresses on non-loopback interfaces.
134 iptables
-A LOOPBACK
-s 127.0.0.0/8 -j DROP
135 iptables
-A LOOPBACK
-d 127.0.0.0/8 -j DROP
137 for i
in INPUT FORWARD OUTPUT
; do
138 iptables
-A ${i} -j LOOPBACK
141 # Accept everything connected
142 for i
in INPUT FORWARD OUTPUT
; do
143 iptables
-A ${i} -j CONNTRACK
146 # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything
147 iptables
-N IPSECINPUT
148 iptables
-N IPSECFORWARD
149 iptables
-N IPSECOUTPUT
150 iptables
-A INPUT
-j IPSECINPUT
151 iptables
-A FORWARD
-j IPSECFORWARD
152 iptables
-A OUTPUT
-j IPSECOUTPUT
153 iptables
-t nat
-N IPSECNAT
154 iptables
-t nat
-A POSTROUTING
-j IPSECNAT
156 # localhost and ethernet.
157 iptables
-A INPUT
-i $GREEN_DEV -m conntrack
--ctstate NEW
-j ACCEPT
! -p icmp
159 # allow DHCP on BLUE to be turned on/off
160 iptables
-N DHCPBLUEINPUT
161 iptables
-A INPUT
-j DHCPBLUEINPUT
164 iptables
-N WIRELESSINPUT
165 iptables
-A INPUT
-m conntrack
--ctstate NEW
-j WIRELESSINPUT
166 iptables
-N WIRELESSFORWARD
167 iptables
-A FORWARD
-m conntrack
--ctstate NEW
-j WIRELESSFORWARD
170 iptables
-N OVPNINPUT
171 iptables
-A INPUT
-j OVPNINPUT
174 iptables
-N TOR_INPUT
175 iptables
-A INPUT
-j TOR_INPUT
177 # Jump into the actual firewall ruleset.
179 iptables
-A INPUT
-j INPUTFW
181 iptables
-N OUTGOINGFW
182 iptables
-A OUTPUT
-j OUTGOINGFW
184 iptables
-N FORWARDFW
185 iptables
-A FORWARD
-j FORWARDFW
188 iptables
-t nat
-N NAT_SOURCE
189 iptables
-t nat
-A POSTROUTING
-j NAT_SOURCE
191 # RED chain, used for the red interface
193 iptables
-A INPUT
-j REDINPUT
194 iptables
-N REDFORWARD
195 iptables
-A FORWARD
-j REDFORWARD
196 iptables
-t nat
-N REDNAT
197 iptables
-t nat
-A POSTROUTING
-j REDNAT
199 # Custom prerouting chains (for transparent proxy)
200 iptables
-t nat
-N SQUID
201 iptables
-t nat
-A PREROUTING
-j SQUID
204 iptables
-t nat
-N NAT_DESTINATION
205 iptables
-t nat
-A PREROUTING
-j NAT_DESTINATION
207 # upnp chain for our upnp daemon
208 iptables
-t nat
-N UPNPFW
209 iptables
-t nat
-A PREROUTING
-j UPNPFW
211 iptables
-A FORWARD
-m conntrack
--ctstate NEW
-j UPNPFW
213 # Apply OpenVPN firewall rules
214 /usr
/local
/bin
/openvpnctrl
--firewall-rules
217 /usr
/local
/bin
/wirelessctrl
221 iptables
-A INPUT
-j POLICYIN
222 iptables
-N POLICYFWD
223 iptables
-A FORWARD
-j POLICYFWD
224 iptables
-N POLICYOUT
225 iptables
-A OUTPUT
-j POLICYOUT
227 # Initialize firewall policies.
228 /usr
/sbin
/firewall-policy
230 # Install firewall rules for the red interface.
236 iptables
-F REDFORWARD
237 iptables
-t nat
-F REDNAT
239 # PPPoE / PPTP Device
240 if [ "$IFACE" != "" ]; then
242 if [ "$DEVICE" != "" ]; then
243 iptables
-A REDINPUT
-i $DEVICE -j ACCEPT
245 if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then
246 if [ "$RED_DEV" != "" ]; then
247 iptables
-A REDINPUT
-i $RED_DEV -j ACCEPT
253 if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then
254 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
255 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
259 if [ "$ORANGE_DEV" != "" ]; then
260 # This rule enables a host on ORANGE network to connect to the outside
261 # (only if we have a red connection)
262 if [ "$IFACE" != "" ]; then
263 iptables
-A REDFORWARD
-i $ORANGE_DEV -o $IFACE -j ACCEPT
267 if [ "$IFACE" != "" -a -f /var
/ipfire
/red
/active
]; then
269 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
270 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
271 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
273 if [ "$METHOD" == "DHCP" -a "$PROTOCOL" == "RFC1483" ]; then
274 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
275 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
278 # Outgoing masquerading (don't masqerade IPSEC (mark 50))
279 iptables
-t nat
-A REDNAT
-m mark
--mark 50 -o $IFACE -j RETURN
280 iptables
-t nat
-A REDNAT
-o $IFACE -j MASQUERADE
285 /usr
/local
/bin
/firewallctrl
288 # See how we were called.
291 boot_mesg
"Loading firewall modules into the kernel"
292 modprobe iptable_nat || failed
=1
293 for i
in $
(find /lib
/modules
/$
(uname
-r) -name nf_conntrack
*); do
294 modprobe $
(basename $i | cut
-d.
-f1) || failed
=1
296 for i
in $
(find /lib
/modules
/$
(uname
-r) -name nf_nat
*); do
297 modprobe $
(basename $i | cut
-d.
-f1) || failed
=1
302 if [ -e /var
/ipfire
/main
/disable_nf_sip
]; then
304 rmmod nf_conntrack_sip
306 rmmod nf_conntrack_h323
309 boot_mesg
"Setting up firewall"
313 # run local firewall configuration, if present
314 if [ -x /etc
/sysconfig
/firewall.
local ]; then
315 /etc
/sysconfig
/firewall.
local start
319 boot_mesg
"Reloading firewall"
323 # run local firewall configuration, if present
324 if [ -x /etc
/sysconfig
/firewall.
local ]; then
325 /etc
/sysconfig
/firewall.
local reload
329 # run local firewall configuration, if present
330 if [ -x /etc
/sysconfig
/firewall.
local ]; then
331 /etc
/sysconfig
/firewall.
local stop
336 echo "Usage: $0 {start|reload|restart}"