Windows: OpenVPN Stop internet connection when disconnected from VPN
Last updated by Shayne M on May 22, 2013 08:56
To protect yourself against accidentally leaking your true ip if the VPN connection were to drop out we have a system of batch files you can use.
These will break your regular internet connection so that traffic will not be allowed in or out except via the VPN, and need to be manually run when you want to start and stop using the VPN.
You will need a few details about your current networking setup to continue, these can be gathered by pressing the start button, hit run, enter "cmd.exe" in the textbox and then enter. Then type "ipconfig /all" to bring up your current network adapters and settings:
Your regular network adapters name: Local Area Connection 2
Your normal ip address: 10.0.0.3
Your subnet mask: 255.255.255.0
Your default gateway: 10.0.0.138
Then you need to open a text editor like notepad and create and save these two files, somewhere handy like on your desktop.
Customise these with your own network settings, as learned above. The last ip address in protectme.bat, needs to be a fake & broken gateway address that doesn't exist in your network. In most cases you can just change it to almost any other ip besides the current one, but in crowded/larger networks you may need to get creative. For example if your gateway is really 10.0.0.138 , changing it to 10.0.1.138 should work.
ProtectMe.bat: -> This batch file is to disable your local network connection, so traffic can only pass via the VPN
netsh int ip set address "Local Area Connection 2" static 10.0.0.3 255.255.255.0 10.0.1.138
EnableLocalNet.bat-> This file will enable your local network connection again, for using your regular internet connection.
netsh int ip set address "Local Area Connection 2" static 10.0.0.3 255.255.255.0 10.0.0.138
When you're finished with the VPN and want to return settings to normal, you would disconnect, and right click "enablelocalnet.bat" and run that as administrator.
And thats it!
Note: In some cases to return your connection to normal you will need to use DHCP instead of a Static IP as defined above. You can do this by changing the "enablelocalnet.bat" to read (changing the network name and gateway to your router ip)
netsh interface ipv4 set address name="Local Area Connection 2" source=dhcp gateway=10.0.0.138
VPNSecure Provides Secure VPN servers in over 45+ Countries
If you are a looking for a versatile easy to use VPN service, checkout Today