Sub topic 12
Using the layers to troubleshoot
Prerequisites and approach
This chapter assumes you know the seven OSI layers and what each one does. It also assumes you know the basics of encapsulation, and that you can run simple commands in a Linux terminal. Here you will turn the model into a repeatable method for finding network faults.
The idea is simple. A failure at one layer breaks everything above it. A working layer says nothing about the layers above it. If you test the layers in order and stop at the first failure, you know where to look, and you skip many wrong guesses.
Why the layers help
Each layer depends on the layer below it. An IP address is useless if the cable is unplugged. A TCP connection cannot open if routing is broken. An HTTP request cannot succeed if the TCP connection is refused.
This gives you two rules:
- If a layer fails, ignore the layers above it until it is fixed. Their errors are probably side effects.
- If a layer passes its test, the layers below it are probably fine, at least for the path you tested.
The second rule is only "probably" true. A test at one layer can pass by luck or by a different path. For example, a ping to a nearby host proves that Layer 3 works to that host. It says nothing about a different destination.
Three ways to walk the stack
You can choose a direction based on the symptoms.
| Approach | Start at | Best when |
|---|---|---|
| Bottom-up | Layer 1 | A new setup, a total outage, or when you suspect hardware or cabling |
| Top-down | Layer 7 | One application fails and others work, so the lower layers are likely fine |
| Divide and conquer | Layer 3 or 4 | You have a hunch and want to split the stack in half with one test, such as `ping` |
Divide and conquer is the fastest in practice. If ping to the destination IP works, Layers 1 to 3 are fine for that path, and you move up. If it fails, you move down.
A bottom-up command sequence
The following commands test one layer each on Linux. Run them in order and stop at the first one that fails.
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?The sections below explain what a pass and a failure mean at each step.
Layers 1 and 2: link and frames
ip link show lists each interface and its state. Look for state UP and the flag LOWER_UP, which means the interface detects a carrier signal. If the state is DOWN, the interface is disabled. If the flags show NO-CARRIER, the interface is enabled but sees no signal.
Typical causes:
- A loose or damaged cable, or a dead switch port (Layer 1).
- Wi-Fi that is switched off or not associated with an access point (Layers 1 and 2).
- A speed or duplex mismatch. The link comes up but shows many errors and poor throughput. Check
ip -s link showfor theerrors,dropped, andoverruncounters. - A wrong VLAN on the switch port. The link is up, but the host cannot reach its gateway, because the frames land in a different broadcast domain.
To check that Layer 2 reaches the gateway, look at the neighbor table:
ip neigh showAn entry marked REACHABLE or STALE means the host has resolved a MAC address for that neighbor. An entry marked FAILED or INCOMPLETE means ARP requests got no reply. That points to a Layer 2 problem, even though the symptom looks like a Layer 3 failure.
Layer 3: addressing and reachability
ip addr show should list an IPv4 or IPv6 address on the interface. Watch for these patterns:
- No address at all means DHCP failed or no static address is set.
- An address starting with
169.254.is a link-local fallback. The host asked for DHCP, got no answer, and assigned itself an address. Treat this as a DHCP failure. - An address in the wrong subnet, or with the wrong prefix length, makes the host treat remote hosts as local and send ARP requests for them.
Then check the routing table:
ip route showYou need a default via <gateway> line for traffic that leaves the local subnet. If it is missing, only local hosts are reachable.
Next, test in widening circles:
- Ping the host's own address. This tests the local IP stack.
- Ping the default gateway. This tests the local link and the gateway.
- Ping a remote IP address, such as a public DNS server. This tests routing beyond the gateway.
- Ping a hostname. This tests DNS name resolution as well.
If step 3 works and step 4 fails, the network path is fine and DNS is the problem. DNS is an application-layer service, so this is a good example of a symptom that looks like a network outage but belongs to Layer 7.
To see where a path breaks, use traceroute (or tracepath):
traceroute -n example.comThe last hop that answers marks the area to investigate. Rows of * * * can mean a real failure, but they can also mean a router that does not answer probes. If later hops answer, the stars are harmless.
Layer 4: ports and connections
nc -zv example.com 443 tries to open a TCP connection and reports the result. The three outcomes mean different things:
| Result | What the client sees | Likely meaning |
|---|---|---|
| Connection succeeds | `succeeded` | The port is open and a service accepts connections |
| Connection refused | `Connection refused` | The host answered with a TCP reset. No service listens on that port, or the host rejects it |
| Timeout | No answer until the timeout | A firewall silently drops the packets, the route is broken, or the host is down |
The difference between refused and timeout is one of the most useful clues at this layer. A refusal is a fast answer from a reachable host. A timeout means the packets never got a reply.
On the server side, check that the service is listening:
ss -tlnpThis lists TCP sockets in the listening state with their numeric ports and owning processes. A service bound to 127.0.0.1:8080 accepts only local connections. A service bound to 0.0.0.0:8080 or [::]:8080 accepts connections on all addresses. A common error is a service that listens only on the loopback address and then cannot be reached from another machine.
For UDP services, nc -zvu is unreliable, because UDP has no handshake and a silent port looks the same as an open one. Test UDP services with the actual application, such as a DNS query.
Layers 5 to 7: session, encryption, and application
curl -I https://example.com fetches only the response headers. It exercises DNS, TCP, TLS, and HTTP in one step, so use it after the lower tests pass. For more detail, add -v:
curl -v https://example.com -o /dev/nullThe verbose output shows each stage in order. Read it as a layer report:
Trying 93.184.216.34:443...means DNS resolved and a TCP connection is starting.Connected tomeans Layer 4 succeeded.- Lines starting with
TLSv1.3and the certificate details show the TLS handshake, which belongs to Layer 6 in the OSI view. HTTP/2 200orHTTP/1.1 200 OKshows that the application answered.
Typical failures at this point:
- Certificate errors, such as an expired certificate, a name that does not match the host, or an untrusted issuer. The TCP connection works, but the TLS handshake fails.
- An HTTP status of 4xx or 5xx. The network path is healthy and the application is returning an error. This is not a network fault.
- A redirect loop or a wrong virtual host, which are configuration problems on the server.
Seeing the same layers in code
You can also test layers from a script. The first example parses an Ethernet II header, which shows what Layer 2 carries.
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 the EtherType 0x0806 marks an ARP payload. This is the kind of frame a host sends when ip neigh show shows an INCOMPLETE entry: a broadcast asking who owns an IP address.
The second example opens a TCP connection and sends a plain HTTP request. A failure raises a different exception depending on the layer that broke.
import socket
request = b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n"
with socket.create_connection(("example.com", 80), timeout=5) as s:
s.sendall(request)
data = s.recv(200)
print(data.decode("ascii", errors="replace").splitlines()[0])Map the exceptions to layers when this script fails:
socket.gaierrormeans the name lookup failed. Look at DNS and Layer 7.TimeoutErrormeans no reply arrived. Look at routing and firewalls.ConnectionRefusedErrormeans a host answered with a reset. Look at the service and its port.
If the script prints a status line such as HTTP/1.1 200 OK, every layer from 1 to 7 worked for that request.
Symptom to layer cheat sheet
Use this table as a starting point, not as a verdict. Each row lists the layer where the cause is most often found.
| Symptom | Most likely layer | First check |
|---|---|---|
| No link light, `NO-CARRIER` | 1 | Cable, port, power |
| Link up, many errors or poor speed | 1 or 2 | `ip -s link show`, duplex, cable quality |
| `169.254.x.x` address | 3 (DHCP, an application service) | DHCP server, VLAN |
| Can reach local hosts, not remote ones | 3 | `ip route show`, gateway |
| `ping` by IP works, by name fails | 7 (DNS) | `/etc/resolv.conf`, resolver |
| Connection refused | 4 or 7 | `ss -tlnp` on the server |
| Connection timeout | 3 or 4 | Firewall rules, routing |
| Certificate warning | 6 | Certificate dates, name, chain |
| HTTP 500 error | 7 | Application logs |
Common mistakes
- Skipping layers. Restarting a web server because pages fail to load wastes time if the cable is unplugged.
- Trusting one test. A passing
pingdoes not prove that TCP port 443 is open, and a failingpingdoes not prove that the host is down. - Ignoring direction. A firewall can allow outgoing traffic and block replies. Test from both ends when you can.
- Treating the model as exact. Real protocols do not always fit one layer. ARP sits between Layers 2 and 3, and TLS spans Layers 5 and 6 in practice. Use the layers to organize your thinking, and do not argue over which number a protocol belongs to.
- Forgetting that DNS comes first. Most application tests begin with a name lookup. A DNS failure can look like a dead server.
Exercises
Exercise
A user reports that a web app is unreachable. ip link show reports state UP, ip addr show shows a valid address, and ping -c 4 203.0.113.10 (the server's IP) succeeds. nc -zv 203.0.113.10 443 prints Connection refused. At which layer do you look next, and what command do you run on the server?
Show answer
Look at Layer 4, and at the service behind it. The refusal is a fast reply from a reachable host, so routing and the link are fine. Run ss -tlnp on the server to check whether any process listens on port 443, and whether it is bound to a reachable address instead of only 127.0.0.1.
Exercise
ping 8.8.8.8 works, but ping example.com fails with a name resolution error. Which layer is the problem in, and why is it not a routing fault?
Show answer
The problem is in DNS, an application-layer (Layer 7) service. Packets reach a remote IP address, so the link, addressing, and routing all work. Only the step that converts the name to an address fails, so check the resolver settings, such as /etc/resolv.conf.
Exercise
nc -zv host 443 times out, while nc -zv host 22 succeeds quickly. What does this suggest, and why is a routing fault unlikely?
Show answer
The host is reachable, because port 22 answers, so routing is fine. A timeout on only port 443 suggests that a firewall silently drops packets to that port. If the service were not running, the host would reply with a refusal instead of a timeout.