7

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?

  • similar, but I can't find my answer in that topic. With this rule i can block that port coming from 1.2 but i dont know how to forward..iptables -A INPUT -s 192.168.1.2 -i eth0 -p udp -m state --state NEW -m udp --dport 1003 -j DROP – user287842 May 7 '15 at 20:39
  • 1
    You could later re-ask this question by reformulating so that you exactly explain what is your UDP-specific specific problem. – peterh - Reinstate Monica May 8 '15 at 4:24
6

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
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.