Linux Networking

Test an open port with nc on Linux

Quick port checks for web, SSH, and mail troubleshooting.

9 min read Beginner Updated 9 Jun 2026

Step-by-step guide

Work through each section in order. Stop when your issue is resolved — you do not need every step for every situation.

Warning

Port tests tell you something is listening or reachable — not that the service is healthy. Do not install legacy telnet for routine checks; use nc or ss instead.

What you will achieve

Quickly check whether a TCP port is open locally or reachable on a remote host — essential for debugging web servers, SSH, mail, and firewall rules on Ubuntu and Debian.

1) Install netcat (OpenBSD variant)

sudo apt install netcat-openbsd

Debian/Ubuntu ship nc from netcat-openbsd by default on many images. Confirm with nc -h.

2) Test a remote TCP port

nc -zv example.com 443
nc -zv 192.168.1.10 22

-z scans without sending data; -v is verbose. Success shows succeeded or open. Connection refused means the host is reachable but nothing listens on that port. Timeout often means firewall or routing block.

3) Test with a timeout

nc -zv -w 3 db.internal 5432

-w 3 waits three seconds — stops hung checks from blocking scripts.

4) Check locally with ss (no extra install)

ss -tlnp | grep :80
ss -tlnp | grep ssh

-t TCP, -l listening, -n numeric ports, -p process. If ss shows LISTEN but remote nc fails, suspect UFW, nftables, or cloud security groups.

5) Differentiate local vs remote failure

# On the server itself:
nc -zv 127.0.0.1 8080
nc -zv $(hostname -I | awk '{print $1}') 8080

Localhost works but LAN IP fails → binding on 127.0.0.1 only or firewall. Both fail → service not running.

6) UDP port checks

nc -zuv 192.168.1.1 53

UDP is unreliable for connect tests — no response can mean open or filtered. DNS and NTP need service-specific tools when results are ambiguous.

7) Why not telnet?

telnet sends cleartext and is often uninstalled. nc and curl cover most admin needs. For HTTP specifically:

curl -v --connect-timeout 5 http://localhost:80/

8) Script-friendly checks

if nc -z -w 2 localhost 5432; then echo "postgres up"; else echo "postgres down"; fi

Use in health-check scripts and CI deploy gates — exit status 0 means port accepted the connection attempt.

Verify

sudo ufw status
nc -zv localhost 22

Document whether failure is DNS (try IP), local bind, or network path — three different fixes.

Related guides

nc networking port test