[OT] Handling multiple UDP clients through NAT

Nicholas Leippe nick at leippe.com
Tue Feb 6 13:26:11 MST 2007

On Tuesday 06 February 2007 12:42, Steve wrote:
> Hello again everyone,
> While designing my new MUD server I ran into a design problem that I'm
> hoping someone here has had experience with.
> Specifically, I currently keep track of clients in a hashmap, with the
> hash being comprised of their IP address and port.
> This works very well until multiple clients who are NAT'd try to connect.

I don't see the problem.  Even if multiple clients are from behind the same 
NATing gateway, and they all explicitly set the port on their end of the 
socket to the same, it should still work.  SNAT, to work, handles source 
collisions by remapping the source ports as necessary, so the first client 
will appear to the server from <ip>:port, while the second client should 
appear to the server from <ip>:some_other_port.  The gateway should 
automagically handle the translation on the connection.  The response packets 
from the server should not appear unsolicited to the gateway.

> Now my initial response to this was to have each client bind a
> listener to a random port, then send a discovery request to the server
> that contains the port that they bound their listener to.

Doesn't the the kernel already bind a random port for the client end of 
outbound connection by default?

Why is the client listening?  Why not just connect to the server?  What you're 
trying to do sounds a lot like FTP.  If this is truly the route you want to 
go, you could possibly wrap your protocol inside FTP and thereby make use of 
the FTP conntrack helpers already out there in routers, or you'll have to do 
the same thing or similar on the client's gateway for tracking related 

Either I'm missing the problem, or something is getting over complicated.

More information about the PLUG mailing list