Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Test network connectivity

By updated

Improve this page

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:

Terminal window
ping -c 4 8.8.8.8
Output
PING 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 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=11.8 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=12.1 ms
64 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 3004ms
rtt 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

Terminal window
ping -c 4 google.com

If 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:

Terminal window
ip addr show
Output (excerpt)
2: 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 ens33

Check two things:

  • state UP appears on the interface line: it is active.
  • inet is followed by an address: the machine has an IP.

If the interface is DOWN:

Terminal window
sudo ip link set ens33 up

Check 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):

Terminal window
ip route show

If 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:

Terminal window
ss -tlnp
OptionRole
-tTCP only
-lListening ports
-nShow port numbers (not names)
-pShow the associated process
Output (excerpt)
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 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:

Terminal window
dig google.com
Output (excerpt)
;; 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:

Terminal window
dig +short google.com
Output
142.250.179.110

If the dig command is missing from your system, install the package that provides it:

Terminal window
sudo apt install bind9-dnsutils

Test an HTTP service with curl

curl sends an HTTP request and displays the result. It is useful to check that a web server responds:

Terminal window
curl -I http://localhost
Output
HTTP/1.1 200 OK
Server: nginx/1.24.0
Content-Type: text/html
  • -I: shows only the headers (not the full content).
  • 200 OK: the server responds correctly.

To test a remote site:

Terminal window
curl -I https://www.stephane-robert.info

Testing 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:

Terminal window
traceroute google.com
Output (excerpt)
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 ms

Each 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:

Terminal window
sudo apt install traceroute

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

CommandRole
ping -c 4 targetTest connectivity to a target
ip addr showCheck your interfaces and IP addresses
ip route showCheck the default gateway
ss -tulnpList the listening TCP and UDP ports
dig +short domainResolve a DNS name
curl -I urlTest an HTTP service
traceroute targetTrace 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.

SymptomLikely causeSolution
ping: connect: Network is unreachableNo gateway configuredCheck with ip route show
ping: google.com: Name or service not known or Temporary failure in name resolutionDNS resolution failingTest ping 8.8.8.8; if it works, DNS is at fault
100% packet loss with pingFirewall or machine switched offTest another target, check the firewall
ss -tlnp shows nothingNo service listeningNormal if nothing is installed; start a service (e.g. sshd)
dig returns no servers could be reachedDNS server unreachableCheck /etc/resolv.conf and network connectivity
curl: (7) Failed to connectThe target service is not listening or a firewall blocks itCheck with ss -tlnp on the target

Key points

  • ping is 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 addr checks the interfaces, ip route the gateway.
  • ss -tulnp shows the TCP and UDP ports listening on your machine.
  • dig and curl test DNS and HTTP services respectively.
  • A * * * in traceroute does 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

6 questions
6 min
70% to pass

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