]>
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 /sbin
/iptables
-A PSCAN
-p tcp
-m limit
--limit 10/minute
-j LOG
--log-prefix "TCP Scan? "
37 /sbin
/iptables
-A PSCAN
-p udp
-m limit
--limit 10/minute
-j LOG
--log-prefix "UDP Scan? "
38 /sbin
/iptables
-A PSCAN
-p icmp
-m limit
--limit 10/minute
-j LOG
--log-prefix "ICMP Scan? "
39 /sbin
/iptables
-A PSCAN
-f -m limit
--limit 10/minute
-j LOG
--log-prefix "FRAG Scan? "
40 /sbin
/iptables
-A PSCAN
-j DROP
42 # New tcp packets without SYN set - could well be an obscure type of port scan
43 # that's not covered above, may just be a broken windows machine
44 /sbin
/iptables
-N NEWNOTSYN
45 /sbin
/iptables
-A NEWNOTSYN
-m limit
--limit 10/minute
-j LOG
--log-prefix "NEW not SYN? "
46 /sbin
/iptables
-A NEWNOTSYN
-j DROP
48 # Chain to contain all the rules relating to bad TCP flags
49 /sbin
/iptables
-N BADTCP
51 # Disallow packets frequently used by port-scanners
53 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
,URG
,PSH
-j PSCAN
55 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL NONE
-j PSCAN
57 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags ALL FIN
-j PSCAN
58 # SYN/RST (also catches xmas variants that set SYN+RST+...)
59 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,RST SYN
,RST
-j PSCAN
60 # SYN/FIN (QueSO or nmap OS probe)
61 /sbin
/iptables
-A BADTCP
-p tcp
--tcp-flags SYN
,FIN SYN
,FIN
-j PSCAN
63 /sbin
/iptables
-A BADTCP
-p tcp
! --syn -m state
--state NEW
-j NEWNOTSYN
65 /sbin
/iptables
-A INPUT
-j BADTCP
66 /sbin
/iptables
-A FORWARD
-j BADTCP
71 /sbin
/iptables
-F REDINPUT
72 /sbin
/iptables
-F REDFORWARD
73 /sbin
/iptables
-t nat
-F REDNAT
76 if [ "$IFACE" != "" ]; then
78 if [ "$DEVICE" != "" ]; then
79 /sbin
/iptables
-A REDINPUT
-i $DEVICE -j ACCEPT
81 if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then
82 if [ "$RED_DEV" != "" ]; then
83 /sbin
/iptables
-A REDINPUT
-i $RED_DEV -j ACCEPT
89 if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then
90 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
91 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
95 if [ "$ORANGE_DEV" != "" ]; then
96 # This rule enables a host on ORANGE network to connect to the outside
97 # (only if we have a red connection)
98 if [ "$IFACE" != "" ]; then
99 /sbin
/iptables
-A REDFORWARD
-i $ORANGE_DEV -p tcp
-o $IFACE -j ACCEPT
100 /sbin
/iptables
-A REDFORWARD
-i $ORANGE_DEV -p udp
-o $IFACE -j ACCEPT
104 if [ "$IFACE" != "" -a -f /var
/ipfire
/red
/active
]; then
106 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
107 /sbin
/iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
108 /sbin
/iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
110 if [ "$METHOD" == "DHCP" -a "$PROTOCOL" == "RFC1483" ]; 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
115 # Outgoing masquerading
116 /sbin
/iptables
-t nat
-A REDNAT
-o $IFACE -j MASQUERADE
121 # See how we were called.
126 # Limit Packets- helps reduce dos/syn attacks
127 # original do nothing line
128 #/sbin/iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -m limit --limit 10/sec
129 # the correct one, but the negative '!' do nothing...
130 #/sbin/iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -m limit ! --limit 10/sec -j DROP
132 # Fix for braindead ISP's
133 /sbin
/iptables
-A FORWARD
-p tcp
--tcp-flags SYN
,RST SYN
-j TCPMSS
--clamp-mss-to-pmtu
135 # CUSTOM chains, can be used by the users themselves
136 /sbin
/iptables
-N CUSTOMINPUT
137 /sbin
/iptables
-A INPUT
-j CUSTOMINPUT
138 /sbin
/iptables
-N CUSTOMFORWARD
139 /sbin
/iptables
-A FORWARD
-j CUSTOMFORWARD
140 /sbin
/iptables
-N CUSTOMOUTPUT
141 /sbin
/iptables
-A OUTPUT
-j CUSTOMOUTPUT
142 /sbin
/iptables
-N OUTGOINGFW
143 /sbin
/iptables
-A OUTPUT
-j OUTGOINGFW
144 /sbin
/iptables
-t nat
-N CUSTOMPREROUTING
145 /sbin
/iptables
-t nat
-A PREROUTING
-j CUSTOMPREROUTING
146 /sbin
/iptables
-t nat
-N CUSTOMPOSTROUTING
147 /sbin
/iptables
-t nat
-A POSTROUTING
-j CUSTOMPOSTROUTING
150 /sbin
/iptables
-N GUIINPUT
151 /sbin
/iptables
-A INPUT
-j GUIINPUT
152 /sbin
/iptables
-A GUIINPUT
-p icmp
--icmp-type 8 -j ACCEPT
154 # Accept everything connected
155 /sbin
/iptables
-A INPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
156 /sbin
/iptables
-A FORWARD
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
158 # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything
159 /sbin
/iptables
-N IPSECVIRTUAL
160 /sbin
/iptables
-N OPENSSLVIRTUAL
161 /sbin
/iptables
-A INPUT
-j IPSECVIRTUAL
162 /sbin
/iptables
-A INPUT
-j OPENSSLVIRTUAL
163 /sbin
/iptables
-A FORWARD
-j IPSECVIRTUAL
164 /sbin
/iptables
-A FORWARD
-j OPENSSLVIRTUAL
167 /sbin
/iptables
-A FORWARD
-j OUTGOINGFW
169 # localhost and ethernet.
170 /sbin
/iptables
-A INPUT
-i lo
-m state
--state NEW
-j ACCEPT
171 /sbin
/iptables
-A INPUT
-s 127.0.0.0/8 -m state
--state NEW
-j DROP
# Loopback not on lo
172 /sbin
/iptables
-A INPUT
-d 127.0.0.0/8 -m state
--state NEW
-j DROP
173 /sbin
/iptables
-A FORWARD
-i lo
-m state
--state NEW
-j ACCEPT
174 /sbin
/iptables
-A FORWARD
-s 127.0.0.0/8 -m state
--state NEW
-j DROP
175 /sbin
/iptables
-A FORWARD
-d 127.0.0.0/8 -m state
--state NEW
-j DROP
176 /sbin
/iptables
-A INPUT
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
-p ! icmp
177 /sbin
/iptables
-A FORWARD
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
179 # If a host on orange tries to initiate a connection to IPFire's red IP and
180 # the connection gets DNATed back through a port forward to a server on orange
181 # we end up with orange -> orange traffic passing through IPFire
182 [ "$ORANGE_DEV" != "" ] && /sbin
/iptables
-A FORWARD
-i $ORANGE_DEV -o $ORANGE_DEV -m state
--state NEW
-j ACCEPT
184 # allow DHCP on BLUE to be turned on/off
185 /sbin
/iptables
-N DHCPBLUEINPUT
186 /sbin
/iptables
-A INPUT
-j DHCPBLUEINPUT
189 /sbin
/iptables
-N IPSECPHYSICAL
190 /sbin
/iptables
-A INPUT
-j IPSECPHYSICAL
193 /sbin
/iptables
-N OPENSSLPHYSICAL
194 /sbin
/iptables
-A INPUT
-j OPENSSLPHYSICAL
197 /sbin
/iptables
-N WIRELESSINPUT
198 /sbin
/iptables
-A INPUT
-m state
--state NEW
-j WIRELESSINPUT
199 /sbin
/iptables
-N WIRELESSFORWARD
200 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j WIRELESSFORWARD
202 # RED chain, used for the red interface
203 /sbin
/iptables
-N REDINPUT
204 /sbin
/iptables
-A INPUT
-j REDINPUT
205 /sbin
/iptables
-N REDFORWARD
206 /sbin
/iptables
-A FORWARD
-j REDFORWARD
207 /sbin
/iptables
-t nat
-N REDNAT
208 /sbin
/iptables
-t nat
-A POSTROUTING
-j REDNAT
212 # DMZ pinhole chain. setdmzholes setuid prog adds rules here to allow
213 # ORANGE to talk to GREEN / BLUE.
214 /sbin
/iptables
-N DMZHOLES
215 if [ "$ORANGE_DEV" != "" ]; then
216 /sbin
/iptables
-A FORWARD
-i $ORANGE_DEV -m state
--state NEW
-j DMZHOLES
219 # XTACCESS chain, used for external access
220 /sbin
/iptables
-N XTACCESS
221 /sbin
/iptables
-A INPUT
-m state
--state NEW
-j XTACCESS
223 # PORTFWACCESS chain, used for portforwarding
224 /sbin
/iptables
-N PORTFWACCESS
225 /sbin
/iptables
-A FORWARD
-m state
--state NEW
-j PORTFWACCESS
227 # Custom prerouting chains (for transparent proxy and port forwarding)
228 /sbin
/iptables
-t nat
-N SQUID
229 /sbin
/iptables
-t nat
-A PREROUTING
-j SQUID
230 /sbin
/iptables
-t nat
-N PORTFW
231 /sbin
/iptables
-t nat
-A PREROUTING
-j PORTFW
233 # upnp chain for our upnp daemon
234 /sbin
/iptables
-t nat
-N UPNPFW
235 /sbin
/iptables
-t nat
-A PREROUTING
-j UPNPFW
238 # Custom mangle chain (for port fowarding)
239 /sbin
/iptables
-t mangle
-N PORTFWMANGLE
240 /sbin
/iptables
-t mangle
-A PREROUTING
-j PORTFWMANGLE
242 # Postrouting rules (for port forwarding)
243 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 1 -j SNAT \
244 --to-source $GREEN_ADDRESS
245 if [ "$BLUE_DEV" != "" ]; then
246 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 2 -j SNAT
--to-source $BLUE_ADDRESS
248 if [ "$ORANGE_DEV" != "" ]; then
249 /sbin
/iptables
-t nat
-A POSTROUTING
-m mark
--mark 3 -j SNAT
--to-source $ORANGE_ADDRESS
252 # run local firewall configuration, if present
253 if [ -x /etc
/sysconfig
/firewall.
local ]; then
254 /etc
/sysconfig
/firewall.
local start
257 # last rule in input and forward chain is for logging.
258 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "INPUT "
259 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "OUTPUT "
263 /usr
/local
/bin
/openvpnctrl
--create-chains-and-rules
267 # Accept everyting connected
268 /sbin
/iptables
-A INPUT
-m state
--state ESTABLISHED
,RELATED
-j ACCEPT
270 # localhost and ethernet.
271 /sbin
/iptables
-A INPUT
-i lo
-j ACCEPT
272 /sbin
/iptables
-A INPUT
-i $GREEN_DEV -m state
--state NEW
-j ACCEPT
274 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
275 /sbin
/iptables
-A INPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
276 /sbin
/iptables
-A INPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
278 if [ "$PROTOCOL" == "RFC1483" -a "$METHOD" == "DHCP" ]; then
279 /sbin
/iptables
-A INPUT
-p tcp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
280 /sbin
/iptables
-A INPUT
-p udp
--source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
283 # run local firewall configuration, if present
284 if [ -x /etc
/sysconfig
/firewall.
local ]; then
285 /etc
/sysconfig
/firewall.
local stop
288 /sbin
/iptables
-A INPUT
-m limit
--limit 10/minute
-j LOG
--log-prefix "INPUT "
289 /sbin
/iptables
-A FORWARD
-m limit
--limit 10/minute
-j LOG
--log-prefix "OUTPUT "
293 /usr
/local
/bin
/openvpnctrl
--delete-chains-and-rules
298 # run local firewall configuration, if present
299 if [ -x /etc
/sysconfig
/firewall.
local ]; then
300 /etc
/sysconfig
/firewall.
local reload
308 echo "Usage: $0 {start|stop|reload|restart}"