Windows – How to add persistent route for VPN when interface # varies

routevpnwindows

In Windows, I can add a persistent route for an IP using the interface number of my VPN connection. However, when I reconnect to the VPN later, the interface number changes, which means the route I added previously no longer works. So each time I connect to the VPN, I have to re-add the route, using the VPN's current interface number.

For example, the VPN's route number may be 0x300003, then when I disconnect and reconnect, the route number becomes 0x320003, and so on.

Is there a way of adding a persistent route to the table which applies to a range of interface numbers? Or some other way of doing this without, each time I connect to the VPN, having to manually find the right interface # and re-add the route?

Best Answer

When multiple VPNs connect in random order, their interface IDs change. Therefor the normal ROUTE -P ADD 10.0.0.0 MASK 255.255.0.0 10.0.0.1 IF 42 does not work. The next time the VPN connects it might have a different interface number.

Powershell has a cmdlet available that adds routes on VPN connection and removes them again when the VPN is disconnected: Add-VpnConnectionRoute. It works without having to specify the interface ID.

The basic syntax is like this:

Add-VpnConnectionRoute -ConnectionName "VPN Connection Name" -DestinationPrefix 10.0.0.0/16

After entering this command, the routes will be created/removed automatically on connection/disconnection of the VPN.