Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 Ubuntu with 2 NIC:

This one is set as default gw on Ubuntu:

eth1, ip, gateway 

This is set on a router, not in Ubuntu :

eth2, ip, gateway 

What I'd like to do is Route all port 119 tcp traffic to eth2 ( 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

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
iptables -A FORWARD -p tcp -d --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

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.