This tool binds an app to a different network device
A bash script is provided for convenience:
$ ./bind2device.sh <device> <path_to_exe> <arguments>
LD_PRELOAD:
$ BIND2DEVICE=<device> LD_PRELOAD=./bind2device.so <path_to_exe> <arguments>
You are directly connected to the internet and via a VPN which is exposed on tun0 (e.g. if you are using Network Manger, add a VPN and check "Use this connection for ressources on its network"):
$ curl https://ifconfig.me
140.82.116.4
$ curl --interface tun0 https://ifconfig.me
204.79.197.200
$ ./bind2device.sh tun0 curl https://ifconfig.me
204.79.197.200
A shared library is provided which can be used with LD_PRELOAD to change application behavior at run-time. The 'socket' call is intercepted and rewired to use the specified interface (SO_BINDTODEVICE).
$ make