Network interface selection

Posted by Antonino on Server Fault See other posts from Server Fault or by Antonino
Published on 2011-02-01T15:21:36Z Indexed on 2011/02/01 15:27 UTC
Read the original article Hit count: 242

Filed under:
|
|
|

Hello.

Suppose I have more than a network interfaces and I want to selectively use them per application. eth0 is the standard interface with the standard gateway in the main routing table eth1 is another interface with a different gateway.

Suppose I launch an application as a user "user_eth1".

I used the following set of rules for iptables / ip rules.

IPTABLES:

iptables -t mangle -A OUTPUT -m user --uid-owner user_eth1 -j MARK --set-mark 100
iptables -t nat -A POSTROUTING -m user -uid-owner -o eth1 user_eth1 -j SNAT --to-source     <eth_ipaddress>

IPRULE:

ip rule add fwmark 100 lookup table100

and i build "table100" as follows (no doubts on that)

ip route show table main | grep -Ev ^default | while read ROUTE; do ip route add table table100 $ROUTE; done
ip route add default via <default_gateway> table table100

It doesn't work at all. What's wrong with this?

Thank you in advance!

© Server Fault or respective owner

Related posts about ubuntu

Related posts about iptables