How to use VPN just for some part of the system? This means that, for example, Firefox and aria2c will use the vpn and pidgin won't! Is it possible?
In my case, I want to use VPN for whole system except: transmission, apt-get and pidgin or vice versa: Just using vpn for these software: firefox, aria2c, youtube-dl
@see superuser question about different interfaces for different processes
This answer requires some compiling (see above for more), root access and
ip
command fromiproute
packageThis will retrieve and compile
bind.so
PRELOAD library in your current directory.Now, let's assume that your VPN is online and you know your tunnel device name (like tun0). Let's also assume that you know your default gw (
route |awk '/default/ {print $2 }'
) And your tunnel/other device gatewayroute |awk '/tun0/ {print $2 }'
To look at your routing tables:
Running a program like firefox with bind.so PRELOADED and binding it to the interface you want to route out traffic with.
If you want you can repeat this for as many interfaces you want and you bind.so so that the specific application is bound to specific interface. All applications not started with bind.so route out as your main routing table specifies.
If you can determine the specific IP addresses and/or ports that you want to use with VPN or vice versa, then the ip command will help you do that by allowing/disallowing a route for such and such.
The ip command is found in the iproute package:
I've been using it in a very limited fashion so I do not want to give you detailed information, but I'm pretty sure you can figure it out with the documentation. You may also find good example online on how to do such things with the ip command.
It is possible to configure a listening socket (i.e. a program that offers a service) to use a specific adapter. But client programs such as Firefox will usually simply send IP packets to the OS (by binding to 0.0.0.0) and leave it up to the OS as to how those packets reach the internet.
Some client programs do allow you to configure binding to a specific adapter IP address, but how to do this is down to each applications configuration.
It is possible to configure IPTABLES2 to use the PID (process ID) to route IP to a given adapter, but this PID will keep changing so would require the firewall rules to be continuously updated.
A better solution is to install a simple SOCKS proxy, such as Squid (which is rather complicated), tinyproxy, Dante or SS5.
Bind the proxy server to offer SOCKS5 on the lo adapter and configure it to send all IP via the VPN adapter.
If you bind the proxy server to an Ethernet port, other machines in the same network can use the same SOCKS server.
Configure each app that needs to use the VPN to use the proxy server.
There are tools such as soxify and tsocks that can be used to force programs that don't natively support SOCKS to use it.
If you want to use the vpn to route your trafic trough it, and you want for example to use it with firefox for example this is what you do: You enter Firefox, go to Options menu:
Go to Advance -> Network Tab
Now in the Connection Settings dialog:
Select Manual configuration
In SOCKS Host, enter your loopback ip address (always 127.0.0.1)
Use the port you chose above (80, or 8080 or whatever if you don’t want to use 80)
Make sure SOCKS v5 is chosen
If you don’t want to proxy some addresses (maybe localhost or something) enter those
addresses\domains in the “No Proxy for:” text box
Click OK.
And you should be good to go. You can check your ip to see if it is working corectly. http://www.whatismyip.org
The procedure should be the same for the rest of the applications. Note that not all have these options.