-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipa-route.sh
50 lines (41 loc) · 1.45 KB
/
pipa-route.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
44
45
46
47
48
49
50
#!/bin/bash
if [ "$#" -le 1 ]; then
echo "Usage: pipa-route.sh <add|delete> [gateway]"
exit 1
fi
ACTION=$1
GATEWAY=$2
SYSTEM=`uname -s`
echo "determined system type is $SYSTEM"
if [ "$ACTION" = "add" ]; then
echo "adding routes for private IP address space through gateway $GATEWAY"
# routes for macOS
if [ "$SYSTEM" = "Darwin" ]; then
route add -net 10.0.0.0/8 $GATEWAY
route add -net 172.16.0.0/12 $GATEWAY
route add -net 192.168.0.0/16 $GATEWAY
fi
# routes for Linux
if [ "$SYSTEM" = "Linux" ]; then
route add -net 10.0.0.0 netmask 255.0.0.0 gw $GATEWAY
route add -net 172.16.0.0 netmask 255.240.0.0 gw $GATEWAY
route add -net 192.168.0.0 netmask 255.255.0.0 gw $GATEWAY
fi
fi
if [ "$ACTION" = "delete" ]; then
echo "deleting routes for private IP address spaces"
# routes for macOS
if [ "$SYSTEM" = "Darwin" ]; then
GATEWAY=$(netstat -rn | grep -E '^10\s+' | awk '{print $2}')
route delete -net 10.0.0.0/8 $GATEWAY
route delete -net 172.16.0.0/12 $GATEWAY
route delete -net 192.168.0.0/16 $GATEWAY
fi
# routes for Linux
if [ "$SYSTEM" = "Linux" ]; then
GATEWAY=$(route -n | grep '10.0.0.0' | awk '{print $2}')
route delete -net 10.0.0.0 netmask 255.0.0.0 gw $GATEWAY
route delete -net 172.16.0.0 netmask 255.240.0.0 gw $GATEWAY
route delete -net 192.168.0.0 netmask 255.255.0.0 gw $GATEWAY
fi
fi