I‘m writing an application that sends information, using UDP packets, to the server on the internet and then receives data same way. It seems to work fine from behind NAT but I’m wondering about more complex cases...

What if client is on a LAN, with multiple parallel routes outside, that run NAT? In this case my server could receive traffic from same client from many different addresses / endpoints but communication should still work? Or is this dependent on router software and original mapping can age out breaking connection? Maybe I should keep track of all addresses I’m getting traffic from and send out to the one most active?

I assume I’ll need some identification token in all my packets to get this working properly since I can not rely on IP address?


I assume you are using NAT to translate a private source address to a public source address. Each WAN interface is going to have a different public address. so packet leaving one WAN interface will not have the same source address as packets leaving the other WAN interface. That is one reason that per-packet load balancing is not recommended (per-flow is what you should use).

Your situation will not work at all with TCP because it uses connections that are based on both the source and destination IP and TCP addresses, which would be different from each WAN interface if you use NAT. UDP doesn't use connections, so it avoid that problem, but you will need to deal with the different source IP and UDP addresses from each WAN interface in your application. Unfortunately, protocols, applications, and programming are all off-topic here. You could try to ask about that on Stack Overflow.

  • What about port mapping age out? It can happen, right? – UfoXp Feb 25 '18 at 2:58
  • What port mapping age out? – Ron Maupin Feb 25 '18 at 2:59
  • Let’s say NAT is getting established on two routers. First client uses for egress only first one then mostly second one. I assume NAT will expire on first one if it is used sparsely... – UfoXp Feb 25 '18 at 3:02
  • That depends on the router model an how it is configured. – Ron Maupin Feb 25 '18 at 3:04

In general most clients will only use one route to a destination at any given time, but the route used may change over time. Mappings in NATs and firewalls may also age out if they are not used for a while.

So if you want to maintain long term communication with your clients you need to.

  1. Introduce some kind of identifier so you can distinguish clients.
  2. Keep track of the IP/port a client most recently used so you can send messages back to the client.
  3. Send keepalives from client to server to refresh the mappings in any firewalls and NATs along the path and to keep your server updated on the client's current network location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.