Operations 5 min read

How to Test Port Connectivity with Telnet and Nmap – A Step‑by‑Step Guide

This tutorial explains why telnet is insecure, shows how to use nmap to discover open ports, demonstrates telnet commands for checking connectivity on specific ports, interprets the results, and provides a simple Bash script to automate multi‑host port testing.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Test Port Connectivity with Telnet and Nmap – A Step‑by‑Step Guide

Telnet is a stripped‑down version of SSH that transmits data without encryption, making it vulnerable to eavesdropping and man‑in‑the‑middle attacks; therefore its default port should be closed. However, telnet can still be useful for quickly testing whether a remote host’s port is reachable.

Before using telnet, run nmap to scan the target server and see which ports are open. For example: $ nmap lxlinux.net After confirming a port is open, test its connectivity with telnet using the syntax telnet <server> <port>. To check HTTP (port 80) on lxlinux.net: $ telnet lxlinux.net 80 If the connection succeeds, telnet prints Connected to lxlinux.net., indicating the port is reachable. If the port is closed, you will see a message such as unable connect to remote host: Connection timed out or Connection refused.

To verify a closed port, first confirm with nmap using the -p option, e.g., $ nmap -p 22 lxlinux.net Since port 22 is not listed as open, testing it with telnet yields: $ telnet lxlinux.net 22 The output Connection refused confirms the port is not reachable.

When a telnet session is established, press CTRL+] to enter the telnet interactive prompt ( telnet>), then type quit to close the connection.

Because telnet can report the status of a single host‑port pair, you can automate checks for multiple hosts and ports with a Bash script. Below is a simple example named multipletelnet.sh:

#!/bin/bash

telnet lxlinux.net 80
telnet baidu.com 80
telnet lxlinux.net 443

Make the script executable with: $ chmod +x multipletelnet.sh Running the script will attempt each telnet connection sequentially, allowing you to see which ports are open. For more extensive testing of many ports, consider using nmap or other dedicated scanning tools instead of a simple telnet loop.

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 troubleshootingLinuxBash scripttelnetport 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.