Operations 7 min read

How to Test and Debug Linux Network Ports with Telnet, Netcat, and Netstat

This guide explains how to test and debug Linux network ports using telnet, netcat (nc), and netstat, covering command syntax, interpreting connection results, sending and receiving data, exiting the tools, and handling environment limitations on embedded systems.

Open Source Linux
Open Source Linux
Open Source Linux
How to Test and Debug Linux Network Ports with Telnet, Netcat, and Netstat

Introduction

When debugging Linux network issues, it is common to need to verify whether a specific port is reachable.

Telnet command

Usage: telnet serverIP port. The server IP and port must be separated by a space.

If the port is closed, telnet reports a connection refusal.

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

If the port is open, telnet connects successfully.

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

After a successful connection you can send and receive data through the terminal.

Exiting telnet

Two methods: press Ctrl+ ]+ then Ctrl+ D, or press Ctrl+ ]+ followed by the command quit .

Netcat (nc) command

Usage: nc -v serverIP port. The -v flag enables verbose output.

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
ggd@ubuntu:~$

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!

nc also allows sending and receiving data after a successful connection.

Exiting nc

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

Limitations on embedded systems

On some development boards the busybox version may lack full telnet or nc options, resulting in missing parameters or limited output.

Verifying with netstat

If telnet or nc only shows a blocked state, use netstat -atpn to view actual connection details.

Locate the tested IP and port in the Foreign Address column and check that the State is ESTABLISHED , which indicates the port is functional.

netstat is a useful tool for monitoring TCP/IP connections, showing routing tables, active connections, and socket states. Common flags include:

-a: display all sockets

-t: show TCP connections

-p: display process information

-n: show numeric addresses without DNS lookup

Important TCP states include LISTENING, SYN‑SENT, SYN‑RECEIVED, ESTABLISHED, FIN‑WAIT‑1, FIN‑WAIT‑2, CLOSE‑WAIT, CLOSING, LAST‑ACK, TIME‑WAIT, and CLOSED.

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.

network debuggingnetstattelnetnetcatport testing
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.