I want to do the following (if it's possible):
Have 1 browser (say Firefox) as normal - all traffic uses my VPN. Have another browser (say Chrome) where all traffic bypasses the VPN.
I have already setup a PC with a VPN using OpenVPN and I understand how to add static routes so that access to specific IP addresses will bypass the VPN.
I thought what I want to do may be possible by setting up a (Squid) proxy server which routes all traffic outside of the VPN, and then configure the Chrome browser to use that proxy server. Unless there is a better/easier way?
But I do not know how to accomplish this and configure Squid/routes despite doing a lot of reading and experimenting (I am not a network expert), nor have I been able to find any resource to tell me how (or if it's possible).
Any help or links to information appreciated.
I think that the best would be to change nothing to your current setup but to take advantage of Linux namespaces instead. You can use tools like nsjail or Firejail for convenience.
The idea would be to set up a dedicated namespace for that other browser that should bypass the VPN, with its own routing rules. That's all you need, change the routing rules so that it uses your regular Ethernet interface rather than the tun interface created by OpenVPN.
The other benefit is isolation of your applications. By limiting their scope and the resources they are able to see, you effectively isolate them from each other.
Using Firejail here is how I would do it roughly - I encourage you to read the doc to fine-tune the configuration to the desired result. Firejail comes with ready to use profiles for common applications so it can immediately start sandboxing your browsers and other applications.
There is a also GUI configuration tool (firetools) but my suggestion would be to try Firejail with just one application instead of reconfiguring your whole environment.
Here is a PoC using Python (assuming you have the netifaces package installed).
As you can see, Python sees only one interface (in addition to the loopback interface). eth0-11182 is of course a virtual interface that exists only within the current namespace.
Suggested reading: Firefox Sandboxing Guide
I haven't used
squid
, but to my understanding it's just a regular proxy, so by installing it on your computer, it still follows your OS routing rules.I would try the following setup:
After having this setup configured, your browsers would not use the VPN by default, and you can configure one of them to go via the proxy server using the server's OpenVPN subnet address.
Note1: You have to use the proxy via the OpenVPN subnet address and not its public IP.
Note2: Do not allow traffic to the proxy server port from outside of the OpenVPN subnet, can be achieved using iptables, or by not opening the port using your cloud provider rules
UPDATE:
When using an external VPN service (e.g: nordVPN) you don't have access to the machine running the OpenVPN server and that makes the above solution invalid, since you can't install anything on the machine running the OpenVPN server.
It's possible to install the proxy service in another device in your local subnet, and some router (e.g: mikrotik) provide this feature. But that will make the solution to work only on a specific location with this setup.
Thanks for all the ideas and comments so far. I have not (yet) got
firejail
to work with the VPN active (@Anonymous suggestion). But I followed up on the suggestion linked by @ofirule specifically this answer to use control groups.That answer has a link to a complete shell script to do everything automatically but I wanted to do things manually at least to start with so I could follow along and make sure I knew exactly what I was changing. So, following the Manual HowTo there I will post below exactly what I did for anyone else.
Note that my network interface is named enp0s31f6 and my gateway IP is 192.168.0.1 I think those are the only two specific things that may need changing for others following this:
I don't (yet) fully understand all the above but it works! :-) Running firefox via the
cgexec
command I can check my IP in firefox with the VPN active and can see it reports my actual public IP not the VPN IP. I also proved this method works by running a radio streaming service which was having issues working with the VPN - it now works absolutely fine bypassing the VPN.