ping is the first command to run when the network does not respond.
It sends a small packet to a target and measures the response time. This
guide gathers the network diagnostic tools a beginner cannot do without.
What you will learn
- Test connectivity with
ping - Check your interfaces with
ip addr - List open ports with
ss - Resolve a DNS name with
dig - Test an HTTP service with
curl
Test connectivity with ping
ping sends ICMP packets (the protocol for network control messages) to a
target and displays the round-trip time:
ping -c 4 8.8.8.8PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=12.3 ms64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=11.8 ms64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=12.1 ms64 bytes from 8.8.8.8: icmp_seq=4 ttl=117 time=11.9 ms
--- 8.8.8.8 ping statistics ---4 packets transmitted, 4 received, 0% packet loss, time 3004msrtt min/avg/max/mdev = 11.800/12.025/12.300/0.183 ms-c 4: sends exactly 4 packets (without-c, ping runs forever).0% packet loss: no packet lost, the target answers every probe.time=12.3 ms: round-trip time in milliseconds.
One reflex before anything else: start with ping 127.0.0.1, the
loopback. This packet never leaves the machine, it crosses neither network
card nor router. If it fails, the problem is therefore on your own system,
network stack or lo interface, and looking at the cable or the router would
waste your time.
Test with a domain name
ping -c 4 google.comIf ping 8.8.8.8 works but ping google.com fails, the problem lies with
DNS, not with the network itself.
Check your interfaces with ip addr
Before diagnosing a network problem, check that your interface does have an IP address. The full reading of this output is explained in Linux networking basics; here, we only keep what decides the rest of the diagnosis:
ip addr show2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 inet 192.168.1.10/24 brd 192.168.1.255 scope global ens33Check two things:
state UPappears on the interface line: it is active.inetis followed by an address: the machine has an IP.
If the interface is DOWN:
sudo ip link set ens33 upCheck the gateway
Make sure the default route exists, that is, that a default via ... line
appears in the output of ip route show (see
Linux networking basics
for how to read routes):
ip route showIf this line is missing, your machine does not know where to send traffic bound for the Internet.
List open ports with ss
ss (socket statistics) replaces the old netstat. It displays network
connections and listening ports:
ss -tlnp| Option | Role |
|---|---|
-t | TCP only |
-l | Listening ports |
-n | Show port numbers (not names) |
-p | Show the associated process |
State Recv-Q Send-Q Local Address:Port Peer Address:Port ProcessLISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=850,fd=3))LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=1200,fd=6))Here, SSH listens on port 22 and Nginx on port 80.
The -t option restricts the output to TCP, which leaves whole
services out. Add -u to include UDP, hence the full form
ss -tulnp: that is the one to remember, otherwise a DNS server or a
monitoring agent will stay invisible in your inventory of ports.
Resolve a DNS name with dig
dig queries DNS servers to translate a name into an IP address:
dig google.com;; ANSWER SECTION:google.com. 300 IN A 142.250.179.110
;; Query time: 15 msec;; SERVER: 192.168.1.1#53(192.168.1.1)ANSWER SECTION: the DNS answer.A: IPv4 record.SERVER: the DNS server that answered.
For a short answer:
dig +short google.com142.250.179.110If the dig command is missing from your system, install the package that
provides it:
sudo apt install bind9-dnsutilssudo dnf install bind-utilsTest an HTTP service with curl
curl sends an HTTP request and displays the result. It is useful to check
that a web server responds:
curl -I http://localhostHTTP/1.1 200 OKServer: nginx/1.24.0Content-Type: text/html-I: shows only the headers (not the full content).200 OK: the server responds correctly.
To test a remote site:
curl -I https://www.stephane-robert.infoTesting locally first, then remotely, is a diagnostic step: if curl answers on
localhost but fails from another machine, the service is running, and the
cause is to be found in the network, the firewall or the address the service
listens on.
Trace the route with traceroute
traceroute displays each router crossed between your machine and the
destination:
traceroute google.com 1 192.168.1.1 (192.168.1.1) 1.234 ms 2 10.0.0.1 (10.0.0.1) 5.678 ms 3 72.14.216.8 (72.14.216.8) 12.345 msEach line is a "hop". On Linux, traceroute sends UDP probes by default and
reads the routers' replies. If a line shows * * *, that router sent no
reply, often because filtering or rate limiting prevents it. This does not
mean the path is broken: if the following hops answer, packets do go
through that router.
traceroute is not always installed by default:
sudo apt install traceroutesudo dnf install tracerouteCommand summary
These 7 commands read as a diagnostic order, not as a catalogue: you
start from the machine with ip addr and ip route, leave the local network
with ping, check name resolution with dig, and only then the
service with curl. Each step rules out one hypothesis, which avoids
testing everything at random. The
Diagnose a network problem on Linux
guide takes this approach further with more complete tools.
| Command | Role |
|---|---|
ping -c 4 target | Test connectivity to a target |
ip addr show | Check your interfaces and IP addresses |
ip route show | Check the default gateway |
ss -tulnp | List the listening TCP and UDP ports |
dig +short domain | Resolve a DNS name |
curl -I url | Test an HTTP service |
traceroute target | Trace the network route |
Troubleshooting
These symptoms share a trap: the displayed message does not name the
cause. Network is unreachable talks about the network while the failure is a
missing route, and a failing curl can come from the service, the
firewall or the listening address. The middle column gives the
hypothesis to check first, the right one the command that settles it.
| Symptom | Likely cause | Solution |
|---|---|---|
ping: connect: Network is unreachable | No gateway configured | Check with ip route show |
ping: google.com: Name or service not known or Temporary failure in name resolution | DNS resolution failing | Test ping 8.8.8.8; if it works, DNS is at fault |
100% packet loss with ping | Firewall or machine switched off | Test another target, check the firewall |
ss -tlnp shows nothing | No service listening | Normal if nothing is installed; start a service (e.g. sshd) |
dig returns no servers could be reached | DNS server unreachable | Check /etc/resolv.conf and network connectivity |
curl: (7) Failed to connect | The target service is not listening or a firewall blocks it | Check with ss -tlnp on the target |
Key points
pingis the first reflex to test connectivity.- Test by IP first (
8.8.8.8), then by name (google.com) to isolate a DNS problem. ip addrchecks the interfaces,ip routethe gateway.ss -tulnpshows the TCP and UDP ports listening on your machine.digandcurltest DNS and HTTP services respectively.- A
* * *intraceroutedoes not prove that the path is broken: that router simply does not reply.
Knowledge check
Check that the essentials of this guide stuck. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Read the logs with journalctl
A new full quiz with random questions
Work again only on the questions you missed