Windows Guide: Enabling your VPN for a single program while letting everything else use your normal connection

This guide was originally written by myself in a thread on another subreddit, however, /u/TorrAbsolute suggested that i post it here. This will let you run your VPN while still running Plex on your normal connection.

Essentially this setup will let you run your VPN at all times without worrying about high ping in online games and the like, as only one (or more if you want) program will be using your VPN while the rest will be using your normal connection.

I learned how to set this up by experimenting as there was no guide for doing this on Windows on the internet last time i checked. Please send a link to such a guide if you find one, it might be better than mine :slight_smile:

This guide is written for use with qBittorrent and privateinternetaccess(PIA) VPN, but the VPN provider doesn’t matter alot as long as your VPN has config files that you can download for use with OpenVPN. I strongly recommend using qBittorrent as it can bind to a network interface which will become very useful later in the guide.


Part 1, Setting up OpenVPN:


  • Step 1 you need to use Openvpn instead of the PIA app. This gives us much more customizabilty and as far as i know the PIA app is built on openvpn anyways. So have Openvpn installed.

  • Step 2 you need to get the openvpn config files for PIA from PIA’s website

  • Step 3 place the “.pem”, “.ca” and one (Choose best location for you) of the “.ovpn” files in “C:\Program Files\OpenVPN\config” like so: http://i.imgur.com/1xZZAb5.png

  • Step 4 create a file called pass.txt in the same folder and insert your PIA username and password on two lines like so: http://i.imgur.com/Wpef5bP.png

  • Step 5 insert into the “.ovpn” file you placed in the “C:\Program Files\OpenVPN\config” folder:
    auth-user-pass pass.txt

Now you should be able to start Openvpn GUI, right click the icon in the taskbar and press connect and this will connect you to PIA servers with the Openvpn client instead of the PIA client.

Check if your IP has changed with https://ipleak.net or https://www.doileak.com/


Part 2, Setting network routes:


  • Step 1 Add these lines to the “.ovpn” file:

script-security 2

route-noexec

up up.bat

down down.bat

  • Step 2 create an “up.bat” and a “down.bat” in the config folder like so: http://i.imgur.com/k9mvC9g.png

  • Step 3 insert into the “up.bat”:

ROUTE ADD 0.0.0.0 MASK 0.0.0.0 %ifconfig_remote%

  • Step 4 insert into the “down.bat”:

ROUTE DELETE 0.0.0.0 MASK 0.0.0.0 %ifconfig_remote%

  • Step 5 This part is why using qBittorrent is a very good idea for this sort of setup but if you really don’t want to switch you’ll have to find a way to bind your torrent client to a network interface.

Open qBittorrent and go into settings, and then “advanced”. Then you want to set the network interface to your VPN interface like so: http://i.imgur.com/T6y4B1P.png

This will make qBittorrent communcate via the VPN and ONLY the VPN, in my experience. This means that if the VPN tunnel goes down, qBittorrent will lose connection instead of connecting with your real IP. You will have to restart qBittorrent every time the VPN is restarted to connect to the new VPN ip though. (Make sure you have exited qBittorrent in the taskbar when restarting it).

  • Step 6 Try going to https://doileak.com and activate the torrent test. Add the magnet links to qBittorrent and start the test. If it worked the “Request IP” should be different from the “Torrent HTTP Request IP” and the “Torrent UDP Request IP”

Maybe you have noticed that qBittorrent is still using some of your non-VPN DNS servers though.

  • Step 7 My best solution to the DNS server problem is making everything on your PC use OpenDNS DNS servers instead of your ISP’s or your VPN’s. To do this add these lines to the “.ovpn” file:

dhcp-option DNS 208.67.222.222

dhcp-option DNS 208.67.220.220

block-outside-dns

Check with https://doileak.com again, all your dns requests from qBittorrent and from your browser should now come from OpenDNS making it harder (to the best of my knowledge) to correlate your normal IP with your VPN IP.

If you experience any issues with your DNS servers cutting out, remove these 3 lines again. I have only had these issues on one of the 2 PC’s i use with this setup.

  • Step 8 Start OpenVPN as a service.

