3 ## Please make changes in /etc/firewall.user
7 . /etc/network.overrides
8 [ -e /etc/config/network] && . /etc/config/network
9 WAN=$(nvram get wan_ifname)
10 LAN=$(nvram get lan_ifname)
13 for T in filter nat mangle; do
18 iptables -N input_rule
19 iptables -N output_rule
20 iptables -N forwarding_rule
22 iptables -t nat -N prerouting_rule
23 iptables -t nat -N postrouting_rule
26 ### (connections with the router as destination)
29 iptables -P INPUT DROP
30 iptables -A INPUT -m state --state INVALID -j DROP
31 iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
32 iptables -A INPUT -p tcp --tcp-flags SYN SYN --tcp-option \! 2 -j DROP
35 # insert accept rule or to jump to new accept-check table here
37 iptables -A INPUT -j input_rule
40 iptables -A INPUT -i \! $WAN -j ACCEPT # allow from lan/wifi interfaces
41 iptables -A INPUT -p icmp -j ACCEPT # allow ICMP
42 iptables -A INPUT -p gre -j ACCEPT # allow GRE
44 # reject (what to do with anything not allowed earlier)
45 iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset
46 iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable
49 ### (connections with the router as source)
52 iptables -P OUTPUT DROP
53 iptables -A OUTPUT -m state --state INVALID -j DROP
54 iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
57 # insert accept rule or to jump to new accept-check table here
59 iptables -A OUTPUT -j output_rule
62 iptables -A OUTPUT -j ACCEPT #allow everything out
64 # reject (what to do with anything not allowed earlier)
65 iptables -A OUTPUT -p tcp -j REJECT --reject-with tcp-reset
66 iptables -A OUTPUT -j REJECT --reject-with icmp-port-unreachable
69 ### (connections routed through the router)
72 iptables -P FORWARD DROP
73 iptables -A FORWARD -m state --state INVALID -j DROP
74 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
75 iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
78 # insert accept rule or to jump to new accept-check table here
80 iptables -A FORWARD -j forwarding_rule
83 iptables -A FORWARD -i br0 -o br0 -j ACCEPT
84 iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT
86 # reject (what to do with anything not allowed earlier)
87 # uses the default -P DROP
90 iptables -t nat -A PREROUTING -j prerouting_rule
91 iptables -t nat -A POSTROUTING -j postrouting_rule
92 iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
95 [ -f /etc/firewall.user ] && . /etc/firewall.user