Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

A machine (M) is behind a NAT.

Port X is forwarded through, and available to the internet.

My application wants to connect to port Y.

How to I configure M to forward incoming data on port X to port Y?

share|improve this question
That's unclear to me. Are you talking about TCP ports? If your application (is that application on another machine across the internet?) wants to connect to port Y, how is forwarding incoming data on port X to port Y on M going to help? Do you mean to say that your application on M can only listen on port Y instead? What do you mean by Port X is forwarded through, and available to the internet? – Stéphane Chazelas Dec 12 '13 at 21:02

I think that you are talking about redirecting from the same machine, if so, you could try with iptables,

# iptables -t nat -A OUTPUT -p tcp --dport X -j REDIRECT --to-ports Y
share|improve this answer
That sounds right. If my question is unclear on that point, please suggest an improvement. :) I'll give this a try and report back. – user50849 Dec 12 '13 at 22:12

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.