]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/firewall
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 /sbin
/iptables
--wait "$@"
17 # Flush all rules and delete all custom chains
26 iptables
-P INPUT DROP
27 iptables
-P FORWARD DROP
28 iptables
-P OUTPUT ACCEPT
30 # Empty LOG_DROP and LOG_REJECT chains
32 iptables
-A LOG_DROP
-m limit
--limit 10/minute
-j LOG
33 iptables
-A LOG_DROP
-j DROP
34 iptables
-N LOG_REJECT
35 iptables
-A LOG_REJECT
-m limit
--limit 10/minute
-j LOG
36 iptables
-A LOG_REJECT
-j REJECT
38 # This chain will log, then DROPs packets with certain bad combinations
39 # of flags might indicate a port-scan attempt (xmas, null, etc)
41 if [ "$DROPPORTSCAN" == "on" ]; then
42 iptables
-A PSCAN
-p tcp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_TCP Scan " -m comment
--comment "DROP_TCP PScan"
43 iptables
-A PSCAN
-p udp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_UDP Scan " -m comment
--comment "DROP_UDP PScan"
44 iptables
-A PSCAN
-p icmp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_ICMP Scan " -m comment
--comment "DROP_ICMP PScan"
45 iptables
-A PSCAN
-f -m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_FRAG Scan " -m comment
--comment "DROP_FRAG PScan"
47 iptables
-A PSCAN
-j DROP
-m comment
--comment "DROP_PScan"
49 # New tcp packets without SYN set - could well be an obscure type of port scan
50 # that's not covered above, may just be a broken windows machine
52 if [ "$DROPNEWNOTSYN" == "on" ]; then
53 iptables
-A NEWNOTSYN
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_NEWNOTSYN "
55 iptables
-A NEWNOTSYN
-j DROP
-m comment
--comment "DROP_NEWNOTSYN"
57 # Chain to contain all the rules relating to bad TCP flags
60 # Don't check loopback
61 iptables
-A BADTCP
-i lo
-j RETURN
63 # Disallow packets frequently used by port-scanners
65 iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
,URG
,PSH
-j PSCAN
67 iptables
-A BADTCP
-p tcp
--tcp-flags ALL NONE
-j PSCAN
69 iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
-j PSCAN
70 # SYN/RST (also catches xmas variants that set SYN+RST+...)
71 iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,RST SYN
,RST
-j PSCAN
72 # SYN/FIN (QueSO or nmap OS probe)
73 iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,FIN SYN
,FIN
-j PSCAN
75 iptables
-A BADTCP
-p tcp
! --syn -m conntrack
--ctstate NEW
-j NEWNOTSYN
77 iptables
-A INPUT
-p tcp
-j BADTCP
78 iptables
-A FORWARD
-p tcp
-j BADTCP
80 # Connection tracking chain
82 iptables
-A CONNTRACK
-m conntrack
--ctstate ESTABLISHED
,RELATED
-j ACCEPT
84 # Fix for braindead ISP's
85 iptables
-A FORWARD
-p tcp
--tcp-flags SYN
,RST SYN
-j TCPMSS
--clamp-mss-to-pmtu
87 # CUSTOM chains, can be used by the users themselves
88 iptables
-N CUSTOMINPUT
89 iptables
-A INPUT
-j CUSTOMINPUT
90 iptables
-N CUSTOMFORWARD
91 iptables
-A FORWARD
-j CUSTOMFORWARD
92 iptables
-N CUSTOMOUTPUT
93 iptables
-A OUTPUT
-j CUSTOMOUTPUT
94 iptables
-t nat
-N CUSTOMPREROUTING
95 iptables
-t nat
-A PREROUTING
-j CUSTOMPREROUTING
96 iptables
-t nat
-N CUSTOMPOSTROUTING
97 iptables
-t nat
-A POSTROUTING
-j CUSTOMPOSTROUTING
99 # Guardian (IPS) chains
101 iptables
-A INPUT
-j GUARDIAN
102 iptables
-A FORWARD
-j GUARDIAN
104 # Block OpenVPN transfer networks
105 iptables
-N OVPNBLOCK
106 for i
in INPUT FORWARD
; do
107 iptables
-A ${i} -j OVPNBLOCK
110 # OpenVPN transfer network translation
111 iptables
-t nat
-N OVPNNAT
112 iptables
-t nat
-A POSTROUTING
-j OVPNNAT
114 # IPTV chains for IGMPPROXY
115 iptables
-N IPTVINPUT
116 iptables
-A INPUT
-j IPTVINPUT
117 iptables
-N IPTVFORWARD
118 iptables
-A FORWARD
-j IPTVFORWARD
122 iptables
-A INPUT
-j GUIINPUT
123 iptables
-A GUIINPUT
-p icmp
--icmp-type 8 -j ACCEPT
125 # Accept everything on loopback
127 iptables
-A LOOPBACK
-i lo
-j ACCEPT
128 iptables
-A LOOPBACK
-o lo
-j ACCEPT
130 # Filter all packets with loopback addresses on non-loopback interfaces.
131 iptables
-A LOOPBACK
-s 127.0.0.0/8 -j DROP
132 iptables
-A LOOPBACK
-d 127.0.0.0/8 -j DROP
134 for i
in INPUT FORWARD OUTPUT
; do
135 iptables
-A ${i} -j LOOPBACK
138 # Accept everything connected
139 for i
in INPUT FORWARD OUTPUT
; do
140 iptables
-A ${i} -j CONNTRACK
143 # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything
144 iptables
-N IPSECINPUT
145 iptables
-N IPSECFORWARD
146 iptables
-N IPSECOUTPUT
147 iptables
-A INPUT
-j IPSECINPUT
148 iptables
-A FORWARD
-j IPSECFORWARD
149 iptables
-A OUTPUT
-j IPSECOUTPUT
150 iptables
-t nat
-N IPSECNAT
151 iptables
-t nat
-A POSTROUTING
-j IPSECNAT
153 # localhost and ethernet.
154 iptables
-A INPUT
-i $GREEN_DEV -m conntrack
--ctstate NEW
-j ACCEPT
! -p icmp
156 # allow DHCP on BLUE to be turned on/off
157 iptables
-N DHCPBLUEINPUT
158 iptables
-A INPUT
-j DHCPBLUEINPUT
161 iptables
-N WIRELESSINPUT
162 iptables
-A INPUT
-m conntrack
--ctstate NEW
-j WIRELESSINPUT
163 iptables
-N WIRELESSFORWARD
164 iptables
-A FORWARD
-m conntrack
--ctstate NEW
-j WIRELESSFORWARD
167 iptables
-N OVPNINPUT
168 iptables
-A INPUT
-j OVPNINPUT
171 iptables
-N TOR_INPUT
172 iptables
-A INPUT
-j TOR_INPUT
174 # Jump into the actual firewall ruleset.
176 iptables
-A INPUT
-j INPUTFW
178 iptables
-N OUTGOINGFW
179 iptables
-A OUTPUT
-j OUTGOINGFW
181 iptables
-N FORWARDFW
182 iptables
-A FORWARD
-j FORWARDFW
185 iptables
-t nat
-N NAT_SOURCE
186 iptables
-t nat
-A POSTROUTING
-j NAT_SOURCE
188 # RED chain, used for the red interface
190 iptables
-A INPUT
-j REDINPUT
191 iptables
-N REDFORWARD
192 iptables
-A FORWARD
-j REDFORWARD
193 iptables
-t nat
-N REDNAT
194 iptables
-t nat
-A POSTROUTING
-j REDNAT
198 # Custom prerouting chains (for transparent proxy)
199 iptables
-t nat
-N SQUID
200 iptables
-t nat
-A PREROUTING
-j SQUID
203 iptables
-t nat
-N NAT_DESTINATION
204 iptables
-t nat
-A PREROUTING
-j NAT_DESTINATION
206 # upnp chain for our upnp daemon
207 iptables
-t nat
-N UPNPFW
208 iptables
-t nat
-A PREROUTING
-j UPNPFW
210 iptables
-A FORWARD
-m conntrack
--ctstate NEW
-j UPNPFW
212 # Apply OpenVPN firewall rules
213 /usr
/local
/bin
/openvpnctrl
--firewall-rules
216 /usr
/local
/bin
/wirelessctrl
220 iptables
-A INPUT
-j POLICYIN
221 iptables
-N POLICYFWD
222 iptables
-A FORWARD
-j POLICYFWD
223 iptables
-N POLICYOUT
224 iptables
-A OUTPUT
-j POLICYOUT
226 /usr
/sbin
/firewall-policy
229 /usr
/local
/bin
/firewallctrl
231 if [ "$DROPINPUT" == "on" ]; then
232 iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_INPUT"
234 iptables
-A INPUT
-j DROP
-m comment
--comment "DROP_INPUT"
235 if [ "$DROPFORWARD" == "on" ]; then
236 iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_FORWARD"
238 iptables
-A FORWARD
-j DROP
-m comment
--comment "DROP_FORWARD"
243 iptables
-F REDFORWARD
244 iptables
-t nat
-F REDNAT
246 # PPPoE / PPTP Device
247 if [ "$IFACE" != "" ]; then
249 if [ "$DEVICE" != "" ]; then
250 iptables
-A REDINPUT
-i $DEVICE -j ACCEPT
252 if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then
253 if [ "$RED_DEV" != "" ]; then
254 iptables
-A REDINPUT
-i $RED_DEV -j ACCEPT
260 if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then
261 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
262 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
266 if [ "$ORANGE_DEV" != "" ]; then
267 # This rule enables a host on ORANGE network to connect to the outside
268 # (only if we have a red connection)
269 if [ "$IFACE" != "" ]; then
270 iptables
-A REDFORWARD
-i $ORANGE_DEV -o $IFACE -j ACCEPT
274 if [ "$IFACE" != "" -a -f /var
/ipfire
/red
/active
]; then
276 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
277 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
278 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
280 if [ "$METHOD" == "DHCP" -a "$PROTOCOL" == "RFC1483" ]; then
281 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
282 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
285 # Outgoing masquerading (don't masqerade IPSEC (mark 50))
286 iptables
-t nat
-A REDNAT
-m mark
--mark 50 -o $IFACE -j RETURN
287 iptables
-t nat
-A REDNAT
-o $IFACE -j MASQUERADE
292 # See how we were called.
295 boot_mesg
"Setting up firewall"
299 # run local firewall configuration, if present
300 if [ -x /etc
/sysconfig
/firewall.
local ]; then
301 /etc
/sysconfig
/firewall.
local start
305 boot_mesg
"Reloading firewall"
309 # run local firewall configuration, if present
310 if [ -x /etc
/sysconfig
/firewall.
local ]; then
311 /etc
/sysconfig
/firewall.
local reload
315 # run local firewall configuration, if present
316 if [ -x /etc
/sysconfig
/firewall.
local ]; then
317 /etc
/sysconfig
/firewall.
local stop
322 echo "Usage: $0 {start|reload|restart}"