1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
4 ## Please make changes in /etc/firewall.user
10 config_get WAN wan ifname
11 config_get LAN lan ifname
14 for T in filter nat; do
19 iptables -N input_rule
20 iptables -N output_rule
21 iptables -N forwarding_rule
23 iptables -t nat -N prerouting_rule
24 iptables -t nat -N postrouting_rule
26 iptables -N LAN_ACCEPT
27 [ -z "$WAN" ] || iptables -A LAN_ACCEPT -i "$WAN" -j RETURN
28 iptables -A LAN_ACCEPT -j ACCEPT
31 ### (connections with the router as destination)
34 iptables -P INPUT DROP
35 iptables -A INPUT -m state --state INVALID -j DROP
36 iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
37 iptables -A INPUT -p tcp --tcp-flags SYN SYN --tcp-option \! 2 -j DROP
40 # insert accept rule or to jump to new accept-check table here
42 iptables -A INPUT -j input_rule
45 iptables -A INPUT -j LAN_ACCEPT # allow from lan/wifi interfaces
46 iptables -A INPUT -p icmp -j ACCEPT # allow ICMP
47 iptables -A INPUT -p gre -j ACCEPT # allow GRE
49 # reject (what to do with anything not allowed earlier)
50 iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset
51 iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable
54 ### (connections with the router as source)
57 iptables -P OUTPUT DROP
58 iptables -A OUTPUT -m state --state INVALID -j DROP
59 iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
62 # insert accept rule or to jump to new accept-check table here
64 iptables -A OUTPUT -j output_rule
67 iptables -A OUTPUT -j ACCEPT #allow everything out
69 # reject (what to do with anything not allowed earlier)
70 iptables -A OUTPUT -p tcp -j REJECT --reject-with tcp-reset
71 iptables -A OUTPUT -j REJECT --reject-with icmp-port-unreachable
74 ### (connections routed through the router)
77 iptables -P FORWARD DROP
78 iptables -A FORWARD -m state --state INVALID -j DROP
79 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
80 iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
83 # insert accept rule or to jump to new accept-check table here
85 iptables -A FORWARD -j forwarding_rule
88 iptables -A FORWARD -i br0 -o br0 -j ACCEPT
89 [ -z "$WAN" ] || iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT
91 # reject (what to do with anything not allowed earlier)
92 # uses the default -P DROP
95 iptables -t nat -A PREROUTING -j prerouting_rule
96 iptables -t nat -A POSTROUTING -j postrouting_rule
97 [ -z "$WAN" ] || iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
100 [ -f /etc/firewall.user ] && . /etc/firewall.user
101 [ -n "$WAN" -a -e /etc/config/firewall ] && {
102 awk -f /usr/lib/common.awk -f /usr/lib/firewall.awk /etc/config/firewall | ash
107 iptables -P INPUT ACCEPT
108 iptables -P OUTPUT ACCEPT
109 iptables -P FORWARD ACCEPT
111 iptables -t nat -P PREROUTING ACCEPT
112 iptables -t nat -P POSTROUTING ACCEPT
113 iptables -t nat -P OUTPUT ACCEPT