Jump to content
  • 0

Force Traffic Through Torguard VPN on Ubuntu VM

Rate this question






I'm a long time user of Torguard on Windows machines but have recently made a change to my setup.  I'm now choosing to run my VPN on an ubuntu VM (via virtualbox) on a host windows machine.  My windows host I never run VPN on anymore, but my VM runs torguard VPN all the time.  I've installed and am running torguard on the VM with no problems, but I want to have the extra security of making sure torrent traffic is stopped if the VPN for some reason goes down.   I'm relatively new to both virtual machines and linux.  I want to do one of two things, whichever is easier:


  • Force all traffic on the VM through torguard, stopping all network access on the VM if the VPN connection is lost OR
  • Force all traffic on my torclient (I'm using transmission) through torguard, stopping all torrents if the VPN connection is lost


I am familiar with how to do this on windows/qbittorrent but not with ubuntu/transmission.  I've tried to follow along with some similar posts but it seems my setup is slightly different than others I've encountered.  Can anyone help?



Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
ufw enable
ufw default deny outgoing
ufw default deny incoming
ufw allow out from to
ufw allow in from to
ufw allow out to any port 1912
ufw allow out on tun0 from any to any
ufw allow in on tun0 from any to any

Not an expert, use at your own risk, but...  I used the above commands for mine (Ubuntu server 2020.4) and it mostly works.  It denies pretty much anything except a connection to an openvpn server, the local network, and anything going through the VPN.

Run the above commands once and they persist after reboot ("ufw reset" if you mess up.) 

A weakness is in that "any port 1912" line.  It is to allow an outbound connection to any torguard vpn (the port is specified in your openvpn config and it should be tcp 1912 by default), but actually it allows that connection to ANY server meaning that it's remotely possible that your client could connect to a torrent via port 1912.  Ideally it would be limited to the server that you are using by replacing "any" in that line with the IP of the server you want to use.

Since DNS is not allowed, all addresses must be IP, not the dns name (applies to firewall and openvpn configuration--after the VPN is up, dns will go thru it.)  If you have a favorite trusted (secure) DNS, you could allow that in a line similar to "ufw allow to port dnssec" where is the IP of your dns server.  Note that using your local router as a dns server (typically will probably create a dns leak because your real IP will be used for requests.

Another thing I just thought about is the wisdom of the "allow in on tun0 from any to any" and "allow out on tun0 from any to any".  It is a) exposing you to anything coming through the vpn and b) potentially allowing others to use your server as a gateway.  Maybe remove "to any" and "from any" respectively?

Also note that my local IP is might be different.


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...