Skip to content

Instantly share code, notes, and snippets.

@M0r13n
Created December 16, 2024 13:21
Show Gist options
  • Save M0r13n/69fb4dc004e7d377142ca2c74393fed7 to your computer and use it in GitHub Desktop.
Save M0r13n/69fb4dc004e7d377142ca2c74393fed7 to your computer and use it in GitHub Desktop.
NAT Hole Punching using NetCat

NAT Traversal Setup with Netcat

This guide demonstrates a simple NAT traversal setup using tcpdump and nc (Netcat) for UDP communication.

Step 1: Monitor UDP Request on the Server

On the server, use tcpdump to monitor the incoming UDP packets on port 12345:

sudo tcpdump -i any udp and port 12345

This command will allow you to view the UDP request from the client, which is important for identifying the NAT port.

Step 2: Send UDP Packet from the Client

On the client, run the following command to send a UDP packet to the server, NATting the packet along the way:

nc -uvp 5555 192.0.2.1 12345

This sends the UDP packet from the client (on port 5555) to the server at IP 192.0.2.1 on port 12345.

Step 3: Accept Incoming UDP Packets on the Server

On the server, listen for incoming UDP packets on port 12345 from the client:

nc -uvp 12345 198.51.100.15 <PORT_FROM_TCPDUMP> || nc -l -uvp 12345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment