Weight: 4
Goal: Troubleshoot network problems on a Linux host, using the standard set of diagnostic tools.
This objective is all about commands. Memorize what each tool does and how to read its output.
When something doesn’t work on the network, work bottom up through the stack:
ip linkip addrip routeping <gateway>ping 8.8.8.8ping example.comss, ncIf step 5 works but step 6 doesn’t, it’s a DNS problem, not a network problem. Knowing this distinction is exam-worthy.
ip — the modern oneip link # interfaces, MAC addresses, up/down state
ip link show eth0
ip link set eth0 up # bring an interface up
ip link set eth0 down # bring it down
ip addr # interfaces with their IP addresses
ip addr show eth0
ip -4 addr # IPv4 only
ip -6 addr # IPv6 onlyifconfig — the legacy
oneifconfig # all up interfaces
ifconfig -a # all interfaces, including down
ifconfig eth0 # one interface
ifconfig eth0 up
ifconfig eth0 downifconfig comes from the net-tools package.
It is deprecated but still on the exam.
A host has a routing table that decides where to send each outgoing packet.
ip route # modern
route -n # legacy (-n disables DNS lookups)
netstat -rn # legacy alternativeTypical output of ip route:
default via 192.168.1.1 dev eth0 proto dhcp
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10
Read it as:
default — the route for anything not
matched by a more specific rule. The “default gateway.”192.168.1.0/24 dev eth0 — directly
attached network; no gateway needed.If ip route does not contain a default
line, you cannot reach anything outside the local subnet, no matter what
else is configured.
ip route add default via 192.168.1.1
ip route add 10.0.0.0/8 via 192.168.1.254
ip route del defaultpingping host # send ICMP echo requests indefinitely
ping -c 4 host # send only 4 packets
ping -i 0.5 host # interval between packets (seconds)
ping -W 2 host # timeout per reply (seconds)
ping -s 1400 host # payload size (test fragmentation/MTU)
ping6 host # IPv6 version (or use `ping -6`)ping outputPING example.com (93.184.216.34): 56 data bytes
64 bytes from 93.184.216.34: icmp_seq=0 ttl=56 time=15.2 ms
64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=14.9 ms
...
4 packets transmitted, 4 packets received, 0.0% packet loss
time= — round-trip time in milliseconds (smaller is
better).ttl= — remaining “time to live” in the IP header; gives
a hint of distance.packet loss — anything above 0% on a stable link is a
problem.Many internet hosts block ICMP for security, so a
failed ping is not always a failure of connectivity.
traceroute, tracepath, mtrThese tools show which routers a packet passes through to reach a destination — by sending packets with increasing TTL values and waiting for the “Time Exceeded” ICMP reply from each hop.
traceroute example.com
traceroute -n example.com # don't resolve hop names (faster)
traceroute -I example.com # use ICMP instead of UDP
traceroute -T -p 80 example.com # use TCP to port 80 (firewalls love TCP/80)
tracepath example.com # similar, no root needed, also shows MTU
mtr example.com # combined traceroute + continuous pingEach line is one hop. * * * means no response from that
router — it could be filtering ICMP, doesn’t matter as long as a later
hop replies.
host,
dig, getentWhen ping <hostname> fails but
ping <ip> works, suspect DNS.
host — short and
friendlyhost example.com
# example.com has address 93.184.216.34
host 93.184.216.34 # reverse lookup
# 34.216.184.93.in-addr.arpa domain name pointer ...
host -t MX example.com # query a specific record type
host -t NS example.com
host -t TXT example.com
host example.com 8.8.8.8 # query a specific DNS serverdig — detaileddig example.com # full A-record query with timing
dig example.com MX # specific type
dig @8.8.8.8 example.com # query a specific server
dig -x 93.184.216.34 # reverse lookup
dig +short example.com # just the answer values
dig +trace example.com # follow the delegation chain from rootdig output includes sections: QUESTION,
ANSWER, AUTHORITY, ADDITIONAL.
The ANSWER is what you asked for.
getent hosts NAME
— what the system actually resolvesgetent hosts example.com
getent ahosts example.comThis is important because host and
dig go straight to DNS, while getent
goes through /etc/nsswitch.conf — so it also checks
/etc/hosts and any other configured source. If
ping and getent agree but dig
disagrees, the answer is coming from /etc/hosts, not
DNS.
nslookup
(legacy, still on the exam)nslookup example.com
nslookup example.com 8.8.8.8Older but still common. host and dig are
preferred today.
ss and
netstatThese show what’s running and connected on the local machine — invaluable when “the service isn’t responding.”
ss — modern, fastss # all established connections
ss -t # TCP only
ss -u # UDP only
ss -l # listening sockets only
ss -n # numeric ports (no DNS lookup)
ss -p # show the process owning each socket
ss -tuln # the classic one: TCP+UDP, listening, numeric
ss -tunap # TCP+UDP, all states, numeric, with processes-tuln is the typical “what is this machine listening
on?” command.
netstat — legacy,
similar usagenetstat -tuln # same idea
netstat -rn # routing table (same as `ip route`)
netstat -i # per-interface statistics
netstat -p # with process info (needs root for others)netstat is part of net-tools and is
deprecated. The exam still expects you to know it.
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.10:22 192.168.1.20:51820 ESTABLISHED
0.0.0.0:22 means “listening on port 22 on every
interface.”127.0.0.1:25 means “only on loopback” — not reachable
from outside.nc (netcat)nc (or netcat) is a Swiss-army knife. For
troubleshooting, the main use is “is this TCP/UDP port open?”
nc -zv host 22 # test TCP port 22 (z = scan, v = verbose)
nc -zv host 80 443 # multiple ports
nc -zvu host 53 # test a UDP port
# Send something into a port
echo "GET / HTTP/1.0" | nc example.com 80
# Listen on a port (handy for ad-hoc testing)
nc -l 12345nc -zv host port is the standard one-liner to check
whether a port is reachable from your machine.
/var/log/syslog (Debian) or
/var/log/messages (RHEL) and the systemd journal contain
useful entries when:
dhclient.journalctl -u NetworkManager.dmesg or the
journal.journalctl -u NetworkManager
dmesg | grep -i eth0| Symptom | Command to try | What it tells you |
|---|---|---|
| Nothing works | ip link |
Is the interface up at all? |
| Interface up but no traffic | ip addr |
Do you have an IP? |
| Have IP, can’t reach outside | ip route |
Is there a default route? |
| Have route, can’t ping gateway | ping <gateway> |
Layer 2 / cable / Wi-Fi issue. |
| Can ping gateway, not internet | ping 8.8.8.8 |
Is upstream routing working? |
| Can ping IPs, not names | host example.com,
cat /etc/resolv.conf |
DNS problem. |
| Service unreachable from another machine | ss -tuln, nc -zv host port, firewall |
Is the daemon actually listening? On the right address? Is a firewall blocking? |
| Slow connection | traceroute, mtr |
Where in the path is the loss/latency? |
Commands to know cold:
ip (link, addr, route)ifconfig, route, arp
(legacy)ping, ping6traceroute, tracepath,
mtrss, netstatnc (netcat)host, dig, nslookup,
getenthostname, hostnamectlConcepts:
/etc/nsswitch.conf in getent
vs dig results.What command shows the routing table on a modern Linux
system? ip route (or ip r). Legacy
alternatives: route -n, netstat -rn.
ping example.com fails but
ping 93.184.216.34 works. What is the most likely
cause? A DNS problem — name resolution is failing. Check
/etc/resolv.conf, /etc/nsswitch.conf, and try
host example.com or dig example.com.
Which command shows the path packets take to a remote
host? traceroute (or tracepath, or
mtr for a continuous variant).
You want to list all TCP and UDP ports currently being
listened on, with numeric port numbers. What command do you
use? ss -tuln (or
netstat -tuln).
What does the address 0.0.0.0:22 in
ss output mean? The service is listening for TCP
connections on port 22, on every interface.
Which command tests whether TCP port 443 is open on host
example.com?
nc -zv example.com 443.
What is the difference between dig and
getent hosts? dig queries DNS
directly. getent hosts uses the system resolver, which
respects /etc/nsswitch.conf and therefore consults
/etc/hosts first.
What is the modern replacement for
ifconfig? The ip command from the
iproute2 package — ip link,
ip addr, ip route.
How do you bring eth0 up at runtime using
ip? ip link set eth0 up.
How do you add an IP address to eth0 at
runtime?
ip addr add 192.168.1.10/24 dev eth0.
What protocol does ping use? ICMP
(Echo Request / Echo Reply).
What does the -n flag do on
netstat, route, or ss?
Disables name (DNS) and service-name lookups — output is numeric only.
Faster and avoids confusing failures from a broken DNS.
How do you query the MX records for
example.com using host and using
dig? host -t MX example.com and
dig example.com MX.
You can ping the gateway but not the public internet.
What do you check next? Whether the gateway itself has
connectivity (likely not your problem), but on your side, confirm
ip route shows a default route via that gateway and
traceroute 8.8.8.8 to see where packets stop.
What’s the difference between traceroute and
mtr? traceroute traces the path once.
mtr runs continuously, combining traceroute with ongoing
ping statistics for each hop.