Linux/Unix: Use Netcat to Establish and Test TCP and UDP Connections on a Server

Fig.01: Linux/Unix: Use Netcat to Establish and Test TCP and UDP Connections on a Server

Fig.01: Linux/Unix: Use Netcat to Establish and Test TCP and UDP Connections on a Server

The syntax is as follow to establish and test TCP and UDP connections on a Linux, FreeBSD, OpenBSD, Apple OS X, NetBSD or Unix-like systems.

Syntax

nc [option] host port
netcat [option] host port

Test port 80 for 192.168.1.5 server

nc -z -v 192.168.1.5 80
nc -z -v 192.168.1.5 http
netcat -z -v 192.168.1.5 80

Sample output:

nixcraft-nas01  [192.168.1.5] 80 (http) open

Test udp port

The syntax is:

netcat -u host port
nc -u host port
nc -u 192.168.1.22 123

Port scanning with netcat or nc

The syntax is:

nc -z -v IP startport-endport
netcat -z -v IP startport-endport
 
netcat -z -v cyberciti.biz 1-1023
 
nc -z -v www.cyberciti.biz 1-1023

Examples and usage: Linux and Unix Port Scanning With netcat [nc] Command