Netcat Section 2 of 14

Connection Types

Netcat supports both TCP and UDP protocols, and can operate in either client (connect) or server (listen) mode. Understanding these modes is crucial for effective usage.

TCP vs UDP

TCP (Transmission Control Protocol)

Connection-oriented protocol that guarantees delivery, ordering, and error checking. Used for reliable communication.

nc example.com 80 # Default TCP nc -v example.com 443 # Verbose TCP

Common uses: HTTP/HTTPS, SSH, FTP, email services

UDP (User Datagram Protocol)

Connectionless protocol with minimal overhead. No guarantee of delivery, ordering, or error checking. Used for speed-sensitive applications.

nc -u example.com 53 # UDP DNS query nc -u -v example.com 123 # Verbose UDP NTP

Common uses: DNS, DHCP, SNMP, VoIP, gaming

Client vs Listen Mode

Client Mode (Connect)

Netcat initiates a connection to a remote host and port. This is the default behavior.

nc example.com 80 # Connect to web server nc -u 8.8.8.8 53 # UDP DNS query nc -v scanme.nmap.org 22 # Verbose SSH check

Listen Mode (-l)

Netcat waits for incoming connections on a specified port. Acts as a simple server.

nc -l 4444 # Listen for TCP connections nc -u -l 53 # Listen for UDP packets nc -l -v 8080 # Verbose TCP listener

Note: In listen mode, don't specify a remote host.

Combining Protocol and Mode

You can combine protocol selection (-u) with listen mode (-l) for UDP listeners:

nc -l 53 # TCP listener on port 53

Listens for TCP connections on port 53

nc -u -l 53 # UDP listener on port 53

Listens for UDP packets on port 53

nc -u example.com 53 # UDP client to port 53

Sends UDP packets to example.com port 53