I recently had to help a client who was having performance issues over the VPN. They had a fast connection at home, but just a standard T1 line at the office for VPN access. When they got onto the VPN, they kept complaining about the performance while working on other items. When we unchecked the “Use default gateway on remote network” option, they were able to get better performance. However, they were unable to get to remote branches on the VPN. I searched multiple sites and merged the information from multiple places to come up with the following batch file:
@echo make sure to be disconnected!
set /p password= Input password:
@echo start to connect to vpnrasdial
netsh interface ip show config name=
set /p ip=
@echo VPN IP is %ip%
route add 192.168.1.0 mask 255.255.255.0 %ip% Metric 1
Batch File Breakdown:
The batch file requests the user password as an input. I did this since the password keeps changing and so that they wouldn’t have to keep calling. It also prevents the password from being stored in the batch file for someone else to possibly see.
Next, it checks and disconnects the VPN if it is connected.
It then dials the
Since it was for a specific user, I placed his user name for the network in the
It then dials that connection, polls the IP address of the VPN connection (since the default gateway is either blank or 0.0.0.0) and sets it up as a variable. Depending on the IP range you are using, you might need to adjust the settings on the “set ip=%ip:~-14%”. When I initially set this up and went through troubleshooting, I found that it was cutting off some of the IP address. I had to bump it up from the 12 value to a 14 value to get the initial 19 part of the 192 to fully populate.
It uses the IP that it pulled from the current VPN connection as the gateway for the destination network (branch office). Feel free to add as many routes as you have networks that are needing to be accessed. In the one I was working on, I had 10+ networks defined.
Finally, since the end user was an executive for the company, I added the batch file he used to use to re-map his network drives at the bottom of the file. I did this so he wouldn’t have to run something else when getting connected and working remotely.