]>
git.ipfire.org Git - people/dweismueller/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 # 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
56 # Disallow packets frequently used by port-scanners
58 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
,URG
,PSH
-j PSCAN
60 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL NONE
-j PSCAN
62 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
-j PSCAN
63 # SYN/RST (also catches xmas variants that set SYN+RST+...)
64 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,RST SYN
,RST
-j PSCAN
65 # SYN/FIN (QueSO or nmap OS probe)
66 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,FIN SYN
,FIN
-j PSCAN
68 /sbin
/iptables
-A BADTCP
-p tcp
! --syn -m state
--state NEW
-j NEWNOTSYN
70 /sbin
/iptables
-A INPUT
-j BADTCP
71 /sbin
/iptables
-A FORWARD
-j BADTCP
76 /sbin
/iptables
-F REDINPUT
77 /sbin
/iptables
-F REDFORWARD
78 /sbin
/iptables
-t nat
-F REDNAT
81 if [ "$IFACE" != "" ]; then
83 if [ "$DEVICE" != "" ]; then
84 /sbin
/iptables
-A REDINPUT
-i $DEVICE -j ACCEPT
86 if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then
87 if [ "$RED_DEV" != "" ]; then
88 /sbin
/iptables
-A REDINPUT
-i $RED_DEV -j ACCEPT
94 if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then
95 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
96 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
100 if [ "$ORANGE_DEV" != "" ]; then
101 # This rule enables a host on ORANGE network to connect to the outside
102 # (only if we have a red connection)
103 if [ "$IFACE" != "" ]; then
104 /sbin
/iptables
-A REDFORWARD
-i $ORANGE_DEV -o $IFACE -j ACCEPT
108 if [ "$IFACE" != "" -a -f /var
/ipfire
/red
/active
]; then
110 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
111 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
112 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
114 if [ "$METHOD" == "DHCP" -a "$PROTOCOL" == "RFC1483" ]; then
115 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
116 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
119 # Outgoing masquerading
120 /sbin
/iptables
-t nat
-A REDNAT
-o $IFACE -j MASQUERADE
125 # See how we were called.
130 # Limit Packets- helps reduce dos/syn attacks
131 # original do nothing line
132 #/sbin/iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -m limit --limit 10/sec
133 # the correct one, but the negative '!' do nothing...
134 #/sbin/iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN ! -m limit --limit 10/sec -j DROP
136 # Fix for braindead ISP's
137 /sbin
/iptables
-A FORWARD
-p tcp
--tcp-flags SYN
,RST SYN
-j TCPMSS
--clamp-mss-to-pmtu
139 # CUSTOM chains, can be used by the users themselves
140 /sbin
/iptables
-N CUSTOMINPUT
141 /sbin
/iptables
-A INPUT
-j CUSTOMINPUT
142 /sbin
/iptables
-N CUSTOMFORWARD
143 /sbin
/iptables
-A FORWARD
-j CUSTOMFORWARD
144 /sbin
/iptables
-N CUSTOMOUTPUT
145 /sbin
/iptables
-A OUTPUT
-j CUSTOMOUTPUT
146 /sbin
/iptables
-N OUTGOINGFW
147 /sbin
/iptables
-A OUTPUT
-j OUTGOINGFW
148 /sbin
/iptables
-t nat
-N CUSTOMPREROUTING
149 /sbin
/iptables
-t nat
-A PREROUTING
-j CUSTOMPREROUTING
150 /sbin
/iptables
-t nat
-N CUSTOMPOSTROUTING
151 /sbin
/iptables
-t nat
-A POSTROUTING
-j CUSTOMPOSTROUTING
153 # IPTV chains for IGMPPROXY
154 /sbin
/iptables
-N IPTVINPUT
155 /sbin
/iptables
-A INPUT
-j IPTVINPUT
156 /sbin
/iptables
-N IPTVFORWARD
157 /sbin
/iptables
-A FORWARD
-j IPTVFORWARD
160 /sbin
/iptables
-N GUIINPUT
161 /sbin
/iptables
-A INPUT
-j GUIINPUT
162 /sbin
/iptables
-A GUIINPUT
-p icmp
--icmp-type 8 -j ACCEPT
164 # Accept everything connected
165 /sbin
/iptables
-A INPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
166 /sbin
/iptables
-A FORWARD
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
168 # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything
169 /sbin
/iptables
-N IPSECINPUT
170 /sbin
/iptables
-N IPSECFORWARD
171 /sbin
/iptables
-N IPSECOUTPUT
172 /sbin
/iptables
-N OPENSSLVIRTUAL
173 /sbin
/iptables
-A INPUT
-j IPSECINPUT
174 /sbin
/iptables
-A INPUT
-j OPENSSLVIRTUAL
-m comment
--comment "OPENSSLVIRTUAL INPUT"
175 /sbin
/iptables
-A FORWARD
-j IPSECFORWARD
176 /sbin
/iptables
-A FORWARD
-j OPENSSLVIRTUAL
-m comment
--comment "OPENSSLVIRTUAL FORWARD"
177 /sbin
/iptables
-A OUTPUT
-j IPSECOUTPUT
178 #/sbin/iptables -t nat -N IPSECNAT
179 #/sbin/iptables -t nat -A POSTROUTING -j IPSECNAT
182 /sbin
/iptables
-A FORWARD
-j OUTGOINGFW
184 # localhost and ethernet.
185 /sbin
/iptables
-A INPUT
-i lo
-m state
--state NEW
-j ACCEPT
186 /sbin
/iptables
-A INPUT
-s 127.0.0.0/8 -m state
--state NEW
-j DROP
# Loopback not on lo
187 /sbin
/iptables
-A INPUT
-d 127.0.0.0/8 -m state
--state NEW
-j DROP
188 /sbin
/iptables
-A FORWARD
-i lo
-m state
--state NEW
-j ACCEPT
189 /sbin
/iptables
-A FORWARD
-s 127.0.0.0/8 -m state
--state NEW
-j DROP
190 /sbin
/iptables
-A FORWARD
-d 127.0.0.0/8 -m state
--state NEW
-j DROP
191 /sbin
/iptables
-A INPUT
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
! -p icmp
192 /sbin
/iptables
-A FORWARD
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
194 # If a host on orange tries to initiate a connection to IPFire's red IP and
195 # the connection gets DNATed back through a port forward to a server on orange
196 # we end up with orange -> orange traffic passing through IPFire
197 [ "$ORANGE_DEV" != "" ] && /sbin
/iptables
-A FORWARD
-i $ORANGE_DEV -o $ORANGE_DEV -m state
--state NEW
-j ACCEPT
199 # allow DHCP on BLUE to be turned on/off
200 /sbin
/iptables
-N DHCPBLUEINPUT
201 /sbin
/iptables
-A INPUT
-j DHCPBLUEINPUT
204 /sbin
/iptables
-N OPENSSLPHYSICAL
205 /sbin
/iptables
-A INPUT
-j OPENSSLPHYSICAL
208 /sbin
/iptables
-N WIRELESSINPUT
209 /sbin
/iptables
-A INPUT
-m state
--state NEW
-j WIRELESSINPUT
210 /sbin
/iptables
-N WIRELESSFORWARD
211 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j WIRELESSFORWARD
213 # RED chain, used for the red interface
214 /sbin
/iptables
-N REDINPUT
215 /sbin
/iptables
-A INPUT
-j REDINPUT
216 /sbin
/iptables
-N REDFORWARD
217 /sbin
/iptables
-A FORWARD
-j REDFORWARD
218 /sbin
/iptables
-t nat
-N REDNAT
219 /sbin
/iptables
-t nat
-A POSTROUTING
-j REDNAT
223 # DMZ pinhole chain. setdmzholes setuid prog adds rules here to allow
224 # ORANGE to talk to GREEN / BLUE.
225 /sbin
/iptables
-N DMZHOLES
226 if [ "$ORANGE_DEV" != "" ]; then
227 /sbin
/iptables
-A FORWARD
-i $ORANGE_DEV -m state
--state NEW
-j DMZHOLES
230 # XTACCESS chain, used for external access
231 /sbin
/iptables
-N XTACCESS
232 /sbin
/iptables
-A INPUT
-m state
--state NEW
-j XTACCESS
234 # PORTFWACCESS chain, used for portforwarding
235 /sbin
/iptables
-N PORTFWACCESS
236 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j PORTFWACCESS
238 # Custom prerouting chains (for transparent proxy and port forwarding)
239 /sbin
/iptables
-t nat
-N SQUID
240 /sbin
/iptables
-t nat
-A PREROUTING
-j SQUID
241 /sbin
/iptables
-t nat
-N PORTFW
242 /sbin
/iptables
-t nat
-A PREROUTING
-j PORTFW
244 # upnp chain for our upnp daemon
245 /sbin
/iptables
-t nat
-N UPNPFW
246 /sbin
/iptables
-t nat
-A PREROUTING
-j UPNPFW
249 # Custom mangle chain (for port fowarding)
250 /sbin
/iptables
-t mangle
-N PORTFWMANGLE
251 /sbin
/iptables
-t mangle
-A PREROUTING
-j PORTFWMANGLE
253 # Postrouting rules (for port forwarding)
254 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 1 -j SNAT \
255 --to-source $GREEN_ADDRESS
256 if [ "$BLUE_DEV" != "" ]; then
257 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 2 -j SNAT
--to-source $BLUE_ADDRESS
259 if [ "$ORANGE_DEV" != "" ]; then
260 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 3 -j SNAT
--to-source $ORANGE_ADDRESS
263 # run local firewall configuration, if present
264 if [ -x /etc
/sysconfig
/firewall.
local ]; then
265 /etc
/sysconfig
/firewall.
local start
268 # last rule in input and forward chain is for logging.
270 if [ "$DROPINPUT" == "on" ]; then
271 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_INPUT "
273 /sbin
/iptables
-A INPUT
-j DROP
-m comment
--comment "DROP_INPUT"
274 if [ "$DROPOUTPUT" == "on" ]; then
275 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_OUTPUT "
277 /sbin
/iptables
-A FORWARD
-j DROP
-m comment
--comment "DROP_OUTPUT"
281 /usr
/local
/bin
/openvpnctrl
--create-chains-and-rules
285 # Accept everyting connected
286 /sbin
/iptables
-A INPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
288 # localhost and ethernet.
289 /sbin
/iptables
-A INPUT
-i lo
-j ACCEPT
290 /sbin
/iptables
-A INPUT
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
292 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
293 /sbin
/iptables
-A INPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
294 /sbin
/iptables
-A INPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
296 if [ "$PROTOCOL" == "RFC1483" -a "$METHOD" == "DHCP" ]; then
297 /sbin
/iptables
-A INPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
298 /sbin
/iptables
-A INPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
301 # run local firewall configuration, if present
302 if [ -x /etc
/sysconfig
/firewall.
local ]; then
303 /etc
/sysconfig
/firewall.
local stop
306 if [ "$DROPINPUT" == "on" ]; then
307 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_INPUT "
309 /sbin
/iptables
-A INPUT
-j DROP
-m comment
--comment "DROP_INPUT"
310 if [ "$DROPOUTPUT" == "on" ]; then
311 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_OUTPUT "
313 /sbin
/iptables
-A FORWARD
-j DROP
-m comment
--comment "DROP_OUTPUT"
317 /usr
/local
/bin
/openvpnctrl
--delete-chains-and-rules
322 # run local firewall configuration, if present
323 if [ -x /etc
/sysconfig
/firewall.
local ]; then
324 /etc
/sysconfig
/firewall.
local reload
332 echo "Usage: $0 {start|stop|reload|restart}"