developer | 056f6de | 2023-01-18 16:10:07 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | if [ "$1" == "start" ]; then |
| 4 | if [ ! -n "$2" ]; then |
| 5 | echo "Error IP is necessary" |
| 6 | exit 0 |
| 7 | fi |
| 8 | if [ ! -n "$3" ]; then |
| 9 | echo "Error netmask is necessary" |
| 10 | exit 0 |
| 11 | fi |
| 12 | if [ ! -n "$4" ]; then |
| 13 | echo "Error gateway is necessary" |
| 14 | exit 0 |
| 15 | fi |
| 16 | |
| 17 | ifconfig erouter0 $2 netmask $3 up |
| 18 | route add default gw $4 dev erouter0 |
| 19 | iptables -t nat -D POSTROUTING -o erouter0 -j MASQUERADE |
| 20 | iptables -t nat -I POSTROUTING -o erouter0 -j MASQUERADE |
| 21 | elif [ "$1" == "stop" ]; then |
| 22 | ifconfig erouter0 0.0.0.0 up |
| 23 | iptables -t nat -D POSTROUTING -o erouter0 -j MASQUERADE |
| 24 | else |
| 25 | echo "Useage: $0 <start/stop> <ip> <mask> <gw>" |
| 26 | fi |