0

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=192.168.0.1 and eth1=10.0.0.1. and an external router connected to eth0 and eth1 with the IPs of 192.168.0.2 and 10.0.0.2, respectively. If I open up my shell and ping 10.0.0.1, 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!

2
  • 1
    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. Jan 24, 2012 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, 2012 at 17:09

2 Answers 2

1

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.

3
  • 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, 2012 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, 2012 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 Jan 24, 2012 at 17:31
0

You may add new default routing to new network and then delete old network affinity like below.

sudo ip route replace default via 192.168.100.1 dev wlp2s0 proto static metric 50
sudo ip route delete default via 192.168.100.1 dev wlp2s0  proto static  metric 600

Here Second line is the old routing with metric 600 and first line is affinity of 50 which is metric

You must log in to answer this question.

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