Go into Services in Windows.

Find OpenVPN Service and go into it’s properties.

Set Startup type to automatic, press apply and press start. OpenVPN should now run in the background at all times.


PART 3, Making qBittorrent start and stop automatically with the VPN:


A command to start and stop qBittorrent can be added to the up.bat and down.bat files. This is neat because qBittorrent has to be restarted every time the VPN restarts and by adding it to the bat files you don’t have to do it manually. However, when using openvpn as a service it doesn’t start qBittorrent the same way as if you had started it yourself (because of the way services are handled in Windows).

Therefore it will not appear as “desktop program” but will still be running in the background.

This means that the only way to access qBittorrent is through the WebUI.

The command to add to “up.bat” is:

start /d "C:\Program Files (x86)\qBittorrent" qbittorrent.exe


The command to add to “down.bat” is:

taskkill /F /IM “qbittorrent.exe”

Then there is a couple a steps you need to take to make sure the OpenVPN Service is logged in as your user:

  • Step 1 Go to services, right click OpenVPN Service and go to properties.

  • Step 2 In the “Log On” tab press “this account” and click browse.

  • Step 3 Press advanced and a large window will popup.

  • Step 4 In the large windows press find now and a list of users will appear at the bottom of the window.

It should look like this: http://i.imgur.com/jxrH3i9.png

  • Step 5 Double click your username(“Hundter” in my case) in the list.

  • Step 6 Press Ok to close the large window. Press Ok again to close the smaller window. Your username should now be in the box next to “This account”.

  • Step 7 Enter the password for the user in Password and Confirm Password and press Ok.

Assuming that you have enabled WebUI in qBittorrent you should be able to access the WebUI without starting qBittorrent yourself as long as the VPN is running.

Assuming you followed the guide you should now have an amazing VPN setup (in my opinion) that will let you use your PC for gaming, browsing and other activites where low latency or direct connection is preferred :slight_smile:

I still think its easier to use a VM to accomplish this. Or, if you are using Linux, a LXC (Linux Containers).

Sorta “off-topic” but using deluge (or whatever) + socks proxy from PIA is much easier, no need to run a vpn at all.
(also make sure to encrypt the stream/connection, its possible in deluge under network in settings)

I run my Plex server on a tower, which uses Libreelec (basically a Linux based OS designed to boot directly into Kodi) as it’s only OS. The Plex media server is an addon, and I use an OpenVPN addon to connect to PIA.

Does anyone have any input on how I would go about routing traffic correctly so that the VPN bypasses all Plex traffic only? I understand that my particular setup is uncommon, so any help would be greatly appreciated.

Holy crap long post, good details. Will be trying this later on. Is there any reason you can’t do this through your router by port #?

Good writeup. For routing additional applications that don’t let you specify a network adapter (most don’t) you can use ForceBindIP.

This is sweet! Can be extremely useful for just SABBZB or torrents

Why not use the built in proxy methods on most torrent clients?

Can we get this stickied??

In my setup, i have VM for downloads and VM for plex. VPN setup on Downloads VM.

You can also just let only Plex through with a setup and script like this: Remote Access Plex Media Server on Windows Behind VPN •

Do you know if this will work on other VPN’s running on OpenVPN? For example, I’m using cyberghost.

trying to finally do this on my box and I keep getting an error on OpenVPN which makes everything else not work

Thu Dec 08 07:52:05 2016 env_block: add PATH=C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem

Running Server 2012. Any ideas?

Is there an app that does this for mac. Without complicated steps like above

What goes on the VM? I’m guessing the VM contains the VPN and the torrenting client?

This guide was originally written because another user had their IP leak with that exact setup (not saying you’re at risk at all).

With PIA VPN there are no logs, is the same for Proxy?

I have PIA. Can you tell me how to use the proxy? There doesn’t seem to be any documentation on it.

You can tell openvpn to ignore traffic to plex’s servers. I have written a guide for this here.

Edit: The routing table in the *.ovpn should work the same regardless of your OS. Give it a shot.

You can use any DNS servers you want to, but i can’t really comment on using DNScrypt as i haven’t used it before. I would be talking out of my ass.