Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 15 min · revision 3

Layers as a debugging map, and what L4 and L7 mean

Deconstruct the TCP/IP network model into an operational debugging taxonomy, mapping connection timeouts, resets, and certificate errors to specific protocol layers.

Contentsand lesson path

What you will learn

  • Describe the TCP/IP layers and assign a given failure (name resolution, routing, closed port, TLS, HTTP error) to the layer it belongs to.

01. The TCP/IP Layer Model as an Operational Triage Map

When a service or a user reports that an API is unreachable, it is tempting to guess: restart the backend containers, blame DNS or edit firewall rules without evidence. A faster habit is to use the layers of the network stack as an ordered checklist and test one layer at a time.

The OSI model has seven layers, but the Internet runs on the simpler four-layer TCP/IP model. Engineers still use the OSI numbers as names (L2, L3, L4, L7), so this lesson does too:

  • Layer 2 (Data Link / Ethernet): Governs frame transmission across physical wires, Wi-Fi radio frequencies, or virtual software bridges (such as Docker docker0 or Linux bridge interfaces). Addressing is handled via 48-bit MAC addresses, resolved dynamically from local IP addresses using the Address Resolution Protocol (ARP). Ethernet frames encapsulate IP packets, adding a source and destination MAC header and a Frame Check Sequence (FCS) checksum to detect frames damaged on the way.
  • Layer 3 (Network / Internet Protocol): Governs logical packet routing across disjoint network boundaries using IPv4 (32-bit) or IPv6 (128-bit) addresses. Routers make forwarding decisions based on destination IP addresses and kernel routing tables without inspecting packet payload contents. Crucially, Layer 3 protocols like ICMP (Internet Control Message Protocol, used by ping) operate directly on top of IP without utilizing transport port numbers. Consequently, a successful ping test confirms Layer 3 routing reachability but reveals nothing about whether an application is listening on a specific TCP or UDP port.
  • Layer 4 (Transport / TCP and UDP): Governs host-to-host process multiplexing and reliability using 16-bit port numbers (0 to 65535). Transmission Control Protocol (TCP) provides sequenced, connection-oriented, flow-controlled byte streams via a three-way handshake (SYN, SYN-ACK, ACK), while User Datagram Protocol (UDP) offers connectionless, low-overhead datagram transmission for real-time video, DNS, and QUIC. Packets are still lost on the way; TCP sequence numbers, acknowledgements and retransmission timers detect the lost segments and resend them, so the application receives a complete, in-order byte stream (at the cost of extra latency) or the connection eventually fails.
  • Layer 7 (Application): Governs application payload semantics, including HTTP/1.1, HTTP/2, HTTP/3, DNS query-response formatting, and Transport Layer Security (TLS) cryptographic handshakes.

Every network error message emitted by standard CLI utilities (curl, ping, ssh) usually points to a specific layer in the protocol stack:

  1. Could not resolve host: api.example.com -> Layer 7 (DNS): The local resolver failed to translate the hostname into an IP address. No TCP connection was ever attempted.
  2. Network is unreachable -> Layer 3 (local routing): The local kernel has no route to the destination, often a missing default gateway. Check with ip route get <ip>.
  3. No route to host -> Layer 2/3 (next hop or a reject): Despite the name, a route usually exists. On Linux this error means the target or the gateway did not answer ARP (the host is down or the address is wrong), or a router or firewall answered with an ICMP host-unreachable or host-prohibited message; firewalld, for example, rejects this way by default. Check ip neigh, the target host and its firewall, not just the routing table.
  4. Connection timed out -> Layer 4 (TCP / Firewall): SYN packets were transmitted onto the wire, but no reply was received within the kernel timeout window. This typically signals a stateful security group or firewall silently dropping packets (DROP).
  5. Connection refused -> Layer 4 (TCP Reset): The destination IP was reached, but the remote kernel immediately returned a TCP RST because no process was listening on that port, or a firewall rule rejected the connection (REJECT sends an ICMP port-unreachable or a TCP RST, and both show up as Connection refused).
  6. SSL certificate problem: certificate has expired -> Layer 7 (TLS Handshake): DNS, routing, and TCP connection establishment all succeeded completely; failure occurred during cryptographic certificate validation prior to sending HTTP application requests.
  7. HTTP/1.1 502 Bad Gateway -> Layer 7 (HTTP Gateway): DNS, TCP, TLS, and client HTTP transmission to the load balancer were completely successful; the load balancer itself received a connection failure from its configured upstream application server.

