#!/bin/bash vpnserver="sthu.org" serverip=$(host ${vpnserver} | awk '{ print $4 }') vpnip=$(route -n | grep -m 1 "tun0" | awk '{ print $1 }') defgw=$(route -n | grep -m 1 "^0.0.0.0" | awk '{ print $2 }') defif=$(route -n | grep -m 1 "^0.0.0.0" | awk '{ print $8 }') echo "current default gw ${defgw} dev ${defif}" echo "" echo "add route to ${serverip} via dev ${defif}" route add -host $serverip gw ${defgw} dev ${defif} echo "remove old default route via gw ${defgw}" route del default gw ${defgw} echo "add default gw ${vpnip} (vpnip)" route add default gw ${vpnip} echo "" echo "Press to restore default route" read echo "restore default gw ${defgw} dev ${defif}" route add default gw ${defgw} dev ${defif} echo "remove default route" route del default gw ${vpnip} echo "remove route to ${serverip}" route del ${serverip} gw ${defgw}