I am trying to send a UDP on a packet to two different external/remote IPs using iptables.
Currently I am running a command that looks like this:
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 3070 -j DNAT --to-destination 188.8.131.52:5640 iptables -t nat -A PREROUTING -i eth0 -p udp --dport 3070 -j DNAT --to-destination 184.108.40.206:5640
However, this does not work, because the UDP packet looks at the iptables' rules, and goes to
220.127.116.11:5640. Putting the other rule first makes the UDP packet go to that second destination. I tried combining the actual to-destinations using their range functionality, but the packet does not go anywhere, as these ranges are not internal IPs:
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 3070 -j DNAT --to-destination 18.104.22.168-22.214.171.124:5640-5640 ### note: I also tried iptables -t nat -A PREROUTING -i eth0 -p udp --dport 3070 -j DNAT --to-destination 126.96.36.199-188.8.131.52:5640-5641 where the port is increased by one on the secondary server
I can confirm that both commands work separately, and that only one works when both are in the same rule hierarchy.
I have also tried to use
TEE to make this work, pointing to one of the IPs as another gateway, but that doesn't work either. Is there any way to do this in iptables, or am I missing the mark in creating a multi-destination general UDP forwarder?
The UDP packets should both be distributed at the same time/simultaneously and duplicated to each respective server. The use case at the moment is that the UDP packet is needed for a process on Server A as well as in Server B, but from the source side that is sending the packet, it can only point to one server. ie: Server C that sends udp packets -> Server D -> duplicate and send packet to Server B and Server A.
Thanks for any help or suggestions.