reza
reza

Reputation: 6358

How to use UDP from a machine with only NAT access

I have a machine, with no external IP address, it will need to send UDP packets to the outside world. Only NAT access.

Will this work?

It is really hard to prototype this in our environment. It is still really under construction. Any thoughts on how I can prototype this?

Upvotes: 0

Views: 128

Answers (2)

Davide Berra
Davide Berra

Reputation: 6568

Most of the home network configurations in the world are made of a PC with an internal IP and a router with a public IP that NAT the internal one. (Independently of UDP/TCP or whatever protocol that needs to go out)

I see no troubles with it

Upvotes: 1

Hari Mahadevan
Hari Mahadevan

Reputation: 920

It should work.

Ensure that for the socket created, set the TTL (time-to-live) to a value that is sufficiently large to cover the possible number of router hops to reach the destination. Running traceroute to the destination IP will give you a rough idea on the number of hops. Note that this value can change depending on network conditions. So it's best to set this to a larger value. Refer to sockets IOCtl API documentation for the syntax for setting TTL.

Finally, remember that UDP is not a reliable protocol. So even after taking the necessary steps above, the packet may not reach its destination. However, if the entire network, including the intermediary routers, is within a controlled environment, such as a corporate intranet, chances of packet drop are minimal.

If you want to add reliability on top of UDP, you can adopt a NAK based algorithm where packets are stamped with a sequence number. Various resources might advise you that if you need to add reliability over UDP you should consider TCP, but my experience has been that if your app runs in a controlled environment with very minimal chance of packet drops and you need fast connection setup and tear down, adding a lightweight reliability over UDP has its merits. Also TCP connections take up valuable space in the OS kernel whereas UDP don't. This could also be a consideration if you want to support very large number of 'connections' in a constrained environment.

At the end of the day you need to experiment a little to figure out what works best for you.

To prototype, I would set up a NAT server using something like Linux and then start working from there. Real world traffic scenarios that you want to simulate will determine where the client and server are to be located on either side of the NAT. That is, if the traffic should go through an ISP or all within a controlled environment.

HTH

Upvotes: 0

Related Questions