fix firewall script, add ar7 network if into the bridge by default
[openwrt.git] / package / base-files / default / etc / init.d / S45firewall
1 #!/bin/sh
2
3 ## Please make changes in /etc/firewall.user
4 ${FAILSAFE:+exit}
5
6 . /etc/functions.sh
7 . /etc/network.overrides
8 [ -e /etc/config/network ] && . /etc/config/network
9
10 WAN=$(nvram get wan_ifname)
11 LAN=$(nvram get lan_ifname)
12
13 ## CLEAR TABLES
14 for T in filter nat mangle; do
15 iptables -t $T -F
16 iptables -t $T -X
17 done
18
19 iptables -N input_rule
20 iptables -N output_rule
21 iptables -N forwarding_rule
22
23 iptables -t nat -N prerouting_rule
24 iptables -t nat -N postrouting_rule
25
26 ### INPUT
27 ### (connections with the router as destination)
28
29 # base case
30 iptables -P INPUT DROP
31 iptables -A INPUT -m state --state INVALID -j DROP
32 iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
33 iptables -A INPUT -p tcp --tcp-flags SYN SYN --tcp-option \! 2 -j DROP
34
35 #
36 # insert accept rule or to jump to new accept-check table here
37 #
38 iptables -A INPUT -j input_rule
39
40 # allow
41 iptables -A INPUT ${WAN:+-i \! $WAN} -j ACCEPT # allow from lan/wifi interfaces
42 iptables -A INPUT -p icmp -j ACCEPT # allow ICMP
43 iptables -A INPUT -p gre -j ACCEPT # allow GRE
44
45 # reject (what to do with anything not allowed earlier)
46 iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset
47 iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable
48
49 ### OUTPUT
50 ### (connections with the router as source)
51
52 # base case
53 iptables -P OUTPUT DROP
54 iptables -A OUTPUT -m state --state INVALID -j DROP
55 iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
56
57 #
58 # insert accept rule or to jump to new accept-check table here
59 #
60 iptables -A OUTPUT -j output_rule
61
62 # allow
63 iptables -A OUTPUT -j ACCEPT #allow everything out
64
65 # reject (what to do with anything not allowed earlier)
66 iptables -A OUTPUT -p tcp -j REJECT --reject-with tcp-reset
67 iptables -A OUTPUT -j REJECT --reject-with icmp-port-unreachable
68
69 ### FORWARDING
70 ### (connections routed through the router)
71
72 # base case
73 iptables -P FORWARD DROP
74 iptables -A FORWARD -m state --state INVALID -j DROP
75 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
76 iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
77
78 #
79 # insert accept rule or to jump to new accept-check table here
80 #
81 iptables -A FORWARD -j forwarding_rule
82
83 # allow
84 iptables -A FORWARD -i br0 -o br0 -j ACCEPT
85 [ -z "$WAN" ] || iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT
86
87 # reject (what to do with anything not allowed earlier)
88 # uses the default -P DROP
89
90 ### MASQ
91 iptables -t nat -A PREROUTING -j prerouting_rule
92 iptables -t nat -A POSTROUTING -j postrouting_rule
93 [ -z "$WAN" ] || iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
94
95 ## USER RULES
96 [ -f /etc/firewall.user ] && . /etc/firewall.user
This page took 0.058538 seconds and 5 git commands to generate.