02. Architectural Comparison: Layer 4 vs. Layer 7 Proxying

In cloud infrastructure, load balancers and reverse proxies operate at either Layer 4 or Layer 7, each presenting distinct performance, visibility, and operational trade-offs:

  • Layer 4 Load Balancers (Transport Level): Examples include AWS Network Load Balancer (NLB), HAProxy in TCP mode, and Linux IPVS. A Layer 4 proxy routes raw TCP/UDP byte streams based strictly on IP tuples (source_ip, source_port, dest_ip, dest_port). It does not parse HTTP headers, paths or cookies. Some Layer 4 balancers can terminate TLS (an NLB TLS listener, for example), but they still forward an opaque byte stream without reading the HTTP inside. Because it does not parse or buffer HTTP requests, a Layer 4 balancer adds little latency and uses little CPU and memory per connection, so the same hardware carries more traffic than it would as a Layer 7 proxy.
  • Layer 7 Reverse Proxies (Application Level): Examples include AWS Application Load Balancer (ALB), Nginx, Envoy, and Traefik. A Layer 7 proxy terminates the client TCP connection, performs cryptographic TLS handshakes, parses the full HTTP request header, and evaluates URL paths (/api vs /static), host headers (tenant1.example.com), and authorization tokens before dispatching the request to upstream pods. Layer 7 proxies make content-based routing (for example, canary releases by header) and header rewriting possible, at the cost of more CPU for TLS termination and parsing, and more memory for buffering requests.
Bash · Demonstrating L4 socket probe vs L7 HTTP protocol inspection
# Layer 4 TCP connection probe using netcat (tests port reachability)
nc -zv 127.0.0.1 8000

# Layer 7 HTTP probe: show the connection, request and response headers.
# Plain http:// because a local dev server on 8000 usually has no TLS; an
# https:// URL here fails with "SSL routines::wrong version number".
curl -sS -v -o /dev/null http://127.0.0.1:8000/api/health

03. Check your understanding

Practice check · 3 questions

TCP/IP layers, failure categorization, and proxy architecture check

Three questions on reading connection errors and on L4 versus L7.

Q1. On the same host, `curl http://10.2.4.15:9090` ends in `Connection timed out`, while port 9091 fails at once with `Connection refused`. What best explains the difference?
Q2. Three backends sit behind a Layer 4 load balancer that health-checks each one by opening a TCP connection to port 8080. One backend has run out of database connections and answers every request with HTTP 500, yet it stays in rotation. Why?
Q3. `curl http://10.0.5.20/` fails with `No route to host`, yet `ip route get 10.0.5.20` shows a valid on-link route. Where do you look next?
Practice only: not graded, not saved, not evidence.

04. Apply it

Incorporate these diagnostic rules when troubleshooting distributed microservices:

  • Triage Bottom-Up: When an endpoint fails, isolate layers in strict order. Start with DNS resolution (dig +short host.domain) even though DNS is a Layer 7 protocol: every later test needs the IP address it returns, and if the lookup fails, no packet was ever sent to the server, so there is nothing lower to test yet. Then check Layer 3 routing (ip route get <ip>), Layer 4 port connectivity (nc -zv <ip> <port>), and Layer 7 protocol response (curl -sv -o /dev/null https://<host>/path for a TLS service; avoid -I for a health check, since it sends HEAD, which some frameworks answer with 405 Method Not Allowed).
  • Differentiate Drop vs Reject: When crafting security rules, understand that DROP causes client connections to hang until timeout (wasting client threads), whereas REJECT immediately returns an error packet (ICMP port-unreachable by default in iptables, or a TCP RST with --reject-with tcp-reset), so clients fail fast with Connection refused.
  • Choose Proxy Tier Wisely: Deploy Layer 4 NLBs for high-throughput database traffic (PostgreSQL, Redis, Kafka) and Layer 7 ALBs for web applications requiring header routing, TLS offloading, and WAF inspection.
  • Never Rely Solely on Ping: Remember that ICMP echoes can succeed while application ports are completely blocked, and firewalls can drop ICMP while allowing HTTP traffic without issue.

05. Review prompt

Explain how the four TCP/IP layers establish an operational debugging framework. Differentiate between Connection refused and Connection timed out in terms of packet mechanics. Detail the architectural differences between Layer 4 and Layer 7 proxies regarding TLS termination and request routing.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check