Nat – How does UDP NAT Know When To Remove The Rule

nat;udp

So say you are a user behind a NAT/router on an internal network. You begin sending UDP data to an internet-facing server. The packet hits your router, it inserts an entry to allow returning packets from that server on a specific port to be forwarded to your local machine when received.

However UDP is connectionless. How does the router know when to remove this rule when the client no longer wishes to send or receive data with this server?

Best Answer

A NAT router doesn't know when to remove a UDP mapping - it guesses.

The router simply ages (or times) out the entry when it hasn't been used for a period of time (usually between 5 and 60 minutes).

With TCP, there's also a similar aging/timeout to make sure that forgotten or lost sessions don't pile up, but it's much longer. Of course, normal TCP connections are properly closed, which means the NAT router can forget about it.

UDP or TCP aging is a trade-off between router resources (fast aging) and compatibility with slow low-bandwidth sessions (slow aging). Sometimes the default settings require tweaking for your workload.