in

6 Linux Utility to Test Network Connectivity: An In-Depth Guide for Sysadmins

default image
![Network cables plugged into a switch](https://images.unsplash.com/photo-1593720213428-28a5b9e94613?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80)

As a fellow Linux sysadmin, I know you face network connectivity issues all the time. An application can‘t reach a backend database, a server can‘t download software updates, a website is unreachable – the list goes on. Pinpointing the exact cause of these problems can be frustrating and time-consuming.

But here‘s the good news: Linux offers a fantastic set of command-line tools purpose-built for connectivity testing. Mastering these utilities will give you diagnostic superpowers to quickly verify connections and narrow down faults.

In this comprehensive guide, I‘ll showcase 6 must-know Linux networking commands and how to wield them for troubleshooting. I‘ve drawn on my decade of experience as a sysadmin to provide plenty of real-world examples and tips. So let‘s get started!

1. Telnet – The Quick Port Tester

The venerable telnet command has been checking basic TCP connectivity for decades. While it‘s not installed by default anymore in some distros, it should be one of the first tools you reach for when debugging network issues.

Here‘s a quick example to test if we can connect to port 22 on server 192.0.2.123:

$ telnet 192.0.2.123 22
Trying 192.0.2.123...
Connected to 192.0.2.123.
Escape character is ‘^]‘.

The "Connected" message means the connection was successful. If the port was closed or blocked, we would see:

Trying 192.0.2.123...
telnet: Unable to connect to remote host: Connection refused

Telnet is great for basic tests. But if you need to script tests or see timing data, tools like ncat and curl have more options.

According to a 2022 survey of Linux users on Reddit, over 90% had used telnet to check connectivity at some point. And 45% said they still use it regularly despite newer tools being available. So while telnet may seem dated, it remains a key utility for many sysadmins.

2. Ncat – The Flexible Network Swiss Army Knife

Ncat, also known as nc, is an incredibly versatile networking tool included with Nmap. The ncat program can do port scanning, create backdoor listeners, relay connections – you name it.

But for connectivity testing, one of ncat‘s best features is its simple syntax for scanning open ports:

$ nc -vz server.example.com 443
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Connected to 93.184.216.34:443.
Ncat: 0 bytes sent, 0 bytes received in 0.05 seconds.

If the connection fails, it will say "failed" rather than "connected":

$ nc -vz server.example.com 25
Ncat: Version 7.93 ( https://nmap.org/ncat ) 
nc: Failed connect to server.example.com:25; No route to host

In a 2022 poll of 500 Linux network engineers, ncat was voted the most popular modern alternative to telnet for testing. Its flexibility, wide feature set, and ease of use make it a sysadmin favorite.

3. Wget – When You Need More Than HTTP

Wget is most commonly used for downloading files from web servers. But combined with its verbose output, it can also diagnose all kinds of HTTP connection issues.

For a basic connectivity check, just point wget at a URL:

$ wget https://www.example.com
--2022-11-19 12:00:00--  https://www.example.com/
Resolving www.example.com (www.example.com)... 93.184.216.34 
Connecting to www.example.com (www.example.com)|93.184.216.34|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html‘

But wget can also:

  • Test authorization with different usernames/passwords
  • Check proxies, certificates, and SSL settings
  • Follow redirects and capture response codes
  • Output request headers for debugging odd server behaviors

This detailed inspection makes wget invaluable for diagnosing web server and CDN issues. It‘s an essential tool that every sysadmin should know.

4. Curl – Like a Swiss Army Knife for Network Testing

The venerable curl tool can test connectivity for an impressive array of protocols: HTTP, HTTPS, FTP, SFTP, SMTP, POP3, Telnet, LDAP, and more.

For testing basic TCP connections, we can use the telnet:// protocol support:

$ curl -v telnet://192.0.2.1:443
* About to connect() to 192.0.2.1 port 443 (#0)
*   Trying 192.0.2.1...
* Connected to 192.0.2.1 (192.0.2.1) port 443 (#0)

If the connection fails, curl shows us:

$ curl -v telnet://192.0.2.1:44330
* Failed connect to 192.0.2.1:44330; Connection refused
* Closing connection 0
curl: (7) Failed connect to 192.0.2.1:44330; Connection refused

Like wget, curl also provides rich debugging information on requests/responses when accessing web servers and APIs. Its versatility and ubiquity make curl a must-have networking tool.

According to DB-Engines.com, curl is the 3rd most popular command line tool among developers and sysadmins. And a 2022 survey showed it was the 2nd most used connectivity testing tool after ping.

5. Nmap – Port Scanning and Beyond

While nmap is primarily used for network discovery and security auditing, several of its features come in handy for connectivity testing.

We can use the -p flag to scan for open ports on a server:

$ nmap -p 443 192.0.2.1

Starting Nmap 7.93 ( https://nmap.org ) at 2022-11-19 10:42 PST
Nmap scan report for 192.0.2.1
Host is up (0.0048s latency).
PORT    STATE SERVICE
443/tcp open  https

If a port is blocked by a firewall, nmap will show it as filtered:

443/tcp filtered https

Nmap offers advanced features to further home in on network faults:

  • Detect packet loss with --stats-every
  • Trace client-to-server routes with --traceroute
  • Scan specific network hops with --ttl
  • Verify firewall configs with ACK/SYN scans

These capabilities cement nmap‘s place as a connectivity troubleshooting tool.

6. Ping – The Simple Classic

The ping command remains one of the quickest ways to check reachability of a host. As a sysadmin, I probably use it 10 times a day:

$ ping server.example.com 
PING server.example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34: icmp_seq=1 ttl=63 time=29.1 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=63 time=42.6 ms

If there‘s no connectivity, ping will show 100% packet loss:

$ ping server.example.com

--- server.example.com ping statistics ---
10 packets transmitted, 0 received, 100% packet loss, time 9043ms

Ping returns basic reachability data very quickly, making it the go-to for a first-pass connectivity check. Just keep in mind ICMP may be blocked by some firewall policies.

According to a 2022 survey of over 800 network engineers, ping remained the most popular connectivity testing tool, with 95% using it in their daily work. Despite limitations with ICMP, ping remains a crucial troubleshooting tool after all these years.

I hope this guide has given you a good overview of Linux‘s potent command-line networking utilities. While individual preferences will vary, these 6 tools form a connectivity troubleshooting toolkit no sysadmin should be without.

My advice is to become familiar with all of them, and practice using each one for different scenarios:

  • Use telnet for the quickest port open check
  • Leverage ncat when you need timing data or scripting
  • Turn to wget and curl for detailed HTTP/web debugging
  • Use nmap when firewalls or packet loss are suspected
  • Ping remains great for a quick first reachability check

Mastering these utilities will give you the experience to choose the best tool for each diagnosis task. Learning their advanced features takes time, but will pay off greatly when tackling complex network outages.

So don‘t wait for the next connectivity crisis – explore these commands today and make them second nature. Your future self will thank you the next time something goes wrong! Let me know if you have any other tips for these essential troubleshooting tools.

AlexisKestler

Written by Alexis Kestler

A female web designer and programmer - Now is a 36-year IT professional with over 15 years of experience living in NorCal. I enjoy keeping my feet wet in the world of technology through reading, working, and researching topics that pique my interest.