-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup_iptables
executable file
·42 lines (38 loc) · 981 Bytes
/
setup_iptables
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
#!/bin/bash
MODE=$1
LAN_IFACE=br0
WAN_IFACE=br1
CAPTIVE_IP=192.168.133.7
clear_iptables() {
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
}
case "$MODE" in
captive)
clear_iptables
iptables -t mangle -N internet
iptables -t mangle -A PREROUTING -i $LAN_IFACE -p tcp -m tcp --dport 80 -j internet
iptables -t mangle -A internet -j MARK --set-mark 99
iptables -t nat -A PREROUTING -i $LAN_IFACE -p tcp -m mark --mark 99 -m tcp --dport 80 -j DNAT --to-destination $CAPTIVE_IP
;;
nat)
clear_iptables
iptables -t nat -A POSTROUTING -o $WAN_IFACE -j MASQUERADE
iptables -A FORWARD -i $WAN_IFACE -o $LAN_IFACE -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $LAN_IFACE -o $WAN_IFACE -j ACCEPT
;;
clear)
clear_iptables
;;
*)
echo "Usage: $0 {captive|nat|clear}" >&2
exit 1
;;
esac