Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using iptables to change a destination port

Tags:

People also ask

Can we change destination address using iptables?

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.

How can I port forward with iptables?

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.

What is forwarding in iptables?

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