Sub topic 13
Using Layers to Narrow Down Network Problems
Prerequisites and goal
This chapter assumes you have read the earlier chapters on the TCP/IP and OSI models, encapsulation, and the per-layer protocols. You should know what a frame, packet, segment, and datagram are. You should also be comfortable running ping, curl, and dig in a terminal.
The goal is a repeatable method. You will take a vague report such as "the site is down" and turn it into a statement such as "DNS resolves, TCP connects, but the TLS handshake fails certificate validation." That statement tells you who to call and what to fix.
Why layers help with faults
Each layer depends only on the layer below it. If a layer works, everything beneath it must be working well enough to support it. A successful TCP connection proves that the link, IP routing, and the TCP handshake all worked. A failure at one layer usually hides everything above it.
This gives you a way to search. You do not need to guess. You pick a layer, run one test, and learn which half of the stack contains the fault.
There are three common strategies:
- Bottom-up. Start at the link layer and move up. This suits a new installation or a machine that "has no network at all."
- Top-down. Start with the failing application and move down. This suits a single broken service when other traffic works.
- Divide and conquer. Start in the middle, usually with
pingor a TCP connection test, and move up or down depending on the result. This is fastest when you have no other clue.
What a failure looks like at each layer
The table uses the TCP/IP four-layer model, with the OSI layers each one covers in parentheses.
| Layer | Typical failure | Typical symptom | First test |
|---|---|---|---|
| Link (OSI 1–2) | Cable unplugged, wrong VLAN, no Wi-Fi association, ARP unanswered | Interface down, no carrier, "Destination Host Unreachable" from your own subnet | `ip link`, `ip neigh` |
| Internet (OSI 3) | No default route, wrong subnet mask, firewall dropping ICMP, routing loop | "Network is unreachable", timeouts beyond your subnet, TTL exceeded | `ip route`, `ping`, `traceroute` |
| Transport (OSI 4) | Port closed, firewall dropping SYN, service not listening | "Connection refused" or a connect timeout | `nc -zv`, `ss -ltn` |
| Application (OSI 5–7) | Bad DNS answer, expired certificate, HTTP 5xx, wrong virtual host | Name not found, certificate errors, error status codes | `dig`, `curl -v`, `openssl s_client` |
Notice that DNS sits in the application layer. A name lookup failure is an application-layer problem even though it makes everything look "down."
A decision flow
The flow below follows a bottom-up check for a client that cannot reach a web server. Each question is a test you can run in seconds.
Commands for each layer
These commands are Linux examples. Replace 192.0.2.10 and example.com with your own targets.
# Link layer: is the interface up, and does the gateway have a MAC address?
ip link show
ip neigh show
# Internet layer: address, route, reachability, path
ip addr show
ip route show default
ping -c 3 192.0.2.10
traceroute -n 192.0.2.10
# Transport layer: can we complete a TCP handshake to the port?
nc -zv 192.0.2.10 443
ss -ltn # on the server: is anything listening?
# Application layer: DNS, TLS, HTTP
dig +short example.com
openssl s_client -connect example.com:443 -servername example.com </dev/null
curl -v https://example.com/In ip neigh, an entry marked FAILED or INCOMPLETE for your gateway means ARP got no reply. That points to the link layer even though you are looking at an IP address.
A script that tests the layers in order
Doing this by hand is useful, but a small script makes the order explicit. This Python program checks DNS, TCP, TLS, and HTTP, and reports the first step that fails. It uses only the standard library.
import socket
import ssl
import sys
def check(host, port=443):
# Application layer: DNS
try:
info = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
except socket.gaierror as exc:
print(f"DNS: FAIL ({exc})")
return
ip = info[0][4][0]
print(f"DNS: ok, {host} -> {ip}")
# Transport layer: TCP handshake
try:
sock = socket.create_connection((ip, port), timeout=5)
except ConnectionRefusedError:
print("TCP: FAIL, connection refused (host reachable, port closed)")
return
except (socket.timeout, TimeoutError):
print("TCP: FAIL, timed out (packets dropped or no route)")
return
except OSError as exc:
print(f"TCP: FAIL ({exc})")
return
print(f"TCP: ok, connected to {ip}:{port}")
# Application layer: TLS handshake
context = ssl.create_default_context()
try:
tls = context.wrap_socket(sock, server_hostname=host)
except ssl.SSLCertVerificationError as exc:
print(f"TLS: FAIL, certificate problem ({exc.verify_message})")
sock.close()
return
except (ssl.SSLError, OSError) as exc:
print(f"TLS: FAIL ({exc})")
sock.close()
return
print(f"TLS: ok, {tls.version()}")
# Application layer: HTTP
request = f"HEAD / HTTP/1.1\r\nHost: {host}\r\nConnection: close\r\n\r\n"
tls.settimeout(5)
try:
tls.sendall(request.encode("ascii"))
status = tls.recv(200).split(b"\r\n")[0].decode("ascii", "replace")
print(f"HTTP: {status}")
except OSError as exc:
print(f"HTTP: FAIL ({exc})")
finally:
tls.close()
if __name__ == "__main__":
check(sys.argv[1] if len(sys.argv) > 1 else "example.com")Run it with python3 check_layers.py example.com. The output stops at the first failing layer, which is the point of the method.
Reading the evidence
Refused versus timed out
These two TCP outcomes mean different things.
- Connection refused means a TCP reset came back. The packet reached a host, and that host (or a firewall acting for it) answered "nothing here." The link and internet layers work. Look at whether the service is running and listening on the right address and port.
- Timed out means nothing came back. A firewall may be silently dropping the SYN, a route may be missing, or the host may be off. You cannot tell which from the client alone.
Name works, IP does not, or the reverse
If ping 192.0.2.10 works but ping example.com fails with "unknown host," the fault is in DNS. If the name resolves but to the wrong address, as with a stale record or split-horizon DNS, everything below DNS will work and still send you to the wrong server. Compare the dig answer with what you expect.
Use a capture to settle arguments
When two people disagree about which layer is failing, capture the traffic. Filter on the suspect host and read the headers by layer.
sudo tcpdump -nn -e -c 20 host 192.0.2.10Look for these patterns:
- Repeated ARP requests with no reply point to the link layer.
- SYN packets with no SYN-ACK point to a drop on the path or at the server.
- A SYN followed by RST, ACK means the port is closed.
- A completed handshake followed by a TLS alert means a failure in the application layer.
Edge cases and traps
- MTU and fragmentation. Small packets pass and large ones vanish. A
pingworks, the TCP handshake works, and the TLS handshake or a large download hangs. The symptom appears at the application layer, but the cause is at the internet layer: a path MTU problem, often combined with filtered ICMP "fragmentation needed" messages. Test withping -M do -s 1472 192.0.2.10and lower the size until it succeeds. - Asymmetric routing. The request goes out one path and the reply returns on another that a stateful firewall rejects. The client sees timeouts, and the link and internet layers look healthy on both ends.
- IPv4 versus IPv6. A name may resolve to both families. A client that prefers IPv6 can stall on a broken IPv6 path while IPv4 works. Test each with
curl -4andcurl -6. - Layers that blur. ARP and ICMP do not fit a single layer neatly, and TLS spans several. Do not insist on a clean label. Use the layers to choose your next test, not to win a classification argument.
- Multiple faults. Fixing one layer can reveal another. Re-run the full sequence after each change.
Summary of the method
- Reproduce the failure and note the exact error message.
- Pick a strategy: bottom-up, top-down, or divide and conquer.
- Test one layer at a time with a command that exercises that layer specifically.
- Stop at the first failing layer and gather evidence there, using a capture if needed.
- Fix one thing, then repeat the full sequence.
Exercise
A user reports that https://intranet.example cannot be opened. From their machine, ping 192.0.2.50 (the server) succeeds, dig +short intranet.example returns 192.0.2.50, and nc -zv 192.0.2.50 443 reports "Connection refused." Which layer is the likely fault, and what do you check next?
Show answer
The transport layer, because DNS and IP reachability work and the TCP connection is actively refused. A reset came back, so the packet reached the host. Check on the server that the web service is running and listening on port 443 on the right address (ss -ltn), and that no local firewall rule sends a reset for that port.
Exercise
A TCP connection to port 443 succeeds, but the TLS handshake hangs for small test pages and works, while large pages never finish loading. Which layer's problem might this really be, and which test would confirm it?
Show answer
Probably the internet layer: a path MTU problem. Small packets get through and large ones are dropped, so the handshake that carries a large certificate chain stalls. Confirm it with ping -M do -s 1472 <server> and reduce the size until replies arrive, or look in a capture for large segments that are retransmitted with no acknowledgment.
Exercise
Why is "ping works" not enough to conclude that a web service is reachable?
Show answer
Ping uses ICMP at the internet layer, while the web service uses TCP at the transport layer and HTTP or TLS above it. A firewall can allow ICMP and block TCP port 443, or the service itself can be down. Ping proves only that some path exists for ICMP echo.