Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to route the traffic used by a process over a specific interface?

For example, network traffic by download application should always use the interface wlan0 where as all other applications on the machine should use eth0.

Is it possible to have this kind of rule in Linux?

share|improve this question

3 Answers 3

It can be done using Linux Network Namespaces.

Here is an article that explains how. Basically you create a network namespace with a different default route and run the processes that need it there. You connect the newly created network namespace to the physical adapter with a bridge (but other solutions are possible of course).

Update: from kernel 3.14 it's even easier using control groups, as described in this article. You have to:

1) define a net_cls control group to annotate the packets from a given process with a classid (or group of process, note that there hasn't to be any parent-child relationship between them)

2) use the iptables cgroup module (added in Linux 3.14) to fwmark the packets

3) use policy routing (ip rule add fwmark ....) to create a new routing table for the marked packets

The advantage is that we don't have to do the bridging thing and everything is much more dynamic thanks s to cgroups.

share|improve this answer

A few people have written shims that use the LD_PRELOAD feature of Linux to achieve this:

share|improve this answer

Not per application, no. You can do it per port or per ip-address etc, or an application itself can bind to (and use) a specific network card.

You can't set up a rule to do it though.

share|improve this answer
    
I've a java application, is it possible to bind that app to an interface? –  Suresh Apr 17 '11 at 13:36
    
A Java application you have the source code for and can re-program the internals? –  Majenko Apr 17 '11 at 13:48
    
I've a java application source code that uses apache http library. –  Suresh Apr 17 '11 at 13:52
    
Then I would head over to stackoverflow.com and ask the programmers there how to change your program. I have never programmed in Java. –  Majenko Apr 17 '11 at 14:04

Your Answer

 
discard

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.