-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_nat.sh
executable file
·44 lines (40 loc) · 900 Bytes
/
setup_nat.sh
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
#!/bin/bash
function start_nat () {
if [ -z "$1" ]
then
echo "Invalid interface"
echo "setup_nat.sh <start|stop> interface"
return 1
else
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -o $1 -A POSTROUTING -j MASQUERADE
iptables -A FORWARD -j ACCEPT
return 0
fi
}
function stop_nat () {
if [ -z "$2" ]
then
echo "Invalid interface"
echo "setup_nat.sh <start|stop> interface"
return 1
else
echo 0 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -o $1 -D POSTROUTING -j MASQUERADE
iptables -D FORWARD -j ACCEPT
return 0
fi
}
case "$1" in
start)
start_nat $2
;;
stop)
stop_nat $2
;;
*)
echo "Invalid operation"
echo "setup_nat.sh <start|stop> interface"
return 2
;;
esac