/
act_as_gateway
executable file
·71 lines (57 loc) · 1.38 KB
/
act_as_gateway
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
#!/bin/sh -e
#
# Firewall
#
INTERNAL_IFACE=eth0
EXTERNAL_IFACE=eth1
start(){
PATH=/usr/sbin:/sbin:/bin:/usr/bin
#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT
# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! $EXTERNAL_IFACE -j ACCEPT
iptables -A FORWARD -i $EXTERNAL_IFACE -o $INTERNAL_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i $INTERNAL_IFACE -o $EXTERNAL_IFACE -j ACCEPT
# Masquerade.
iptables -t nat -A POSTROUTING -o $EXTERNAL_IFACE -j MASQUERADE
# Don't forward from the outside to the inside.
iptables -A FORWARD -i $EXTERNAL_IFACE -o $EXTERNAL_IFACE -j REJECT
# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward
}
stop(){
#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
# Disable routing.
echo 0 > /proc/sys/net/ipv4/ip_forward
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop ; start
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 1
;;
esac