Netcat is built into most if not all Linux distributions. It is an incredibly useful tool for quick network tests: to see if a device is reachable or a service is running. Seeing a “Connection refused” in netcat is in itself already valuable information as it could indicate that the remote host is reachable, but the service just isn’t running.

Probing a port

Typically if you want to see if a TCP port is up on a remote host, you use telnet. The same can be accomplished using netcat:

user@localhost~# nc -vz 443 [] 443 (https) open

The -verbose flag is necessary as it’ll make netcat print the actual result. Adding the -z means netcat will only “knock” and close the connection after handshaking.

Port scanning

Netcat can also scan ranges of ports! Instead of typing a single port, you can specify a range:

user@localhost~# nc -vz 1-1023 [] 443 (https) [] 80 (http) [] 53 (domain) [] 22 (ssh) open