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.
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.
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.
Listen Mode (-l)
Netcat waits for incoming connections on a specified port. Acts as a simple server.
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:
Listens for TCP connections on port 53
Listens for UDP packets on port 53
Sends UDP packets to example.com port 53