0

I have PC A (192.168.255.126, eth1) and it will receive some UDP packets, port: 51000.

Now I wish the PC A will automatically forward the UDP packets to PC B (192.168.255.127)

I have found many solutions but all of them don't work.

Solution A:

iptables -A PREROUTING -t nat -i eth1 -p udp --dport 51000 -j DNAT --to-destination 192.168.255.127:51000
iptables -A FORWARD -p udp -d 192.168.255.127 --dport 51000 -j ACCEPT
iptables -A POSTROUTING -t nat -s 192.168.255.127 -o eth1 -j MASQUERADE

Solution B:

iptables -t nat -I PREROUTING -p udp --dport 51000 -j DNAT --to 192.168.255.126:51000

Solution C:

iptables -t nat -A PREROUTING -p udp --dport 51000 -j NETMAP --to 192.168.255.127

So what should I do?

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47

1 Answers1

0

Make sure PC A does packet forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

Allow forwarding on iptables:

iptables -I FORWARD -p udp -j ACCEPT

Let the NAT do the rest:

iptables -A PREROUTING -t nat -p udp --dport 51000 -j DNAT --to-destination 192.168.255.127
MTG
  • 193
  • 6