Sub topic 12
Using the layers to troubleshoot
This chapter assumes you know the seven OSI layers and what each does. It also assumes you can run basic commands in a Linux terminal. Here you will turn the layer model into a repeatable troubleshooting method.
Why layers help
A network fault can sit in a cable, a switch, an IP setting, a firewall, a certificate, or the application itself. Checking everything at once wastes time. The layers give you an order. Each layer depends on the ones below it, so a problem low in the stack breaks everything above it. If Layer 2 is down, a perfect web server still cannot answer.
Find the lowest layer that fails. That is where you start fixing.
Three ways to walk the stack
- Bottom-up: Start at Layer 1 and move up. This is the safest method when you know nothing about the fault, or when nothing works at all.
- Top-down: Start at the application and move down. This suits a problem that affects one program, for example one website that fails while others load.
- Divide and conquer: Start in the middle, usually with
pingat Layer 3. If it works, the lower layers are fine and you move up. If it fails, you move down.
A bottom-up sequence
Each command below tests one layer, so the first failing step shows where to look.
ip link show # Layers 1-2: is the interface up?
ip addr show # Layer 3: does it have an IP address?
ping -c 4 example.com # Layer 3: can packets reach the host (ICMP)?
nc -zv example.com 443 # Layer 4: does a TCP connection to port 443 succeed?
curl -I https://example.com # Layers 6-7: does TLS and HTTP respond?Reading each result
Layers 1 and 2
ip link show reports state UP or state DOWN. A NO-CARRIER flag means the interface sees no signal. Check the cable, the switch port, or the Wi-Fi connection. If the link is up but traffic still fails, look at Layer 2 details such as the MAC address table, VLAN assignment, or duplicate MAC addresses.
Layer 3
ip addr show should list an address on the interface. An address beginning with 169.254 means the host failed to get one from DHCP. If the address looks right, ping tests reachability. Pinging a name also tests DNS, which is an Application layer service. When a name fails but a raw IP address works, the fault is DNS, not routing. Test this by pinging an address such as 8.8.8.8 directly.
Layer 4
nc -zv example.com 443 tries a TCP connection and reports the result. The two failures look different:
| Result | Likely meaning |
|---|---|
| Connection refused | The host is reachable, but nothing listens on that port. |
| Timeout | A firewall drops the packets, or the route is broken. |
| Succeeded | TCP works. The fault is higher up. |
Layers 6 and 7
curl -I fetches only the response headers. A certificate error points to Layer 6 (TLS). An HTTP status such as 404 or 500 means the network works and the application is answering with an error.
Look inside a frame
When tools disagree, capture traffic and read the headers. This script parses an Ethernet II header. The EtherType value tells you which protocol follows.
import struct
def mac(b):
return ":".join(f"{x:02x}" for x in b)
# 14-byte Ethernet II header: destination MAC, source MAC, EtherType
header = bytes.fromhex("ffffffffffff" "001122334455" "0806")
dst, src, ethertype = struct.unpack("!6s6sH", header)
print(mac(dst), mac(src), hex(ethertype))
# ff:ff:ff:ff:ff:ff 00:11:22:33:44:55 0x806The destination ff:ff:ff:ff:ff:ff is the broadcast address, and 0x0806 means ARP. A host that sends many ARP requests and never gets an answer has a Layer 2 or Layer 3 problem on its local network.
Common mistakes
- Starting at the application and assuming the app is broken, when the link is down.
- Treating a DNS failure as a routing failure.
- Changing several things at once, so you cannot tell which change fixed the fault.
- Stopping at the first working layer instead of testing the layer above it.
Exercise
You run ping -c 4 8.8.8.8 and get replies. ping -c 4 example.com says "Temporary failure in name resolution". Which layer do you investigate, and what is one thing you check?
Show answer
Investigate the Application layer, where DNS lives. The replies from 8.8.8.8 show that Layers 1 to 3 work. Check the DNS servers in /etc/resolv.conf (or resolvectl status) and test them with dig example.com.
Exercise
nc -zv example.com 443 hangs and then times out, but ping succeeds. Name one likely cause and the layer involved.
Show answer
A firewall is probably dropping TCP traffic to port 443 without replying. This is a Layer 4 fault. A refused connection would instead mean the host is up but no service listens on that port.