Using iptables to change a destination port

Kristof Provost picture Kristof Provost · Oct 28, 2008 · Viewed 62.9k times · Source

Is it possible to change the destination port of a UDP packet using iptables?

I'm trying to get an SNMP agent to send out traps on 1620 instead of 162. Unfortunately so far I've only managed to change the source port:

iptables -t nat -A POSTROUTING -p udp --dport 162 -j SNAT --to :1620

Answer

PiedPiper picture PiedPiper · Oct 28, 2008

Assuming you know which machine you are sending to:

iptables -t nat -A OUTPUT -p udp --dport 162 -j DNAT --to-destination <dest-ip>:1620