2

I have two NIC's (one Ethernet and one tethering from mobile). My Ethernet internet connection is port filtered, so I can't use some applications on that. All applications can run on my mobile tethering, but as I have only limited data I only want some selected applications to use that NIC.

So the question is: how can I force only some process to use a specific NIC?

5

Basically you want to "jail" your process and force it to bind to a specific NIC. Lots of people use LD_PRELOAD but LD_PRELOAD does not control the route that the processes uses. It will use the first route. One possible resolution was on SuperUser https://superuser.com/questions/241178/how-to-use-different-network-interfaces-for-different-processes/241215#241215

ip netns can do this.

TL;DR: Create network namespaces, associate interfaces to them and then run "ip netns exec NAME cmd..."

Just check if your distro supports ip netns... (Backtrack 5r3 does not, whereas Kali does ;) )

IN MORE DETAILS:

#create netns
ip netns add myNamespace
#link iface to netns
ip link set eth0 netns myNamespace
#set ip address in namespace
ip netns exec myNamespace ifconfig eth0 192.168.0.10/24 up
#set loopback (may be needed by process run in this namespace)
ip netns exec myNamespace ifconfig lo 127.0.0.1/8 up
#set route in namespace
ip netns exec myNamespace route add default gw 192.168.0.1
#force firefox to run inside namespace (using eth0 as outgoing interface and the route)
ip netns exec myNamespace firefox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.