Score:1

iptables bidirectional nat udp configuration for multiple sources

hr flag

I have the following setup, all udp packets:

client (42.123.124.125) -> (42.123.0.125) nat_server (192.168.2.2) -> (192.168.2.5) udp_service

nat_server has to receive incoming udp from client over a public ip and redirect the packet to the udp_service over a private network. Then it has to redirect all the responses from the udp_service back to the client.

The client negotiates connection to a specific port (4244) and then receives data on its random udp port.

The flow can be described with tcpdump. Negotiation:

15:03:48.630928 IP 42.123.124.125.38541 > nat_server.4244: UDP, length 4         
15:03:48.630953 IP nat_server.38541 > 192.168.2.5.4244: UDP, length 4           
15:03:48.680698 IP 192.168.2.5.43434 > nat_server.38541: UDP, length 4          
15:03:48.680707 IP nat_server > 42.123.124.125.38541: UDP, length 4        

Data flow:

15:03:48.680741 IP 192.168.2.5.43434 > nat_server.38541: UDP, length 16           
15:03:48.680743 IP nat_server.43434 > 42.123.124.125.38541: UDP, length 16    

The ports 38541 and 43434 stay the same during the whole connection. I managed to do it with this iptables config:

iptables -t nat -A PREROUTING -s 42.123.124.125 -p udp -j DNAT --to-destination 192.168.2.5:4244
iptables -t nat -A PREROUTING -s 192.168.2.5 -p udp -j DNAT --to-destination 42.123.124.125
iptables -t nat -A POSTROUTING -j MASQUERADE

How can I achieve the same behaviour when there are many clients? So instead of 42.123.124.125 I would like to use a range, e.g. 42.123.124.0/24

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.