Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a multihomed linux box with 6 network interfaces that I'm using to run some tests of router hardware. I would like to be able to set "NIC affinity" (for lack of a better term) on an arbitrary process so that even though a destination IP might correspond to a local interface, all network traffic for that process will be routed out via another interface (and looped back in by the external device). Ideally, one process's affinity setting will not affect another's.

As a sample use case, say I have eth0= and eth1= and an external router connected to eth0 and eth1 with the IPs of and, respectively. If I open up my shell and ping, no traffic will traverse the external connection as the destination corresponds to the local machine, but if I were to somehow set the shell process's affinity to eth0, ICMP traffic would flow out via eth0, into the external router, and back again to eth1. It's the traversal of the external router that I want to guarantee, and as there will be more than one, I need to be able to bind to arbitrary NICs.

Is this possible? Given my searches thus far, I see no answers but the absence of mentions of what I'm trying to do leads me to suspect I'm missing an important consideration, as this doesn't seem like a original question (just an odd one).

FWIW, this is an Ubuntu Linux 11.10 box. Any pointers to similar work or suggestions for tools would be greatly appreciated. Thanks!

share|improve this question
Side note, but the "affinity" for a network interface in my experience generally means CPU affinity -- which is which processor(s) or core(s) should handle the interrupts generated by network traffic. – Kyle Brandt Jan 24 '12 at 15:05
Yeah, I knew the term was cumbersome, but I wasn't sure what else to call it ("Process-specific routing", perhaps?). – mjbraun Jan 24 '12 at 17:09
up vote 1 down vote accepted

This seems like a situation where you might need to take one step back and let us know in a more general way what you are trying to accomplish, rather then how to implement a particular solution.

That being said, in order to set a process bound to a specific interface in Linux you need to hack the bind system call (man 2 bind). You can do this by using alternative libraries and pre-loading them, see How to use different network interfaces for different processes over on Super User.

share|improve this answer
Well, I'm building a testing rig to develop a new router configuration for portions of our network. I have the physical hardware and my goal is to be able to configure the routers and then drop them into place with no changes. So I am using the multihomed box to simulate the various networks each router might encounter: one port on the machine would be physically connected to the "external" port on the router and another port on the machine would be connected to the "internal" port on the same router." I could then shift between shells corresponding to inside and outside connections. – mjbraun Jan 24 '12 at 17:13
Also, that link is golden. I had the concept in my head, but I didn't have the words to properly elucidate it for successful searching. Many thanks. – mjbraun Jan 24 '12 at 17:15
@mjbraun: Okay, then this hackish solution sounds right and you know what you were looking for :-) Most people in this situation would probably be trying to do something simpler like source based routing :-P – Kyle Brandt Jan 24 '12 at 17:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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