How to add persistent route for 2 VPN connections when interface # varies?

10,828

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.

Share:
10,828

Related videos on Youtube

Hanuman
Author by

Hanuman

Assumption is the mother of all fuck ups.

Updated on September 18, 2022

Comments

  • Hanuman
    Hanuman over 1 year

    I need to configure split tunnelling with persistent routes for 2 VPN connections on the same computer as the user needs to connect to 2 different corporate servers at the same time. I have a problem though as the VPN interface # varies in some instances and thus the routes are not being used properly and consistently when the VPN connections are established.

    Here are the routes I added:

    route add -p 192.168.10.0 mask 255.255.255.0 0.0.0.0 IF 24
    route add -p 10.8.18.0 mask 255.255.255.0 0.0.0.0 IF 23
    

    24 being the VPN interface number for VPN 1, 23 for VPN 2. See below.

    C:\Windows\system32>route print
    ===========================================================================
    Interface List
     24...........................VPN 1
     23...........................VPN 2
     17...da d1 cb e2 2c ad ......Apple Mobile Device Ethernet
      1...........................Software Loopback Interface 1
     12...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
     13...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
     14...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
     16...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #3
    ===========================================================================
    

    If I add the routes after connecting to the VPNs then it all works fine but if I disconnect the two VPN connections and then reconnect them in a different order, then the routes are messed up and obviously I can't access the remote networks.

    Is there any another way to make the route use a specific interface persistently?

  • Hanuman
    Hanuman over 8 years
    This is not viable. The VPN connections are made from an off site laptop.
  • Hanuman
    Hanuman over 8 years
    Anyone else has some suggestions?
  • Hanuman
    Hanuman about 8 years
    I tried PowerShell. It returns the following error: PS C:\WINDOWS\system32> Add-VpnConnectionRoute -ConnectionName "VPN 1" -DestinationPrefix "192.168.10.0/16" Add-VpnConnectionRoute : Invalid parameter DestinationPrefix 192.168.10.0/16. : The parameter is incorrect. At line:1 char:1 + Add-VpnConnectionRoute -ConnectionName "VPN 1" -DestinationPref ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (VPN 1:root/Microsoft/...ConnectionRoute) [Add-VpnConnectionRoute], CimExceptio n + FullyQualifiedErrorId : WIN32 87,Add-VpnConnectionRoute
  • ErikvO
    ErikvO about 8 years
    I think the IP range you provided might be invalid: 192.168.10.0/16. I think it should either be 192.168.0.0/16 or 192.168.10.0/24.
  • Hanuman
    Hanuman about 8 years
    Yeah that was dumb of me. It works now. Thank you.
  • Tilo
    Tilo over 6 years
    how to do in powershell similar as route PRINT?
  • user3513074
    user3513074 almost 6 years
    Ok any reference to "Add-VPNConnectionRoute" in Powershell is Windows 10 only. That command is not supported in Windows 7, so if you're running Windows 7 we're still screwed until someone finds a way..
  • ErikvO
    ErikvO almost 6 years
    Actually, according to the technet link I provided it works from Windows 8.1 and up, but you're right: Windows 7 (and 8.0) users still have a problem.
  • lese
    lese over 3 years
    @Tilo : similar to route print (Get-VpnConnection -Name $Name -AllUserConnection).routes