Iptables udp port forwarding [duplicate]
I'm using latest debian relese and i need to do some port forwarding, but i dont know how.I have 2 stream sources coming to my server on the same udp port from 2 diferent ip-s
192.168.1.2:1003 via udp to 192.168.1.4 (server)
192.168.1.3:1003 via udp to 192.168.1.4 (server)
My qestion is: how to forward this port 1003 coming from 1.2 to some other port 1004 for example?
You need to use the PREROUTING
chain to forward port :
iptables -t nat -A PREROUTING -p udp -i eth0 -d 192.168.1.2 --dport 1003 -j DNAT --to-destination 192.168.1.2:1004
By the way, it seems filter is happening directly on the target host, so you could use REDIRECT
in that case :
iptables -t nat -A PREROUTING -i eth0 -d 192.168.1.2 -p udp --dport 1003 -j REDIRECT --to-ports 1004
In both case, don't forget to allow traffic on port UDP/1004
after NAT (assuming UDP/1003
is already allowed) :
iptables -A FORWARD -i eth0 -p udp -d 192.168.1.2 --dport 1004 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT