Menu
Basic network troubleshooting
“Read and change addresses and routes with ip, find listening ports with ss, test paths with ping, traceroute, tracepath and netcat, and know the old net-tools.”
“The network is down” can mean a hundred things: a cable, a wrong address, a missing route, a dead DNS server, a firewall, a service that crashed. Good troubleshooting is about asking the right question in the right order, and each question has a command.
This byte covers the iproute2 tools (ip, ss) that every current distribution ships, the path testers (ping, traceroute, tracepath, netcat) and the legacy net-tools (ifconfig, route, netstat) the exam still expects you to recognize. Everything you change here with ip is temporary: it’s gone after a reboot. To make it stick, use the tools from persistent network configuration.
You need root (or sudo) to change anything, not to look. If a command is missing, install iproute2, iputils-ping, traceroute, iputils-tracepath and netcat-openbsd on Debian or Ubuntu, or iproute, iputils, traceroute and nmap-ncat on RHEL or Fedora.
Interfaces with ip#
ip takes an object and a command: ip <object> <command>. Objects can be shortened: ip a is ip addr, ip r is ip route, ip l is ip link, ip n is ip neigh.
Look#
ip addr show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:4e:66:a1 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.50/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3
valid_lft 85912sec preferred_lft 85912sec
inet6 fe80::a00:27ff:fe4e:66a1/64 scope link noprefixroute
valid_lft forever preferred_lft foreverHow to read it:
<...UP,LOWER_UP>:UPmeans the interface is switched on,LOWER_UPmeans a cable or radio link is actually there.NO-CARRIERmeans “unplugged”.link/ether: the MAC address.inetis IPv4,inet6is IPv6, each with its prefix.dynamicmeans it came from DHCP.mtu 1500: the largest packet the interface sends.
Useful variations:
ip -br addr # one line per interface
ip -4 addr # only IPv4
ip addr show dev enp0s3 # one interface
ip -s link show enp0s3 # with packet, error and drop countersChange#
sudo ip link set dev enp0s3 down # switch the interface off
sudo ip link set dev enp0s3 up # and on again
sudo ip addr add 192.168.1.60/24 dev enp0s3
sudo ip addr del 192.168.1.60/24 dev enp0s3
sudo ip addr flush dev enp0s3 # remove every address
sudo ip link set dev enp0s3 mtu 9000 # change the MTUAn interface can hold several addresses at once, so ip addr add adds one rather than replacing the old one. Always give the prefix: without /24, ip assumes /32, a network of one, and nothing else on the LAN is reachable.
ip neigh shows the neighbor table: which MAC address belongs to which IP on your local network (ARP for IPv4, NDP for IPv6):
192.168.1.1 dev enp0s3 lladdr a4:2b:b0:11:22:33 REACHABLE
192.168.1.10 dev enp0s3 lladdr 08:00:27:9c:41:0e STALERouting with ip#
The routing table tells the kernel where to send each packet. Every packet goes to the most specific matching route. If nothing else matches, it goes to the default route, also called the default gateway.
ip routedefault via 192.168.1.1 dev enp0s3 proto dhcp src 192.168.1.50 metric 100
192.168.1.0/24 dev enp0s3 proto kernel scope link src 192.168.1.50 metric 100Line one: anything without a better match goes via the router 192.168.1.1. Line two: 192.168.1.0/24 is directly attached, so packets there go straight out of enp0s3 (proto kernel means the kernel added it when the address was set).
To ask “which route would a packet to this address take?”:
ip route get 1.1.1.11.1.1.1 via 192.168.1.1 dev enp0s3 src 192.168.1.50 uid 1000
cacheChange routes like this:
sudo ip route add 10.10.0.0/16 via 192.168.1.254 # a network behind another router
sudo ip route del 10.10.0.0/16
sudo ip route add default via 192.168.1.1 # set the default gateway
sudo ip route replace default via 192.168.1.254 # change it in one step
sudo ip route del default
ip -6 route # the IPv6 tableip route add default fails with RTNETLINK answers: File exists if a default route is already there. Use replace, or delete the old one first.
To make a static route persistent with NetworkManager, add it to the profile:
sudo nmcli connection modify office +ipv4.routes "10.10.0.0/16 192.168.1.254"
sudo nmcli connection up officeNote
A Linux box only passes packets between its interfaces (acts as a router) when forwarding is on: sysctl net.ipv4.ip_forward shows 0 or 1. Turn it on with sudo sysctl -w net.ipv4.ip_forward=1, and make it permanent in a file under /etc/sysctl.d/.
hostname#
hostname prints or sets the machine’s name. Setting it this way lasts only until reboot (use hostnamectl for a permanent change).
| Command | Shows |
|---|---|
hostname | the name, like web01 |
hostname -s | the short name, without the domain |
hostname -f | the fully qualified name, like web01.example.lan |
hostname -d | only the domain, example.lan |
hostname -i | the address(es) the hostname resolves to |
hostname -I | every address on every interface (no name lookup) |
sudo hostname web02 | sets the name until reboot |
hostname -i printing 127.0.1.1 is normal on Debian: it comes from /etc/hosts.
Sockets with ss#
ss (socket statistics) shows open connections and listening ports. It replaces netstat.
sudo ss -tulpnNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
udp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=612,fd=13))
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=801,fd=3))
tcp LISTEN 0 511 *:80 *:* users:(("nginx",pid=1022,fd=6))
tcp LISTEN 0 4096 127.0.0.1:5432 0.0.0.0:* users:(("postgres",pid=944,fd=7))| Option | Meaning |
|---|---|
-t / -u | TCP / UDP sockets |
-l | only listening sockets (without it: only established ones) |
-a | all sockets, listening and connected |
-n | numbers, not names (22, not ssh) |
-p | the process using the socket (needs root for other users’ processes) |
-s | summary counts |
-4 / -6 | only IPv4 / IPv6 |
The local address tells you who can reach the service. 0.0.0.0:22 or *:80 listens on every interface. 127.0.0.1:5432 only accepts connections from the machine itself, a classic reason for “works locally, refused from outside”.
ss can filter, too:
ss -tn state established '( dport = :443 )'Testing reachability with ping and ping6#
ping sends ICMP echo requests and waits for echo replies. It answers the most basic question: can I reach that address at all?
ping -c 4 192.168.1.1PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.512 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.431 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.540 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.509 ms
--- 192.168.1.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 0.431/0.498/0.540/0.041 msWithout -c, Linux ping runs until you press Ctrl+C. Other options: -i 0.5 (interval in seconds), -W 2 (seconds to wait for a reply), -s 1472 (payload size), -I enp0s3 (send from this interface).
For IPv6, use ping6 or ping -6. On current systems ping6, where it still exists, is just another name for ping. Link-local addresses need the interface:
ping6 -c 2 ::1
ping -6 -c 2 fe80::1%enp0s3Read failures carefully:
Destination Host Unreachable: nobody on the local network answered ARP. Wrong address, or the host is off.Network is unreachable: your machine has no route for that address. Checkip route.- No output, 100% packet loss: packets go out, but nothing comes back. Often a firewall dropping ICMP.
Tip
A failing ping doesn’t prove a host is down. Many servers and cloud firewalls block ICMP. Test the real service port with nc before you conclude anything.
Following the path: traceroute and tracepath#
When the gateway answers but a far host doesn’t, find where the packets stop. traceroute sends probes with a TTL (time to live) of 1, then 2, then 3. Each router lowers the TTL by one, and the router where it hits zero sends back an ICMP “time exceeded”. That reveals every hop:
traceroute example.comtraceroute to example.com (203.0.113.10), 30 hops max, 60 byte packets
1 router.lan (192.168.1.1) 0.612 ms 0.571 ms 0.549 ms
2 10.20.0.1 (10.20.0.1) 8.921 ms 9.004 ms 8.877 ms
3 * * *
4 ae-1.core1.ams.example.net (198.51.100.17) 12.402 ms 12.388 ms 12.511 ms
5 203.0.113.10 (203.0.113.10) 14.230 ms 14.118 ms 14.207 msEach line is a hop with three timing probes. * * * means that router didn’t answer in time, which is common and harmless if later hops still answer. If every hop after a certain point is * * *, that is where traffic dies.
Linux traceroute sends UDP probes by default (ports from 33434 up). -I uses ICMP echo instead, -T uses TCP SYN (needs root), -n skips name lookups. traceroute6 or traceroute -6 does the same over IPv6.
tracepath is the simpler cousin from iputils. It needs no root and also discovers the path MTU, the largest packet that fits through every hop:
tracepath -n example.com 1?: [LOCALHOST] pmtu 1500
1: 192.168.1.1 0.598ms
1: 192.168.1.1 0.512ms
2: 10.20.0.1 9.112ms
3: no reply
4: 198.51.100.17 12.733ms asymm 5
5: 203.0.113.10 14.302ms reached
Resume: pmtu 1500 hops 5 back 5For IPv6 use tracepath6, or tracepath -6 on systems where the separate tracepath6 command is gone.
mtr (from the mtr package) combines ping and traceroute in one live, updating screen. It isn’t on the exam, but it’s the tool many admins reach for first.Talking to ports: netcat#
netcat (nc) opens a raw TCP or UDP connection and connects it to your terminal. It’s the Swiss army knife for “is that port really open?”
nc -zv example.com 443
nc -zv example.com 8443Connection to example.com (203.0.113.10) 443 port [tcp/https] succeeded!
nc: connect to example.com (203.0.113.10) port 8443 (tcp) failed: Connection refused-z only checks the connection without sending data, -v prints what happens, -u switches to UDP, -w 3 gives up after 3 seconds. “Connection refused” means the host answered but nothing listens there. A long wait ending in a timeout usually means a firewall drops the packets.
You can also speak a text protocol by hand. Here is a raw HTTP request (see the HTTP topic for what the lines mean):
printf 'HEAD / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n' | nc example.com 80Or open a tiny chat between two terminals. One listens, the other connects, and whatever you type appears on the other side:
nc -l 5000 # terminal 1: listen on port 5000
nc 192.168.1.50 5000 # terminal 2: connect to itThere are several netcats. Debian and Ubuntu use netcat-openbsd (shown above). RHEL and Fedora ship ncat from the Nmap project as nc, which prints messages like Ncat: Connected to 203.0.113.10:443. The old netcat-traditional wants nc -l -p 5000 to listen.
Legacy net-tools: ifconfig, route, netstat#
Before iproute2, Linux used the net-tools package: ifconfig, route, netstat and arp. They are deprecated, not installed by default on Debian 12 or RHEL 9 (install the net-tools package), and they don’t show everything (for example extra addresses added with ip addr add). But old scripts, old documentation and the exam still use them.
ifconfig enp0s3enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.50 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe4e:66a1 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:4e:66:a1 txqueuelen 1000 (Ethernet)
RX packets 10234 bytes 9876543 (9.4 MiB)
TX packets 5120 bytes 612345 (598.0 KiB)route -nKernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 enp0s3
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3The G flag marks a route through a gateway. Destination 0.0.0.0 with mask 0.0.0.0 is the default route.
| Task | Legacy net-tools | iproute2 |
|---|---|---|
| Show all interfaces | ifconfig -a | ip addr |
| Set an address | ifconfig enp0s3 192.168.1.60 netmask 255.255.255.0 | ip addr add 192.168.1.60/24 dev enp0s3 |
| Interface up / down | ifconfig enp0s3 up / down | ip link set enp0s3 up / down |
| Show routes | route -n or netstat -rn | ip route |
| Set default gateway | route add default gw 192.168.1.1 | ip route add default via 192.168.1.1 |
| Add a network route | route add -net 10.10.0.0 netmask 255.255.0.0 gw 192.168.1.254 | ip route add 10.10.0.0/16 via 192.168.1.254 |
| Delete default route | route del default gw 192.168.1.1 | ip route del default |
| Listening ports | netstat -tulpn | ss -tulpn |
| All connections | netstat -an | ss -an |
| Interface counters | netstat -i | ip -s link |
| ARP / neighbor table | arp -n | ip neigh |
A troubleshooting order#
Work from the bottom up. Stop at the first step that fails, fix it, and start again:
- Link: is the interface up with a carrier?
ip -br link(look forUPand noNO-CARRIER). - Address: does it have the right address and prefix?
ip -br addr. A169.254.x.xaddress means DHCP failed. - Local network: does the gateway answer?
ip routeto find it, thenping -c 3 <gateway>. - Beyond: can you reach an outside address by number?
ping -c 3 1.1.1.1. If not,tracepath -n 1.1.1.1shows where it stops. - Names: does DNS work?
ping example.comfails butping 1.1.1.1works means a DNS problem. See client side DNS. - Service: is the port open? On the server
ss -tlnp, from the clientnc -zv host port. Check whether it listens on127.0.0.1only, and whether a firewall is in the way.
The logs help too: journalctl -u NetworkManager (or -u systemd-networkd) and dmesg | grep -i enp0s3 show link changes and DHCP results.
Exam checklist#
ip addr,ip link,ip route,ip neighto view.ip addr add|del IP/prefix dev IF,ip link set IF up|down. All changes are lost at reboot.- Default route:
ip route add default via GW. Network route:ip route add NET/prefix via GW.ip route get IPshows which route is used. - Legacy equivalents:
ifconfig,route -n,route add default gw GW,netstat -tulpn,netstat -rn,arp. They come from net-tools and are deprecated. ss -tulpn: TCP, UDP, listening, process, numeric.0.0.0.0or*listens everywhere,127.0.0.1only locally.pinguses ICMP echo;-ccount.ping6(orping -6) for IPv6; link-local needs%interface.tracerouteuses rising TTLs and UDP by default (-IICMP,-TTCP).tracepathneeds no root and reports path MTU. Both have6versions.nc -zv host porttests a TCP port,nc -l portlistens,-ufor UDP.hostnameshows or temporarily sets the name.-fFQDN,-iresolved address,-Iall local addresses.- Troubleshoot bottom up: link, address, gateway, routing, DNS, service and firewall.
Answer these 3 questions to commit this byte to your learning path.
Reset. This byte isn't committed any more. Answer the questions again to commit it.
$ git commit -m "learn(lpic-109): Basic network troubleshooting"
[main 6c90fd7] learn(lpic-109): Basic network troubleshooting
1 byte changed, 3 insertions(+)
See it on your path Already committed . Try the questions again any time, it won't undo anything. To uncommit it and start over: