You can change the destination address in PREROUTING , and source address in POSTROUTING . The rationale is that during the POSTROUTING chain, the routing decision has already taken place, and altering the destination address now would be nonsensical.
Port forwarding on iptables is done with something called a Destination NAT. This will tell the incoming packs, depending on the conditions implied, to route through a different port or address. For this, we will need to do this through iptables' NAT PREROUTING chain.
Port forwarding also referred to as port mapping, is a method for allowing remote devices to connect to a specific service within your private local-area network (LAN).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With