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

Is possible on Debian to change the port of packets that are going to a specific port, using iptables?


I want packets going in the outbound direction to a.b.c.d for port 1723 to be redirected to the address a.b.c.d on port 10000. Is this possible?

share|improve this question
Please use standard terminology like source and destination. Am I correct in assuming you want iptables to change the destination port on outbound packets to a specific host from 1723 to 10000 for both TCP and UDP? – jw013 Oct 16 '12 at 21:07
@jw013 You're right – Jhonathan Oct 16 '12 at 21:11
up vote 3 down vote accepted
for proto in tcp udp; do
  sudo iptables -t nat -A OUTPUT -d a.b.c.d -p "$proto" --dport 1723 -j DNAT --to-destination a.b.c.d:10000
share|improve this answer
This only works if ip forwarding is activated: echo 1 > /proc/sys/net/ipv4/ip_forward – Rei Mar 31 at 13:48

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.