Add the following scripts under /etc/ppp/
(requires root privilege):
common
#!/bin/sh
# add/delete route only if device is in a specific intranet IP address block,
# change this value to YOUR network.
INTRANET_BLOCK='10.230'
# Element order in array determines interface priority
# you can add more interfaces to this list to meet your needs
NETWORK_INTERFACES=(
'bridge0' # Thunderbolt bridge
'en0' # WiFi
)
function is_intranet()
{
local interface=$1
local inet=$(/sbin/ifconfig "$interface" inet | /usr/bin/grep "inet $INTRANET_BLOCK")
if [ -n "$inet" ]; then
return 0
else
return 1
fi
}
function add_route()
{
local interface=$1
local default_gateway=$(/usr/sbin/netstat -rn | /usr/bin/grep default | /usr/bin/grep "$interface" | /usr/bin/awk '{print $2}')
/sbin/route -n add -net "$INTRANET_BLOCK" "$default_gateway"
}
function delete_route()
{
/sbin/route delete -net "$INTRANET_BLOCK"
}
ip-up
#!/bin/sh
source /etc/ppp/common
for i in "${NETWORK_INTERFACES[@]}"
do
if is_intranet $i; then
add_route $i
exit 0
fi
done
ip-down
#!/bin/sh
source /etc/ppp/common
for i in "${NETWORK_INTERFACES[@]}"
do
if is_intranet $i; then
delete_route $i
exit 0
fi
done
sudo chmod 755 [script]
netstat -nr