Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to use a Windows VPN but only for a particular network, so that it doesn't take over my entire network connection.

e.g., Instead of the VPN becoming the default route, make it only the route for

(I can see that there is a solution for this for Ubuntu in this question, but sometimes I have to do this on Windows too)

Can this be automated so that whenever I connect to the VPN it does this?

share|improve this question

11 Answers 11

up vote 66 down vote accepted

You can turn off taking over your entire connection by going to the properties of the VPN, Networking tab, "Internet Protocol (TCP/IP)" properties, Advanced, untick "Use default gateway on remote network". This may or may not leave a route to depending on the VPN server's setup. If it doesn't, you'll have to manually add the route each time, although you could put it in a batch file.

In order to manually add the route, run (as administrator):

route -p add mask

This example will make a persistent (it's not necessary to run the command after a reboot) route to the IP through the VPN gateway

More about this at http://technet.microsoft.com/en-us/library/bb878117.aspx

share|improve this answer
"You'll have to manually add the route" ... how? How does someone force, let's say, "" to go through the vpn, but nothing else? –  Timothy Khouri Jun 11 '11 at 2:16
Personally, I found just turning off the checkbox was enough. I did not have to add any routes. I verified everything is going where I would expect it to via numerous tracerts. –  eidylon Sep 28 '11 at 20:05
Same, this checkbox was all that was needed. –  Luk Sep 6 '12 at 20:59
Please clarify. Which traffic is routed over the VPN? Is it just traffic targetted to the IP of the VPN server? For example, if the VPN connection goes to "my.domain.com", then does that mean all traffic on the client to "my.domain.com" goes over the VPN, and everything else goes to the default gateway? –  Triynko Sep 25 '12 at 0:06
I used "route print" command, and verified that the routes Windows 7 generated were dead wrong. It was not sending traffic addressed to my VPN's IP to the VPN... instead it was sending it to my local gateway. There were also a few circular entries in the table. I deleted the route Windows created, then manually added the correct route so that my VPN server's IP address entry would use the VPN's gateway and local IP of the client for the interface. Traffic to my VPN server was then successfully routed through the VPN tunnel, and all other traffic was unaffected as expected. Works well. –  Triynko Sep 25 '12 at 7:13

I successfully used @TRS-80's technique to achieve this.

I work from home and have to VPN onto the corporate network for my email (I hate webmail!!).

At the same time, I need to be constantly surfing for info and also need youtube for my background music... Now you definitely don't want to stream youtube off a VPN since that makes it sound like a Robot Singing!!! :)

All I did was follow @TRS-80:

properties of the VPN, Networking tab, "Internet Protocol (TCP/IP)" properties, Advanced, untick "Use default gateway on remote network"

and then did my own:

under DNS tab, tick "register this connections addresses in DNS"

All works seamlessly!

share|improve this answer

Granted this answer does not reflect your request but i use a VM specifically for this purpose. That way only the network inside the VM is restricted by the routes.

You may find some better answers by other people but at least this may give you something to consider as it an easy solution after the VM has been created.

share|improve this answer
This is a good solution provided your hardware can handle it well. –  Enigma Feb 7 '13 at 15:16

if you have both IPV4 and IPV6 you have to uncheck the "Use default gateway on remote network" in both places, even if you only use IPV4

share|improve this answer

If you use the CMAK and setup a routing file that the client can download... windows will download the routing file & adjust routes as appropriate. There are options to remove the default route... and add various static routes & such. This is known as a split-tunnel btw.

There is a good how-to here: http://blogs.technet.com/b/rrasblog/archive/2007/06/11/split-tunnelling-using-cmak.aspx

share|improve this answer

A little old but I found a way to do this using another machine. I have a laptop where I set up the VPN connection and on there I have FreeProxy set up with Socks5..

Then I set up firefox on my client machine to use the laptop's proxy server.. the result is that if I use FireFox or anything that's set up to use that Socks5 proxy, it will use the VPN, otherwise it uses standard routing..

share|improve this answer

Didn't find here free solution for my needs. And I have written it by myself.

If you want to work with some VPN servers with dynamic client and server IP, you can try free tool http://www.latestbit.com/winvpnhelper

share|improve this answer
Is this tool still working? I tried running on Win7 and it says my_socket failed 2, cannot talk to kernel module –  test30 Aug 26 '14 at 23:49
It should work. I'll check it. –  abdmob Aug 28 '14 at 8:48
Still working for me in Windows 7 64 bit. Could you send me full log? –  abdmob Aug 28 '14 at 10:02
I am not currently on my windows machine, but could you tell me how can I verify that I can get rid of this error my_socket failed 2, cannot talk to kernel module? (of course I had ran install_svc.bat as administrator) –  test30 Aug 28 '14 at 11:37
install_svc.bat? Are you sure that we are talking about the same tool? There is nothing like 'install_svc.bat' in my tool distribution package. It's not even windows service (just console tool). –  abdmob Aug 31 '14 at 13:24

You can use something like netcatcher - just add all the routes you need one time and forget it. It will automatically add and delete routes when you connect or disconnect your VPN session. If your VPN IP address is dynamically obtained (DHCP) netcatcher will catch it and update the routes right way.

share|improve this answer
if this is something you wrote you need to disclose that anseko.com/about.html see faq –  Jeff Atwood Aug 30 '11 at 9:32

from russian forum: http://forum.ixbt.com/topic.cgi?id=14:43549

save as file (ex: vpn_route.vbs) and after vpn connected execute command

cscript vpn_route.vbs


strComputer = "."
strMACAddress = "MAC of VPN interface here (example 00:45:55:00:00:00)"
strTarget = "route target here (example"
strMask = "mask here (example"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where MACAddress = '" & strMACAddress & "'")
For Each objItem in colItems
strIP = objItem.IPAddress(0)
Set objShell = CreateObject("WScript.Shell")
objShell.Run "route add " & strTarget & " mask " & strMask & " " & strIP
share|improve this answer

I found that it needed to directly point interface in route command. Without it, Windows going to use main network card interface, instead of VPN. In my case, it looks like

route -p add mask IF 26

note the 'IF 26'.

share|improve this answer

This can't be done in Windows without using additional programs, batch files, or the command line. An alternative is to get a virtual (or physical) machine which you can run the VPN on.

It seems strange that something as easily explainable as this is so difficult to achieve. How difficult could it be to just route traffic from one program to the VPN interface and all the other programs to the default NIC interface? Why would we need to set up a whole virtual machine for that? And with Linux it's possible but its solution is not very elegant either.

It's very much sought after too: I came across dozens of threads on the same subject. So I only hope someone realises the ludicrousness of this and do something about it. (In Windows 8!)

This solution is from an unattributed batch file. It has been slightly adapted.

Instructions for Windows 7

The script will connect to and route traffic through your VPN until a reboot - you can replace route add with route -p add for the change to persist, but if you don't have a persistent IP with your VPN, it will eventually stop working when your VPN IP changes.

  1. Open the Network and Sharing Center
  2. Open the properties for your VPN connection
  3. Click the Networking tab
  4. For both IPv4 and 6:
    1. Click Properties
    2. Click Advanced
    3. Uncheck Use default gateway[...]
  5. Close everything opened from the previous steps
  6. Edit and save the batch script found below
  7. Run it as an administrator

You need to replace the following in the script:

  • <VPN> with the Name of the VPN connection you created
  • <USER> with the VPN username
  • <PASS> with the VPN password
  • <TARGET> with the IP address you want routed through the VPN (if you want to route more addresses, simply duplicate the three lines where the target is used)

Note: If you don't want to save the password in the file, replace <PASS> with %password% and add the following after the first line of the script: set password= Input password:.


@echo off
@echo make sure to be disconnected!
rasdial <VPN> /d
@echo start to connect to vpn
rasdial <VPN> <USER> <PASS>
netsh interface ip show config name="<VPN>" | findstr "IP" > ip.dat
set /p ip= < ip.dat
del ip.dat
set ip=%ip:~-12%
@echo VPN IP is %ip%

set target=<TARGET>
@echo Add route for %target%
route add %target% mask %ip%

timeout /T 3 > nul
share|improve this answer

protected by Community Feb 2 at 12:34

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.