Skip to main content
Systematic Network Troubleshooting with CLI
Lesson 1 of 24

Systematic Network Troubleshooting with CLI

Isolate network faults step by step from local interfaces and routing to DNS and listening sockets using ip, mtr, dig, ss, and nc.

Intermediate 22 min Blue Team / SOC

Learning objectives

  • Apply a bottom-up layered workflow to isolate connectivity faults from link state to application ports
  • Verify local interface addresses, routing tables, and listening sockets with ip and ss
  • Distinguish intermediate ICMP rate-limiting from real path packet loss in mtr output
  • Diagnose DNS resolution failures with dig and test TCP port reachability with nc

Recommended first: IPv4/IPv6 Addressing & CIDR SubnettingTCP, UDP, Ports & ICMP DiagnosticsDNS Resolution & DHCP Lease MechanicsRouting Tables, Gateways, NAT & VLANsFirewalls, Stateful Filtering & Rule Order

#Why this matters

When an application fails to connect, guessing at firewall rules or restarting services wastes time and hides the root cause. A request can fail at the local interface, routing table, transit hop, DNS resolver, firewall, or listening process. Testing one layer at a time with CLI tools turns vague symptoms into verifiable facts.

Changing configuration blindly also destroys your baseline and makes intermittent faults harder to reproduce. Recording the exact command output at each layer gives you a clear timeline and concrete evidence if you need to escalate the incident to another team.

#The bottom-up fault-isolation model

Start at the host you control, move outward along the path, and check naming and application ports last.

  1. Local interface & IPip -br addr and ip route
  2. Path & packet lossping and mtr -rn
  3. Name resolutiondig A/AAAA records
  4. Port reachabilitync -zv host port
  5. Server socket statess -tulnp
Layer Question to answer Primary CLI check
Link & IP (L2/L3) Is the interface up with the right IP and mask? ip -br addr
Routing (L3) Does a route exist to the target or gateway? ip route get <ip>
Transit path (L3) Where do packets drop or gain latency? mtr -rn -c 10 <ip>
Naming (L7) Does the hostname resolve to the expected IP? dig <name>
Transport (L4) Does the port accept, refuse, or time out? nc -zv <ip> <port>
Host service (L4/L7) Is the process listening on the right IP and port? ss -tulnp

Working from the bottom up prevents false leads. If the local network interface is down or lacks a default route, every DNS query and TCP connection test will fail as a side effect. Verifying lower layers first ensures each new check depends only on components you already proved healthy.

#Checking local state and sockets with ip and ss

Inspect the local network stack before blaming external infrastructure. On Linux, ip -br addr shows interface link state (UP or DOWN) and assigned addresses, while ip route displays the default gateway and subnet routes.

On the server, ss -tulnp lists TCP (-t) and UDP (-u) listening sockets (-l) with numeric ports (-n) and process owners (-p, requiring sudo for other users' processes).

Checking addresses, routes, and listening sockets on lab.local
$ ip -br addr
lo               UNKNOWN        127.0.0.1/8 ::1/128
eth0             UP             10.10.10.25/24
$ ip route
default via 10.10.10.1 dev eth0
10.10.10.0/24 dev eth0 proto kernel scope link src 10.10.10.25
$ sudo ss -tulnp
Netid State  Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp   LISTEN 0      128        127.0.0.1:8080      0.0.0.0:*     users:(("python3",pid=1420,fd=3))
tcp   LISTEN 0      511          0.0.0.0:443       0.0.0.0:*     users:(("nginx",pid=912,fd=6))

Watch the Local Address:Port column. nginx listens on 0.0.0.0:443, accepting remote traffic on all IPv4 interfaces. python3 listens only on 127.0.0.1:8080 (loopback), so remote hosts cannot reach port 8080 even with no firewall.

You can also run ip route get 192.0.2.10 to confirm which source IP, interface, and next-hop gateway the kernel selects for a specific destination. In ss -tulnp output, binding to 0.0.0.0 accepts connections on every IPv4 interface, whereas binding to a specific address such as 10.10.10.25 restricts traffic to that interface alone.

#Isolating path loss and DNS with mtr and dig

Next, trace the network path with mtr, which repeatedly sends TTL-limited probes and summarizes per-hop loss and latency. Pass -n to skip reverse DNS lookups (preventing hangs when DNS is broken) and -r -c 10 for a 10-cycle report.

Measuring path loss and testing DNS in a lab network
$ mtr -rn -c 10 192.0.2.10
HOST: client.lab.local            Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- 10.10.10.1                 0.0%    10    0.4   0.5   0.3   0.8   0.1
  2.|-- 10.10.99.2                40.0%    10    2.1   2.2   1.9   2.6   0.2
  3.|-- 192.0.2.10                 0.0%    10    3.4   3.5   3.1   4.1   0.3
$ dig @10.10.10.2 api.lab.local A +noall +answer +comments
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41822
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; ANSWER SECTION:
api.lab.local.          300     IN      A       192.0.2.10

Hop 2 shows 40.0% loss while hop 3 (192.0.2.10) shows 0.0%. That is not a broken link: routers rate-limit ICMP Time Exceeded replies to themselves while forwarding transit traffic normally. Real loss starts at a hop and continues to the destination.

For DNS, query both the system resolver (dig api.lab.local) and a known nameserver (dig @10.10.10.2 api.lab.local). NOERROR with an answer means success, NXDOMAIN means the name does not exist, and SERVFAIL or a timeout indicates resolver failure.

Before blaming remote routers, run ping -c 5 10.10.10.1 to confirm the local gateway responds cleanly at layer 3. If dig api.lab.local times out while dig @10.10.10.2 api.lab.local succeeds, inspect /etc/resolv.conf or resolvectl status because the local stub resolver configuration is broken rather than the authoritative server.

#Testing reachability with nc

Once IP routing and DNS check out, test the target TCP port with nc -zv <ip> <port> (-z zero-I/O scan, -v verbose):

  • Succeeded / open: The TCP handshake completed; any remaining fault is at TLS or the application.
  • Connection refused: A host or reject rule sent a TCP RST. The network path works, and no service is listening on that IP/port.
  • Connection timed out: Neither SYN-ACK nor RST returned. A firewall silently dropped the packet, or the return route is missing.

Always add a short timeout such as -w 3 so dropped packets do not stall your shell or scripts. When nc succeeds, continue testing at the application layer with curl -v or openssl s_client to isolate TLS certificate or HTTP errors.

#Common mistakes

  • Treating intermediate mtr loss as a link fault: If the final hop has 0% loss, the middle router is only throttling ICMP replies.
  • Omitting -n during outages: Without -n, ss and mtr stall on reverse DNS lookups when DNS is down.
  • Confusing Connection refused with a silent drop: A silent firewall drop times out; Connection refused means an active RST returned.
  • Relying only on ping: Hosts often block ICMP Echo while allowing TCP 443, so verify application ports with nc.

#Summary

  • Work bottom-up from local interfaces (ip) to path (mtr), DNS (dig), and TCP ports (nc).
  • Inspect ss -tulnp on the server to catch 127.0.0.1 loopback bindings.
  • Read mtr loss through to the final hop, and use -n to avoid DNS stalls.
  • Use nc errors to separate timeouts (silent drops) from Connection refused (closed port or reject).

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge