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?


1 Answer 1


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 ;) )


#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 up
#set loopback (may be needed by process run in this namespace)
ip netns exec myNamespace ifconfig lo up
#set route in namespace
ip netns exec myNamespace route add default gw
#force firefox to run inside namespace (using eth0 as outgoing interface and the route)
ip netns exec myNamespace firefox

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .