]>
git.ipfire.org Git - people/teissler/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 IFACE
=`/bin/cat /var/ipfire/red/iface 2> /dev/null | /usr/bin/tr -d '\012'`
7 if [ -f /var
/ipfire
/red
/device
]; then
8 DEVICE
=`/bin/cat /var/ipfire/red/device 2> /dev/null | /usr/bin/tr -d '\012'`
12 # Flush all rules and delete all custom chains
14 /sbin
/iptables
-t nat
-F
15 /sbin
/iptables
-t mangle
-F
17 /sbin
/iptables
-t nat
-X
18 /sbin
/iptables
-t mangle
-X
21 /sbin
/iptables
-P INPUT DROP
22 /sbin
/iptables
-P FORWARD DROP
23 /sbin
/iptables
-P OUTPUT ACCEPT
25 # Empty LOG_DROP and LOG_REJECT chains
26 /sbin
/iptables
-N LOG_DROP
27 /sbin
/iptables
-A LOG_DROP
-m limit
--limit 10/minute
-j LOG
28 /sbin
/iptables
-A LOG_DROP
-j DROP
29 /sbin
/iptables
-N LOG_REJECT
30 /sbin
/iptables
-A LOG_REJECT
-m limit
--limit 10/minute
-j LOG
31 /sbin
/iptables
-A LOG_REJECT
-j REJECT
33 # This chain will log, then DROPs packets with certain bad combinations
34 # of flags might indicate a port-scan attempt (xmas, null, etc)
35 /sbin
/iptables
-N PSCAN
36 if [ "$DROPPORTSCAN" == "on" ]; then
37 /sbin
/iptables
-A PSCAN
-p tcp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_TCP Scan " -m comment
--comment "DROP_TCP PScan"
38 /sbin
/iptables
-A PSCAN
-p udp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_UDP Scan " -m comment
--comment "DROP_UPD PScan"
39 /sbin
/iptables
-A PSCAN
-p icmp
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_ICMP Scan " -m comment
--comment "DROP_ICMP PScan"
40 /sbin
/iptables
-A PSCAN
-f -m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_FRAG Scan " -m comment
--comment "DROP_FRAG PScan"
42 /sbin
/iptables
-A PSCAN
-j DROP
-m comment
--comment "DROP_PScan"
44 # New tcp packets without SYN set - could well be an obscure type of port scan
45 # that's not covered above, may just be a broken windows machine
46 /sbin
/iptables
-N NEWNOTSYN
47 if [ "$DROPNEWNOTSYN" == "on" ]; then
48 /sbin
/iptables
-A NEWNOTSYN
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_NEWNOTSYN "
50 /sbin
/iptables
-A NEWNOTSYN
-j DROP
-m comment
--comment "DROP_NEWNOTSYN"
52 # Chain to contain all the rules relating to bad TCP flags
53 /sbin
/iptables
-N BADTCP
55 # Disallow packets frequently used by port-scanners
57 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
,URG
,PSH
-j PSCAN
59 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL NONE
-j PSCAN
61 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
-j PSCAN
62 # SYN/RST (also catches xmas variants that set SYN+RST+...)
63 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,RST SYN
,RST
-j PSCAN
64 # SYN/FIN (QueSO or nmap OS probe)
65 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,FIN SYN
,FIN
-j PSCAN
67 /sbin
/iptables
-A BADTCP
-p tcp
! --syn -m state
--state NEW
-j NEWNOTSYN
69 /sbin
/iptables
-A INPUT
-j BADTCP
70 /sbin
/iptables
-A FORWARD
-j BADTCP
75 /sbin
/iptables
-F REDINPUT
76 /sbin
/iptables
-F REDFORWARD
77 /sbin
/iptables
-t nat
-F REDNAT
80 if [ "$IFACE" != "" ]; then
82 if [ "$DEVICE" != "" ]; then
83 /sbin
/iptables
-A REDINPUT
-i $DEVICE -j ACCEPT
85 if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then
86 if [ "$RED_DEV" != "" ]; then
87 /sbin
/iptables
-A REDINPUT
-i $RED_DEV -j ACCEPT
93 if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then
94 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
95 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
99 if [ "$ORANGE_DEV" != "" ]; then
100 # This rule enables a host on ORANGE network to connect to the outside
101 # (only if we have a red connection)
102 if [ "$IFACE" != "" ]; then
103 /sbin
/iptables
-A REDFORWARD
-i $ORANGE_DEV -p tcp
-o $IFACE -j ACCEPT
104 /sbin
/iptables
-A REDFORWARD
-i $ORANGE_DEV -p udp
-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
154 /sbin
/iptables
-N GUIINPUT
155 /sbin
/iptables
-A INPUT
-j GUIINPUT
156 /sbin
/iptables
-A GUIINPUT
-p icmp
--icmp-type 8 -j ACCEPT
158 # Accept everything connected
159 /sbin
/iptables
-A INPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
160 /sbin
/iptables
-A FORWARD
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
162 # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything
163 /sbin
/iptables
-N IPSECVIRTUAL
164 /sbin
/iptables
-N OPENSSLVIRTUAL
165 /sbin
/iptables
-A INPUT
-j IPSECVIRTUAL
-m comment
--comment "IPSECVIRTUAL INPUT"
166 /sbin
/iptables
-A INPUT
-j OPENSSLVIRTUAL
-m comment
--comment "OPENSSLVIRTUAL INPUT"
167 /sbin
/iptables
-A FORWARD
-j IPSECVIRTUAL
-m comment
--comment "IPSECVIRTUAL FORWARD"
168 /sbin
/iptables
-A FORWARD
-j OPENSSLVIRTUAL
-m comment
--comment "OPENSSLVIRTUAL FORWARD"
171 /sbin
/iptables
-A FORWARD
-j OUTGOINGFW
173 # localhost and ethernet.
174 /sbin
/iptables
-A INPUT
-i lo
-m state
--state NEW
-j ACCEPT
175 /sbin
/iptables
-A INPUT
-s 127.0.0.0/8 -m state
--state NEW
-j DROP
# Loopback not on lo
176 /sbin
/iptables
-A INPUT
-d 127.0.0.0/8 -m state
--state NEW
-j DROP
177 /sbin
/iptables
-A FORWARD
-i lo
-m state
--state NEW
-j ACCEPT
178 /sbin
/iptables
-A FORWARD
-s 127.0.0.0/8 -m state
--state NEW
-j DROP
179 /sbin
/iptables
-A FORWARD
-d 127.0.0.0/8 -m state
--state NEW
-j DROP
180 /sbin
/iptables
-A INPUT
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
-p ! icmp
181 /sbin
/iptables
-A FORWARD
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
183 # If a host on orange tries to initiate a connection to IPFire's red IP and
184 # the connection gets DNATed back through a port forward to a server on orange
185 # we end up with orange -> orange traffic passing through IPFire
186 [ "$ORANGE_DEV" != "" ] && /sbin
/iptables
-A FORWARD
-i $ORANGE_DEV -o $ORANGE_DEV -m state
--state NEW
-j ACCEPT
188 # allow DHCP on BLUE to be turned on/off
189 /sbin
/iptables
-N DHCPBLUEINPUT
190 /sbin
/iptables
-A INPUT
-j DHCPBLUEINPUT
193 /sbin
/iptables
-N IPSECPHYSICAL
194 /sbin
/iptables
-A INPUT
-j IPSECPHYSICAL
197 /sbin
/iptables
-N OPENSSLPHYSICAL
198 /sbin
/iptables
-A INPUT
-j OPENSSLPHYSICAL
201 /sbin
/iptables
-N WIRELESSINPUT
202 /sbin
/iptables
-A INPUT
-m state
--state NEW
-j WIRELESSINPUT
203 /sbin
/iptables
-N WIRELESSFORWARD
204 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j WIRELESSFORWARD
206 # RED chain, used for the red interface
207 /sbin
/iptables
-N REDINPUT
208 /sbin
/iptables
-A INPUT
-j REDINPUT
209 /sbin
/iptables
-N REDFORWARD
210 /sbin
/iptables
-A FORWARD
-j REDFORWARD
211 /sbin
/iptables
-t nat
-N REDNAT
212 /sbin
/iptables
-t nat
-A POSTROUTING
-j REDNAT
216 # DMZ pinhole chain. setdmzholes setuid prog adds rules here to allow
217 # ORANGE to talk to GREEN / BLUE.
218 /sbin
/iptables
-N DMZHOLES
219 if [ "$ORANGE_DEV" != "" ]; then
220 /sbin
/iptables
-A FORWARD
-i $ORANGE_DEV -m state
--state NEW
-j DMZHOLES
223 # XTACCESS chain, used for external access
224 /sbin
/iptables
-N XTACCESS
225 /sbin
/iptables
-A INPUT
-m state
--state NEW
-j XTACCESS
227 # PORTFWACCESS chain, used for portforwarding
228 /sbin
/iptables
-N PORTFWACCESS
229 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j PORTFWACCESS
231 # Custom prerouting chains (for transparent proxy and port forwarding)
232 /sbin
/iptables
-t nat
-N SQUID
233 /sbin
/iptables
-t nat
-A PREROUTING
-j SQUID
234 /sbin
/iptables
-t nat
-N PORTFW
235 /sbin
/iptables
-t nat
-A PREROUTING
-j PORTFW
237 # upnp chain for our upnp daemon
238 /sbin
/iptables
-t nat
-N UPNPFW
239 /sbin
/iptables
-t nat
-A PREROUTING
-j UPNPFW
242 # Custom mangle chain (for port fowarding)
243 /sbin
/iptables
-t mangle
-N PORTFWMANGLE
244 /sbin
/iptables
-t mangle
-A PREROUTING
-j PORTFWMANGLE
246 # Postrouting rules (for port forwarding)
247 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 1 -j SNAT \
248 --to-source $GREEN_ADDRESS
249 if [ "$BLUE_DEV" != "" ]; then
250 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 2 -j SNAT
--to-source $BLUE_ADDRESS
252 if [ "$ORANGE_DEV" != "" ]; then
253 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 3 -j SNAT
--to-source $ORANGE_ADDRESS
256 # run local firewall configuration, if present
257 if [ -x /etc
/sysconfig
/firewall.
local ]; then
258 /etc
/sysconfig
/firewall.
local start
261 # last rule in input and forward chain is for logging.
263 if [ "$DROPINPUT" == "on" ]; then
264 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_INPUT "
266 /sbin
/iptables
-A INPUT
-j DROP
-m comment
--comment "DROP_INPUT"
267 if [ "$DROPOUTPUT" == "on" ]; then
268 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_OUTPUT "
270 /sbin
/iptables
-A FORWARD
-j DROP
-m comment
--comment "DROP_OUTPUT"
274 /usr
/local
/bin
/openvpnctrl
--create-chains-and-rules
278 # Accept everyting connected
279 /sbin
/iptables
-A INPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
281 # localhost and ethernet.
282 /sbin
/iptables
-A INPUT
-i lo
-j ACCEPT
283 /sbin
/iptables
-A INPUT
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
285 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
286 /sbin
/iptables
-A INPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
287 /sbin
/iptables
-A INPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
289 if [ "$PROTOCOL" == "RFC1483" -a "$METHOD" == "DHCP" ]; then
290 /sbin
/iptables
-A INPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
291 /sbin
/iptables
-A INPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
294 # run local firewall configuration, if present
295 if [ -x /etc
/sysconfig
/firewall.
local ]; then
296 /etc
/sysconfig
/firewall.
local stop
299 if [ "$DROPINPUT" == "on" ]; then
300 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_INPUT "
302 /sbin
/iptables
-A INPUT
-j DROP
-m comment
--comment "DROP_INPUT"
303 if [ "$DROPOUTPUT" == "on" ]; then
304 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "DROP_OUTPUT "
306 /sbin
/iptables
-A FORWARD
-j DROP
-m comment
--comment "DROP_OUTPUT"
310 /usr
/local
/bin
/openvpnctrl
--delete-chains-and-rules
315 # run local firewall configuration, if present
316 if [ -x /etc
/sysconfig
/firewall.
local ]; then
317 /etc
/sysconfig
/firewall.
local reload
325 echo "Usage: $0 {start|stop|reload|restart}"