Operations 8 min read

How to Test and Debug Linux Network Ports with telnet, nc, and netstat

This guide explains how to verify TCP port connectivity on Linux using telnet and nc, shows how to interpret their output for open or closed ports, describes ways to exit these tools, and demonstrates how netstat can confirm the connection state and identify the owning process.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Test and Debug Linux Network Ports with telnet, nc, and netstat

Introduction

When troubleshooting network issues on a Linux system, it is common to need a quick way to verify whether a specific TCP port is reachable. The following sections cover three command‑line utilities— telnet, nc (netcat), and netstat —that can be used for this purpose.

Using telnet to Test a Port

Basic syntax: telnet serverIP port Make sure there is a space between the IP address and the port number.

When the port is closed

ggd@ubuntu:~$ telnet 192.168.70.1 20
Trying 192.168.70.1...
telnet: Unable to connect to remote host: Connection refused

When the port is open

ggd@ubuntu:~$ telnet 192.168.70.1 8080
Trying 192.168.70.1...
Connected to 192.168.70.1.
Escape character is '^]'.

The message Connected to 192.168.70.1. indicates that the port is reachable.

Sending and Receiving Data after Connection

Once the connection is established, you can type data in the terminal to send it to the server and receive any response, effectively using telnet as a simple client.

Exiting telnet

Two methods:

Press Ctrl + ] then Ctrl + D Press Ctrl + ] then type

quit

Using nc (netcat) to Test a Port

Basic syntax with verbose output:

nc -v serverIP port

When the port is closed

ggd@ubuntu:~$ nc -v 192.168.70.1 20
nc: connect to 192.168.70.1 port 20 (tcp) failed: Connection refused

When the port is open

ggd@ubuntu:~$ nc -v 192.168.70.1 8080
Connection to 192.168.70.1 8080 port [tcp/http-alt] succeeded!

Like telnet, nc also allows you to send and receive data after a successful connection.

Exiting nc

Press Ctrl + D or Ctrl + C to terminate the session.

Combining with netstat for Deeper Verification

If telnet or nc output is insufficient, netstat -atpn can show active connections, the associated process IDs, and their states.

Key columns to examine:

Foreign Address : the remote IP and port you tested

PID/Program name : the owning process

State : should be ESTABLISHED for a healthy connection

Example netstat output

The screenshot (omitted here) highlights the relevant rows where the state is ESTABLISHED, confirming that the port is functioning.

Brief Overview of netstat

netstat

is a versatile tool for monitoring TCP/IP networking. It can display routing tables, active connections, and interface statistics.

Important options

-a

: show all sockets -t: display TCP connections -p: show the owning program -n: show numerical addresses (no DNS lookup)

Common connection states

LISTENING : server waiting for incoming connections

SYN‑SENT / SYN‑RECEIVED : handshake phases

ESTABLISHED : full‑duplex connection established

FIN‑WAIT‑1 , FIN‑WAIT‑2 , CLOSE‑WAIT , CLOSING , LAST‑ACK , TIME‑WAIT , CLOSED : various stages of connection termination

Environment Considerations

On embedded devices or minimal Linux installations, the BusyBox versions of telnet and nc may lack some options, so falling back to netstat is a reliable alternative.

Conclusion

Using telnet or nc provides a quick check of port reachability, while netstat offers detailed verification of the connection state and the responsible process, making them essential tools for Linux network debugging.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxcommand-linenetwork debuggingnetstattelnetncport testing
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.