Server Fault is a question and answer site for system and network administrators. 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

Is there any simple example of UDP-NAT hole punching, capable of hole punching for 2 peers communication via internet?
I am trying to do UDP hole punching so that it would be possible to NAT traversal. After going through the text available on the internet and we can have Wikipedia article as reference. How am I doing it?

First of all I have done NAT mapping (Virtual server) from public port: 11235 to internal port 11230 so that if i send any udp packet to the PublicIP:PublicPort, it should come to the InternalIP:InternalPort. Afterthis, I am doing following:
1. I get my public IP from browser by response I know my public ip now. lets say its four octets are IA.IB.IC.ID
2. I have created an application with a socket (UDP) bind to a local port 11230, which sends some UDP packets to port 11235.
3. The application then starts as a server, listening at the UDP port 11230. Any request that is received from other host is replied by almost same message body.
4. I run another application on same system, sending data to my public IP at port 1135

The packets sent to the UDP application listening doesnt receive any if i send the packets to PublicIP:PublicPort. However, If I change public IP to internal IP of LAN, the packets are received.

My Network Config is as follows:

  • DSL Modem's WAN interface to the ISP using phone line.
  • Modem's Ethernet interface connected to one of (1 of 8) router's LAN interface
  • and the Laptops are connected to the router via WiFi

Why is my applications not able to connect when using public IP. I also tried to send the UDP packets from client to server in a loop for all the port numbers above 1000 to 65535 so that if any port is mapped for internal ip's port, the request will come atleast once from client to the server. But that also didn't work. The code for the applications can be found here:
Client, sending the packets to the server
Server, listening for the packets (requests) from client
Any clues, suggestions ...

share|improve this question
why downvoted without any reason? – abhinav Nov 14 '11 at 13:22

Many NAT systems only work on incoming traffic from the public internet. They don't work when accessing public IPs from inside the network. You should get the sender machine outside your NAT.

share|improve this answer
i thought the packet will be first sent to ISP and from ISP to modem again?? Like PC-->router-->modem-->ISP-->modem-->router-->PC? As far as i know, Simple IP routing says the same. Am I mising smthg? – abhinav Nov 12 '11 at 20:14
as far as I know your router or modem knows it has the public IP and the connection is terminated to the router/modem with no matching NAT rules. – anttiR Nov 12 '11 at 20:17
@abhinav: Your router will only send a packet to your ISP if the ISP's side of the link is its final destination or if it doesn't have a more specific route to that destination. Neither condition applies here -- your router has a more specific route to its own interface, the interface route. – David Schwartz Nov 13 '11 at 0:18

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.