Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following two problems. Please help me to solve them:

  1. In symmetric NAT, as I know, the local hidden node (behind the NAT) must initiate connection in order to create a window in the NAT to allow the packets of the remote host back into the local network. Can somebody give me some idea how i can do this?

  2. How can an application learn that there are NATs in the path between the source and the destination?

share|improve this question

I can give you a place to start for (2): Michal Zalewski's p0f passive monitoring tool. It seems to support some way of guessing that the source of a TCP "SYN" is behind a NAT.

share|improve this answer

Since UDP is connection-less, NAT implementation cannot know where UDP communication actually ends, so it just creates translation table entry on first passed packet. For example, hidden host with IP send packet to host via NAT router with address, source port is 10000, destination - 20000. On packet arrival NAT creates entry such as this: 10000 - 10000 - 20000

Port number in second field may be different if it is already used by other translation entry. After this entry created, all UDP packets from to will be redirected to

On second question: if there is a NAT between source and destination, remote addresses reported by getpeername(2) and reported directly by remote end (in UDP payload) will be different.

There are more info and links about NAT hole punching on wikipedia.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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