Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have Ubuntu with 2 NIC:

This one is set as default gw on Ubuntu:

eth1, ip 192.168.10.11, gateway 192.168.10.1 

This is set on a router, not in Ubuntu :

eth2, ip 192.168.20.11, gateway 192.168.20.1 

What I'd like to do is Route all port 119 tcp traffic to eth2 (192.168.20.11) and all other internet traffic to the eth1

I know I will need to use iptables but I wasn't able to put together a working solution yet.

Any help much appreciated.

Thank you

share|improve this question
add comment

1 Answer

You can't route tcp traffic, routing is relevant to a network layer protocol or IP. You can forward or redirect IP packets based on tcp ports i.e. port forwarding. In your case you can use iptables. One possibility is to use rules like this

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -i eth1 -A PREROUTING -p tcp --dport 119 -j DNAT --to-destination 192.168.20.11:119
iptables -A FORWARD -p tcp -d 192.168.20.119 --dport 119 -j ACCEPT
share|improve this answer
    
Thanks but maybe I didn't explain myself well. What I want to do is have all traffic to outside port 119 to go through eth2. The rules you posted look more like if my Ubuntu PC was hosting a service on port 119 but that's not the case. The service on port 119 is running somewhere on the internet. –  Jan Feb 15 '13 at 16:30
add comment

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.