Redirect Output with Iptables

7,288
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
done
Share:
7,288

Related videos on Youtube

Jhonathan
Author by

Jhonathan

Updated on September 18, 2022

Comments

  • Jhonathan
    Jhonathan over 1 year

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

    Example:

    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?

    • jw013
      jw013 over 11 years
      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?
    • Jhonathan
      Jhonathan over 11 years
      @jw013 You're right
  • Leahkim
    Leahkim about 8 years
    This only works if ip forwarding is activated: echo 1 > /proc/sys/net/ipv4/ip_forward