Operations 7 min read

Linux Network Troubleshooting: Using ping, traceroute, nslookup, netstat, and telnet

This article explains how to diagnose Linux server network problems using common tools such as ping, a shell script for LAN scanning, traceroute, nslookup, netstat, and telnet, providing command syntax, example outputs, and guidance on interpreting results.

php中文网 Courses
php中文网 Courses
php中文网 Courses
Linux Network Troubleshooting: Using ping, traceroute, nslookup, netstat, and telnet

If a company website is inaccessible, the issue may stem from network problems; similarly, remote connection tools or MySQL may fail due to network issues. This guide shows how to troubleshoot Linux server network problems.

ping tests connectivity between hosts using an IP address or domain name. It works on both Linux and Windows. Example usage and output:

# ping -c 4 8.210.247.5
PING 8.210.247.5 (8.210.247.5) 56(84) bytes of data.
64 bytes from 8.210.247.5: icmp_seq=1 ttl=64 time=1.54 ms
64 bytes from 8.210.247.5: icmp_seq=2 ttl=64 time=1.48 ms
64 bytes from 8.210.247.5: icmp_seq=3 ttl=64 time=1.46 ms
64 bytes from 8.210.247.5: icmp_seq=4 ttl=64 time=1.48 ms
--- 8.210.247.5 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 1.460/1.494/1.548/0.042 ms

A shell script can scan a LAN to list reachable IPs:

#!/bin/bash
net='192.168.2.'
seqs=`seq 1 254`
for seq in $seqs
do
ip=$net$seq
/usr/bin/ping -c 1 -W 1 $ip >/dev/null 2>&1
if [ "$?" == "0" ]; then
echo "$ip is UP"
fi
done

traceroute shows each network hop between the local host and a destination, useful for diagnosing slow website access:

# traceroute -n google.com
traceroute to google.com (172.217.163.238), 30 hops max, 60 byte packets
1 * * *
2 11.109.220.61 1.444 ms 1.577 ms 11.109.216.189 1.500 ms
3 11.109.220.190 5.512 ms * 11.109.220.174 5.382 ms
4 11.131.180.222 1.660 ms 11.131.180.218 1.519 ms 11.131.180.250 1.365 ms

nslookup resolves a domain name to its IP address:

nslookup 5iqm.com
Server: 100.100.2.136
Address: 100.100.2.136#53
Non-authoritative answer:
Name: 5iqm.com
Address: 121.196.12.64

netstat displays listening ports and active connections, helping verify whether required services (e.g., port 80 for HTTP) are open:

# netstat -tlunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      30721/nginx: master
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      1275/pure-ftpd (SER
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1167/sshd
tcp        0      0 0.0.0.0:888             0.0.0.0:*               LISTEN      30721/nginx: master
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      2068/python

telnet tests whether a specific port on a remote host is reachable:

# telnet 8.210.110.139 22
Trying 8.210.110.139...
Connected to 8.210.110.139.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
# telnet 8.210.110.139 3306
Trying 8.210.110.139...  (if it keeps trying, the port is closed)

By following these steps—pinging the server IP, pinging the domain, checking DNS resolution, verifying that required ports are open with netstat or telnet—you can systematically identify and resolve most Linux network connectivity issues.

Network Troubleshootingpingtraceroutelinuxnetstattelnetnslookup
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login 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.