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?

  • 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
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
  • 1
    This only works if ip forwarding is activated: echo 1 > /proc/sys/net/ipv4/ip_forward – Leahkim Mar 31 '16 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.