-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnet.macos.sh
executable file
·82 lines (71 loc) · 2.46 KB
/
net.macos.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
#* reason -- why this script was called, one of: pre-init connect disconnect
#* VPNGATEWAY -- vpn gateway address (always present)
#* TUNDEV -- tunnel device (always present)
#* INTERNAL_IP4_ADDRESS -- address (always present)
#* INTERNAL_IP4_NETMASK -- netmask (often unset)
#* INTERNAL_IP4_NETMASKLEN -- netmask length (often unset)
#* INTERNAL_IP4_NETADDR -- address of network (only present if netmask is set)
#* INTERNAL_IP4_DNS -- list of dns serverss
#* INTERNAL_IP4_NBNS -- list of wins servers
#* CISCO_DEF_DOMAIN -- default domain name
#* CISCO_BANNER -- banner from server
#* CISCO_SPLIT_INC -- number of networks in split-network-list
#* CISCO_SPLIT_INC_%d_ADDR -- network address
#* CISCO_SPLIT_INC_%d_MASK -- subnet mask (for example: 255.255.255.0)
#* CISCO_SPLIT_INC_%d_MASKLEN -- subnet masklen (for example: 24)
#* CISCO_SPLIT_INC_%d_PROTOCOL -- protocol (often just 0)
#* CISCO_SPLIT_INC_%d_SPORT -- source port (often just 0)
#* CISCO_SPLIT_INC_%d_DPORT -- destination port (often just 0)
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# Override DNS servers, if needed
#INTERNAL_IP4_DNS="10.0.0.1 10.0.0.2"
# Specify here the routes you want to add
INTERNAL_ROUTES="10.42.0.0/24 172.31.33.0/24"
# Specify here the service name, if you want to run multiple VPNs at the same time.
SERVICE_NAME="org.foobar.myvpn"
configure_iface () {
ifconfig "$TUNDEV" inet "$INTERNAL_IP4_ADDRESS" "$INTERNAL_IP4_ADDRESS" \
netmask 255.255.255.255 mtu ${INTERNAL_IP4_MTU:-1412} up
}
set_routes() {
for route in $INTERNAL_ROUTES; do
route add "$route" -iface "$TUNDEV" >/dev/null
done
}
set_dns() {
sudo scutil <<EOF
d.init
d.add Addresses * $INTERNAL_IP4_ADDRESS
d.add DestAddresses * $INTERNAL_IP4_ADDRESS
d.add InterfaceName $TUNDEV
set State:/Network/Service/$SERVICE_NAME/IPv4
d.init
d.add SupplementalMatchDomains * $CISCO_DEF_DOMAIN
d.add ServerAddresses * $INTERNAL_IP4_DNS
set State:/Network/Service/$SERVICE_NAME/DNS
EOF
}
unset_dns() {
sudo scutil <<EOF
remove State:/Network/Service/$SERVICE_NAME/DNS
remove State:/Network/Service/$SERVICE_NAME/IPv4
EOF
}
case "$reason" in
pre-init)
;;
connect)
mkdir -p /var/run/vpnc
configure_iface
set_dns
set_routes
;;
disconnect)
unset_dns
;;
*)
exit 0
;;
esac
exit 0