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.
An Ubuntu 24.04 LTS machine with a terminal open.
The addresses in this article are example addresses: 192.0.2.10 (your machine), 192.0.2.1 (the gateway), 198.51.100.10 (a remote machine), example.com. Replace them with your own.
The commands below only read information, so they are safe. They do not change your network configuration.
Steps
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:
The state UP means the card is on. DOWN means it is not on yet or the cable is not plugged in.
The address column should contain an IPv4 address such as 192.0.2.10/24. If it is empty, the machine has not received an address: check the machine's netplan configuration.
An address starting with 127. belongs to the lo card (loopback), which lets the machine talk to itself.
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
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.
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:
If you can ping the gateway but not the remote destination: the problem lies outside your network or on the way out.
If you can ping an IP address but pinging a domain name reports that it cannot be found: the problem is DNS; check with resolvectl status and resolvectl query.
The summary line shows packet loss, the percentage of lost packets, and rtt min/avg/max, the round-trip times.
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.
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.
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:
127.0.0.1:631 listens only inside the machine itself, so nothing from outside can reach it.
0.0.0.0:22 or [::]:22 listens on every network card, meaning other machines on the network can connect.
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.
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.
Mistaking a ping with no reply for a broken network: a firewall may block ICMP. Try another way as well.
Forgetting sudo with ss -p: the program column will be empty for processes owned by other users.
Misreading 127.0.0.1 as "open to the network": this address only works inside the machine itself.
Looking only at ip address and forgetting ip route: having an address but no default route still means you cannot reach the Internet.
Using ifconfig and netstat from old guides: they belong to the net-tools package, which is not installed by default on recent Ubuntu releases; use ip and ss instead.
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.
Man page of ip: https://manpages.ubuntu.com/manpages/noble/en/man8/ip.8.html
Man page of ss: https://manpages.ubuntu.com/manpages/noble/en/man8/ss.8.html
Man page of ping: https://manpages.ubuntu.com/manpages/noble/en/man8/ping.8.html
Man page of tracepath: https://manpages.ubuntu.com/manpages/noble/en/man8/tracepath.8.html
Wikipedia, Ping (networking utility): https://en.wikipedia.org/wiki/Ping_(networking_utility)