Checking network connectivity on Ubuntu with ip, ss, ping and tracepath

  1. Goal
  2. Preparation
  3. Steps
  4. Step 1: Does my machine have an address? (ip address, ip link)
  5. Step 2: Is there a way out? (ip route)
  6. Step 3: Does the nearest neighbor answer? (ip neighbor)
  7. Step 4: Try ping
  8. Step 5: Where do packets pass through? (tracepath)
  9. Step 6: Which program has a port open? (ss)
  10. Verification
  11. Common mistakes
  12. In short
  13. References

Goal

When the network misbehaves, instead of guessing you can work step by step from near to far: does my machine have an address, does it have a way out, does the destination answer, and which program has a port open.

This article introduces four tools that come with Ubuntu 24.04 LTS: ip, ss, ping and tracepath.

Preparation

Steps

Steps

Step 1: Does my machine have an address? (ip address, ip link)

ip -br link
ip -br address

The -br (brief) option prints each network card on a single line to make it easier to read. Look at:

Step 2: Is there a way out? (ip route)

ip route

Look for the line that starts with default via, for example default via 192.0.2.1 dev enp1s0. That is the default route. Without this line, the machine can only talk to its own subnet.

To see which path packets will take to a destination:

ip route get 198.51.100.10

Step 3: Does the nearest neighbor answer? (ip neighbor)

ip neighbor

This table shows the MAC addresses of the machines on the same subnet that your machine has contacted, including the gateway.

A line with the state REACHABLE or STALE is a good sign; FAILED means the MAC address of that machine could not be resolved.

Step 4: Try ping

ping sends ICMP echo packets and measures the reply time. Go from near to far:

ping -c 4 192.0.2.1
ping -c 4 198.51.100.10
ping -c 4 example.com

The -c 4 option limits the count to four packets so the command stops by itself. How to read the results:

An important note: many servers and firewalls deliberately do not answer ICMP. No reply to a ping does not necessarily mean the network is broken; also try connecting to the real service port.

Step 5: Where do packets pass through? (tracepath)

tracepath -n 198.51.100.10

tracepath lists each hop that packets pass through on the way to the destination. The -n option prints numeric addresses and skips name lookups, so it runs faster.

It does not need root privileges. no reply lines in the middle of the path are quite common because some devices do not answer; what matters is where the path stops completely and where the time jumps sharply.

The pmtu line shows the largest packet size that can travel along that path (path MTU).

The tracepath command is in the iputils-tracepath package; if the machine says the command is not found, install it with sudo apt install iputils-tracepath.

Step 6: Which program has a port open? (ss)

ss (socket statistics) lists connections and open ports, and replaces the old netstat command.

ss -tuln

What each letter means: t is TCP, u is UDP, l means only listening ports, n prints numbers instead of names. Each line shows the local address and port. Pay attention to the address column:

To find out which program holds a port, add p and run with sudo:

sudo ss -tulnp

A few other useful variations: ss -t state established lists only established TCP connections, and ss -tn dst 198.51.100.10 filters by destination.

When you see an unfamiliar open port, do not rush to close it by stopping a service you do not understand; first look up what that program is.

Every service exposed to the network should have a strong password, as described in the article Strong passwords and password managers: break the habit of one password for everything.

Verification

A quick five-command "check-up", going from near to far:

ip -br address
ip route
ping -c 2 192.0.2.1
ping -c 2 example.com
ss -tuln

If all five commands give sensible results, your machine's network is basically fine.

Common mistakes

In short

Diagnose in this order: ip -br address (do you have an address), ip route (is there a way out), ping (does the destination answer), tracepath (where does it break) and ss -tuln (which ports are open).

Going from near to far helps you narrow down the fault quickly without guessing.

References

Checking network connectivity on Ubuntu with ip, ss, ping and tracepath