Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 am trying to set up port forwarding on UDP from port 12345 to port 54321 using the following:

iptables -t nat -A PREROUTING -p udp -i eth0 -d  --dport 12345 -j DNAT --to

iptables -A FORWARD -p udp -i eth0 -d --dport 54321 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

This works fine for new connections, however, it wouldn't work for connections currently active.

To clarify what I mean, let's say that before adding the rules, there is an active connection from <--->, and I am trying to redirect all incoming connections on to

After adding the above two rules, all other packets destined to are received at except the ones from

I guess the state of the connection plays a role in this. How can I solve this and get the packets from destined to port 12345 get delivered to port 54321?

share|improve this question

migrated from Aug 26 '12 at 8:46

This question came from our site for professional and enthusiast programmers.

UDP are datagram packets, there's no sense of "active connection" like with TCP. Or are you talking about some higher layer protocol handshake? – Jon Lin Aug 26 '12 at 3:40
I explained the case! I know UDP is connectionless, but after I add the port forwarding rules, packets from a previously seen remote IP and Port are not forwarded to the new port. – Hooman Aug 26 '12 at 14:00
anyone has any suggestion? – Hooman Sep 28 '12 at 23:59
up vote 2 down vote accepted

I figured out how to do it!

You need to use the REDIRECT on NAT! However before that you have to erase the entry corresponding to this connection from conntrack! Something like the following

conntrack -D -p udp -d --dport=55555 
share|improve this answer

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.