source: freewrt/package/iptables/files/firewall.init@ 1f0c6bf

freewrt_1_0 freewrt_2_0
Last change on this file since 1f0c6bf was cf0d868, checked in by Thorsten Glaser <tg@…>, 19 years ago

ash doesn't do fall-through

git-svn-id: svn://www.freewrt.org/trunk/freewrt@273 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100755
File size: 2.8 KB
Line 
1#!/bin/sh
2
3. /etc/rc.conf
4. /etc/functions.sh
5
6WAN=$(nvram get wan_ifname)
7LAN=$(nvram get lan_ifname)
8
9case $1 in
10autostart)
11 test x"$firewall" = x"NO" && exit 0
12 exec $0 start
13 ;;
14start)
15 iptables -N input_rule
16 iptables -N output_rule
17 iptables -N forwarding_rule
18
19 iptables -t nat -N prerouting_rule
20 iptables -t nat -N postrouting_rule
21
22 ### INPUT
23 ### (connections with the router as destination)
24
25 # base case
26 iptables -P INPUT DROP
27 iptables -A INPUT -m state --state INVALID -j DROP
28 iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
29 iptables -A INPUT -p tcp --tcp-flags SYN SYN --tcp-option \! 2 -j DROP
30
31 #
32 # insert accept rule or to jump to new accept-check table here
33 #
34 iptables -A INPUT -j input_rule
35
36 # allow
37 iptables -A INPUT ${WAN:+\! -i $WAN} -j ACCEPT # allow from all interfaces except for wan
38 iptables -A INPUT -p icmp -j ACCEPT # allow ICMP
39 iptables -A INPUT -p gre -j ACCEPT # allow GRE
40 # allow ssh from remote
41 iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j ACCEPT
42 iptables -A input_rule -i $WAN -p tcp --dport 22 -j ACCEPT
43
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
47
48 ### OUTPUT
49 # (connections with the router as source)
50
51 # base case
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
55
56 #
57 # insert accept rule or to jump to new accept-check table here
58 #
59 iptables -A OUTPUT -j output_rule
60
61 # allow
62 iptables -A OUTPUT -j ACCEPT #allow everything out
63
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
67
68 ### FORWARDING
69 ### (connections routed through the router)
70
71 # base case
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
76
77 #
78 # insert accept rule or to jump to new accept-check table here
79 #
80 iptables -A FORWARD -j forwarding_rule
81
82 # allow
83 iptables -A FORWARD -i br0 -o br0 -j ACCEPT
84 [ -z "$WAN" ] || iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT
85
86 # reject (what to do with anything not allowed earlier)
87 # uses the default -P DROP
88
89 ### MASQ
90 iptables -t nat -A PREROUTING -j prerouting_rule
91 iptables -t nat -A POSTROUTING -j postrouting_rule
92 [ -z "$WAN" ] || iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
93 ;;
94stop)
95 ## CLEAR TABLES
96 for T in filter nat; do
97 iptables -t $T -F
98 iptables -t $T -X
99 done
100 ;;
101restart)
102 $0 stop
103 $0 start
104 ;;
105*)
106 echo "Usage: $0 {start | stop | restart}"
107 ;;
108esac
109exit 0
Note: See TracBrowser for help on using the repository browser.