blob: 15794dece2634af029d91ee5e35198e9df21dfe1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#!/bin/sh
echo "configure /etc/firewall.conf first."
exit 1
### Interfaces
WAN=ppp0
LAN=br0
WLAN=wlan0
######################################################################
### Default ruleset
######################################################################
### Create chains
iptables -N input_rule
iptables -N forwarding_rule
iptables -t nat -N prerouting_rule
iptables -t nat -N postrouting_rule
### Default policy
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
### INPUT
### (connections with the router as destination)
# base case
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --tcp-flags SYN SYN \! --tcp-option 2 -j DROP
# custom rules
iptables -A INPUT -j input_rule
# allow access from anything but WAN
iptables -A INPUT ${WAN:+\! -i $WAN} -j ACCEPT
# allow icmp messages
iptables -A INPUT -p icmp -j ACCEPT
# reject
iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset
iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable
### OUTPUT
### (connections with the router as source)
# base case
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED,NEW -j ACCEPT
iptables -A OUTPUT -p icmp -j ACCEPT
### FORWARD
### (connections routed through the router)
# base case
iptables -A FORWARD -m state --state INVALID -j DROP
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
# fix for broken ISPs blocking ICMP "fragmentation needed" packets
#iptables -t mangle -A FORWARD -p tcp -o $WAN --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
# custom rules
iptables -A FORWARD -j forwarding_rule
iptables -t nat -A PREROUTING -j prerouting_rule
iptables -t nat -A POSTROUTING -j postrouting_rule
# allow LAN
iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT
### MASQUERADING
echo 1 > /proc/sys/net/ipv4/ip_dynaddr
iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
######################################################################
### Default ruleset end
######################################################################
###
### Connections to the router
###
# ssh
#iptables -A input_rule -i $WAN -p tcp -s <a.b.c.d> --dport 22 -j ACCEPT
# IPSec
#iptables -A input_rule -i $WAN -p esp -s <a.b.c.d> -j ACCEPT
#iptables -A input_rule -i $WAN -p udp -s <a.b.c.d> --dport 500 -j ACCEPT
# OpenVPN
#iptables -A input_rule -i $WAN -p udp -s <a.b.c.d> --dport 1194 -j ACCEPT
# PPTP
#iptables -A input_rule -i $WAN -p gre -j ACCEPT
#iptables -A input_rule -i $WAN -p tcp --dport 1723 -j ACCEPT
###
### VPN traffic
###
# IPSec
#iptables -A forwarding_rule -o ipsec+ -j ACCEPT
#iptables -A forwarding_rule -i ipsec+ -j ACCEPT
# OpenVPN
#iptables -A forwarding_rule -o tun+ -j ACCEPT
#iptables -A forwarding_rule -i tun+ -j ACCEPT
###
### Port forwardings to LAN
###
#iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 3389 -j DNAT --to 192.168.1.10
#iptables -A forwarding_rule -i $WAN -p tcp --dport 3389 -d 192.168.1.10 -j ACCEPT
# Transparent Bridging Proxy
#ebtables -t broute -A BROUTING -p IPv4 --ip-protocol 6 \
# --ip-destination-port 80 -j redirect --redirect-target ACCEPT
#iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 \
# -j REDIRECT --to-port 8080
|