A 'short' guide for noobs like me, who don't know much about networks. Not much new here, but a summary of all good options described in previous answers and in other related threads. Whole procedure consists of 3 basic steps:
1) Make all traffic NOT going via VPN. For this you must uncheck Use default gateway on remote network
checkbox in VPN settings. Make sure to uncheck this checkbox for both IPv4 and IPv6. Usually I simply disable IPv6 protocol completely for VPN connection.
(!) It is (sometimes) possible that unchecking that checkbox will be enough for normal work - in my experience, necessary routes (which will direct necessary traffic via VPN) can be added automatically after VPN connection is established. I don't know exactly where and how these rules are configured, but such scenario exists - probably it is some magic done by VPN network administrators.
2) Make only necessary traffic going via VPN. For this you need to define routes. Here you have 3 options:
2.1) Add permanent route via VPN gateway:
route -p add a.b.c.d/<CIDR> w.x.y.z
or route -p add a.b.c.d mask e.f.g.h w.x.y.z
where 'VPN gateway' = 'your IP on VPN network' = w.x.y.z
and target address/network = a.b.c.d
. You can find w.x.y.z
by executing ipconfig
and looking for your VPN connection name or, if you use PowerShell, you can get compact output by executing ipconfig | grep -A5 PPP
(which will output 5 lines after finding each PPP connection).
Cons: you will have to re-create routes if your VPN IP will change.
2.2) Add permanent route via VPN network interface:
route -p add a.b.c.d/<CIDR> 0.0.0.0 IF <interface number>
where a.b.c.d
is the target address/network and interface number
is identifier of your VPN connection. This ID can be found by executing netstat -rn
, or, for more compact output, netstat -rn | grep -A10 'Interface List'
.
Pros: no need to change anything if your VPN address (w.x.y.z
) will change.
Cons: need to re-create routes with new ID if you delete your VPN connection.
2.3) Use PowerShell cmdlet:
Add-VpnConnectionRoute -ConnectionName '<VPN connection name>' -DestinationPrefix a.b.c.d/<CIDR>
Pros: necessary routes are added each time VPN connection is established and deleted each time it is disconnected.
Cons: there is no Get-VpnConnectionRoutes
cmdlet so it can be hard to manage these rules.
3) Check and ensure routing works as expected!
If you added persistent routes, you can check them by executing netstat -rn | grep -A10 'Persistent Routes'
.
And, finally, run a few tracert
commands against both IP addresses which are supposed to be accessed via VPN and against those which should work without VPN.
Is there a related question for filtering a bunch of sites through VPN? It looks like the answers here will work only for the case where there's a single site behind VPN. I'm in China and about half the sites I'd like to use are blocked so should go through VPN but other sites are faster/smoother without VPN. – hippietrail – 2015-06-10T03:06:36.497
I went ahead and asked a new question: http://superuser.com/questions/925947
– hippietrail – 2015-06-10T03:18:20.687