Windows – add a static route to a VPN network if the default gateway IP is dynamic? (Windows 7)

networkingroutingtcpipvpnwindows

Can I add a static route to a VPN network if the default gateway IP is dynamic? (Windows 7)

This is easy to solve with a permanent route if the default gateway does not change as you can do this:

route add 10.0.0.0 mask 255.255.255.0 192.168.117.232 -p

However the VPN created by our customer's firewall assigns a dynamic IP address for the VPN's default gateway and as such, the last block of the IP can change.

Is there any way to do this via adapter only? Or using an IP range?

Best Answer

I've found out the answer myself:

You don't actually need to specify the default gateway - you can use the catch-all of 0.0.0.0 and then specify the interface number instead (the docs do not make this obvious!):

  1. Find the interface number of the VPN by running "route print" from the command prompt and use this for the IF argument in the command below.

  2. Add a static route for the IP range concerned using "route add" (with -p to make it permanent):

    route add x.x.x.x mask 255.255.255.0 0.0.0.0 IF yy -p

Of course - you need to replace the IP address (x.x.x.x) and interface number (yy) in the command above with those relevant to your system.

Thankfully the VPN interface ID doesn't seem to change when you reconnect but it will be different from computer to computer.

"route print" should then show the desired static route with the gateway address as "On-link":

===========================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
         10.0.0.0    255.255.255.0         On-link        1
===========================================================================