Can I add a static route to a VPN network if the default gateway IP is dynamic? (Windows 7)
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?
Solution 1:
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!):
-
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.
-
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
===========================================================================
Solution 2:
The marked answer isn't valid when you have more than one VPN configured on the client.
Windows will assign a different number to the Interface of the VPN depending on which one you start first.
Let's say you have two VPN connections. They get assigned the IF number 38 if you only launch one of them. But if you launch both, one will get number 38 and the other will get number 39.
The first one to launch will be the one that gets the lower number.