NAT and UDP replies by default

Posted on

Problem :

If I send UDP packets from Machine A with local port M behind a NAT to Machine B’s port N, where Machine B is outside the NAT (elsewhere on the Internet), can I reasonably expect that NAT would pass UDP packets received from Machine B (local port N) back to port M on Machine A, without requiring manual port forwarding on the NAT?

I know the answer would be yes if the router is configured to preserve source ports when possible, and that source port is not in use. But my question is more about probability. Most of the time, do most routers have this configuration on by default or not.

In other words if I make a multiplayer game to use UDP, would it be reasonable to expect that it would work on most people’s computers (even tough at their homes most people have routers) ?

Solution :

DNS queries behave just like that: UDP packet on port 53 from your computer to the Internet and back again.

Nevertheless it is only in a “reply-response” thing and the response should not be delayed in time, or it will be lost.

In a game, there will be a lot of packets from the server to the clients. You will be needing to implement a constant polling of server status to make it work. Remember: one question – one answer.

Technically, you could implement your game that way without needing to open ports on routers

Leave a Reply

Your email address will not be published.