Estimated time: 40 minutes.
OSI 7 layers vs TCP/IP 4 layers
Layer: Comparison
Why: OSI (ISO/IEC 7498-1) defines a 7-layer reference model: Physical → Data Link → Network → Transport → Session → Presentation → Application.
TCP/IP (RFC 1122 §1.1.3) collapses this into 4 layers of real implementation: Link (OSI L1+L2) → Internet (L3) → Transport (L4) → Application (OSI L5+L6+L7).
The difference is not "dropping 3 layers" but the wire format: TCP/IP has no separate header for Session (L5) and Presentation (L6).
The L5 function (session control) is done by the app itself through cookies/JWT/WebSocket.
The L6 functions (encoding, compression) are handled by TLS (RFC 8446) and Content-Encoding (RFC 9110 §8.4) inside L7.
OSI came out as an ISO standard (1984), after ARPANET had already deployed TCP/IP (1983), which made TCP/IP the de-facto stack in implementation; OSI kept its role as a reference/pedagogy tool in docs and vendor terminology.
Understanding this mapping matters when you read "L7 firewall" (AWS WAF), "L4 load balancer" (AWS NLB), "L3 routing" (iptables) — vendors use OSI numbering.
Get it wrong → you map features incorrectly when comparing services.
When it breaks: Mixing up the layers of the two models causes misreading of documentation. When a vendor says 'Layer 7 firewall' (OSI) they mean the Application layer.
But TCP/IP calls Application L4. Reading Cisco/AWS docs without knowing they use OSI will make you map the wrong layer when debugging.
In real deployments: Mapping: OSI L1-2 → TCP/IP Link | OSI L3 → TCP/IP Internet | OSI L4 → TCP/IP Transport | OSI L5-7 → TCP/IP Application.
OSI came out as an ISO standard, while TCP/IP grew out of the experimental ARPANET. TCP/IP won because it was already in production before OSI was finished.
Application
Layer: L4
PDU: Message
Devices: Process (nginx, curl, ping...)
Protocols: HTTP, DNS, SSH, TLS, FTP
Why: The Application layer (RFC 1122 §4) is where a userspace process "speaks" through the socket API — an HTTP request, a DNS query, an SSH command.
Input: a byte stream from Transport (TCP) or a datagram (UDP).
Output: a semantic message in a specific protocol (HTTP/1.1 text, HTTP/2 binary frames, DNS binary — RFC 1035 §4).
What this layer hides from the dev: nothing else — everything below L4 is already abstracted by the socket API.
The app does not know about packet loss, reordering or fragmentation; the TCP stack has handled them.
Errors at this layer are semantic: 400 (client sent a bad format), 500 (server logic error), 502 (upstream did not respond correctly) — not network errors.
The takeaway: when curl reports 502, it is not "the network is broken" — it is the nginx upstream (another app) failing. Check journalctl -u nginx, docker logs, do not restart the router.
When it breaks: Mistaking an Application error for a network error → debugging in the wrong direction for hours.
A 502 Bad Gateway is an Application layer failure, not a problem with the network cable. Without understanding this layer, you restart the server pointlessly instead of checking the nginx/app log.
In real deployments: Once a VPS deploy is done, check the application log first: journalctl -u nginx, docker logs <container>.
A 502/503 error is always Application or Transport, not Link/Internet.
Transport
Layer: L3
PDU: Segment / Datagram
Devices: OS kernel
Protocols: TCP, UDP
Why: The Transport layer (RFC 1122 §4) receives an IP packet from the Internet layer and demuxes it to a socket based on the 4-tuple (srcIP,
srcPort, dstIP, dstPort) — RFC 793 §2.7.
The 16-bit PORT is the only mechanism that lets one host run several processes on the same local IP; without ports, one IP could run only 1 service.
TCP (RFC 9293) adds 3 guarantees that IP lacks: ordering (sequence numbers + a reorder buffer),
slow start, AIMD).
UDP (RFC 768) drops all of that — it keeps only port demux + a 16-bit checksum, with 0 ms of buffering latency.
Transport hides packet loss/reordering from the L4 Application — nginx does not write retransmission code, the kernel TCP stack does.
Understanding this → when curl times out: use tcpdump to see whether the TCP handshake fails at the SYN (a firewall blocks it), at the SYN-ACK (the server does not reply), or the application never calls accept().
When it breaks: If you do not understand the Transport layer, then when a port is blocked you will not know why curl fails even though ping is OK.
Installing nginx but forgetting to open port 80/443 in the firewall = Transport is blocked = all HTTP traffic is dead.
In real deployments: After starting nginx on a VPS, always check: ss -tlnp | grep 80 (is the service listening?) and nc -vz <ip> 80 from the client machine (is the port open from outside?).
These two steps confirm the Transport layer is OK.
Internet
Layer: L2
PDU: Packet
Devices: Router
Protocols: IP, ICMP
Why: The Internet layer (RFC1122§3) receives a segment from Transport and encapsulates it into an IP packet with a 20-byte header
(RFC791§3.1):
Source IP, Destination IP, TTL, Protocol number (6=TCP, 17=UDP, 1=ICMP).
It hands it to the L1 Link to be forwarded through routers based on the Destination IP + the routing table.
This layer hides the network topology from Transport: L4 does not know how many routers the packet passes through, or whether it crosses a WAN/LAN/VPN.
TTL (RFC 791 §3.2) drops by 1 at every router — preventing endless loops, and it is the mechanism traceroute exploits to see each hop.
The routing layer (BGP on the internet, OSPF inside an AS) is not part of the IP spec — it is a separate control plane.
The Internet layer is where "internetworking" happens — the name "Internet" = inter-network. The takeaway: when "I can't get online", check in this order — ip route (is there a default route?)
→ ping 8.8.8.8 (is L3 OK?) → ping google.com (is DNS OK?). If you can ping the IP but not the domain, it is an L7 DNS failure, not L3.
When it breaks: A wrong routing table or a wrong default gateway → packets cannot reach the internet even though WiFi shows 'connected'.
Many cases of 'the network won't load' are really a dead default gateway or a wrong routing table — not the network cable.
In real deployments: When a VPS cannot reach the internet: ip route (is there a default route yet?), ping 8.8.8.8 (is the Internet layer OK?), ping 8.8.4.4 (does not depend on DNS).
If you can ping the IP but not the domain = DNS failure, not the Internet layer.
Link
Layer: L1
PDU: Frame / Bits
Devices: NIC, switch, cable, WiFi
Protocols: Ethernet, WiFi 802.11
Why: The Link layer (RFC 1122 §2) combines OSI L1 Physical + L2 Data Link. Input: an IP packet from the Internet layer.
Output: a bit stream out of the NIC according to the physical standard (IEEE 802.3 Ethernet, IEEE 802.11 WiFi).
It encapsulates into a frame with destination MAC + source MAC + FCS (frame check sequence) before transmitting. This layer uses the MAC address (48-bit, IEEE 802) — the NIC's unique hardware address.
ARP (RFC 826) resolves IP → MAC within the same broadcast domain: the host broadcasts "Who has 192.168.1.1?", and the gateway replies with its MAC.
Note: a frame sent to a remote server uses the MAC of the next-hop gateway, not the server's MAC (the server is in a different domain and cannot be reached directly at L2).
The Link layer hides the physical medium from Internet — IP does not know whether it is running over copper Ethernet, fiber, WiFi or 5G. A cut cable/lost WiFi signal → no layer above can forward.
On a cloud VM, the hypervisor + virtual switch manage this layer — the NIC driver, an MTU mismatch (for example AWS Jumbo Frames 9001 vs standard 1500), or an AWS security group (iptables-like, acting at L3/L4) can still fail.
The error surface is usually Network Unreachable (EHOSTUNREACH) or No route to host.
When it breaks: Link fails = everything above is meaningless.
On a cloud VPS, Link is usually managed by the provider but can still fail because of the NIC driver, an MTU mismatch, or a cloud security group blocking at L2.
In real deployments: ip link show — see whether the interface is UP. If the state is DOWN then Link is dead.
On AWS/GCP, a security group rule blocks here — but the error looks like Network Unreachable, not Connection Refused.
The socket API receives a char* "example.com" through getaddrinfo() — the libc resolver reads /etc/nsswitch.conf, queries the DNS server (usually UDP :53,
falling back to TCP :53 for responses >512 bytes — RFC 1035 §4.2.1), and parses the A record (IPv4) or AAAA (IPv6).
The recursive mechanism: the stub resolver asks the local DNS (ISP/router), the local DNS asks the root (13 root servers, RFC 7720),
the root returns the TLD (.com), the TLD returns the authoritative server (example.com's NS), and the authoritative server returns the A record.
The result is cached according to the record's TTL.
Response codes classify errors (RFC 1035 §4.1.1): NXDOMAIN (rcode=3, the name does not exist), SERVFAIL (rcode=2, the authoritative server failed), timeout (the resolver cannot be reached).
DNS is not part of the packet journey of ping/curl once the resolve is done — but it is a mandatory step 0. Could not resolve host is ALWAYS a DNS failure, not the network.
If dig example.com fails from the VPS → /etc/resolv.conf is wrong or a firewall blocks UDP :53.
When it breaks: Skipping the DNS lookup when debugging → you do not notice the DNS failure and assume it is a network error. 'Could not resolve host' is ALWAYS a DNS problem, not a cut cable.
If you can ping the IP directly but pinging the domain fails = DNS is dead.
# Query DNS manually
dig example.com +short
# Or the older way
nslookup example.com
Observe with:
dig example.com +short — see the returned IP and the query time. If you only see SERVFAIL or no IP is returned, the DNS resolver has a problem. Try dig example.com @8.8.8.8 to bypass the ISP's resolver.
Symptoms when it breaks:
curl/ping reports 'could not resolve host example.com': dig example.com returns: ;; connection timed out; no servers could be reached or status: SERVFAIL
A DNS query returns the wrong IP (poisoned/stale cache): dig example.com +short returns an IP that does not match dig example.com @8.8.8.8 +short
Fix:
Check which DNS resolver is in use
cat /etc/resolv.conf
Bypass the ISP resolver and query 8.8.8.8 directly
dig example.com @8.8.8.8 +short
If the resolver is systemd-resolved, check its status
systemd-resolve --status | grep 'DNS Servers'
The ping command is a userspace process that calls the syscall socket(AF_INET, SOCK_RAW, IPPROTO_ICMP) — unlike a TCP socket (SOCK_STREAM) or a UDP socket (SOCK_DGRAM).
ICMP (RFC 792) is protocol number 1, sitting directly on IP — there is no concept of a port.
The kernel creates an ICMP echo request (type=8, code=0) with an identifier + sequence number to match the reply; the payload is usually a timestamp + pattern bytes (default 56 bytes of data + 8 bytes of ICMP header = 64 bytes).
It is sent down to the Internet layer. On Linux, a non-root user needs CAP_NET_RAW or the sysctl net.ipv4.ping_group_range to run ping. ICMP is at L3 (the Internet layer), not L4 (Transport).
CLIs/UIs often group ping next to nc/curl — that is a tooling convention and does not reflect its position in the stack.
The consequence: a passing ping does not imply a passing TCP :80 — a firewall may allow ICMP and block TCP (or vice versa).
When it breaks: Thinking ping tests the entire stack → skipping the TCP port test after a deploy. ICMP ping and TCP 80/443 are 2 different things.
Firewalls often block ICMP while allowing TCP, or the reverse.
# Ping 4 packets then stop (Linux/Mac)
ping -c 4 example.com
# Windows
ping -n 4 example.com
Observe with:
ping -c 4 example.com — look at time= (RTT) and packet loss %. If loss is 0% and time is <100ms, the Internet layer is completely fine. If time is >500ms, there is a routing problem or the server is overloaded.
The kernel wraps a 20-byte IP header (RFC 791 §3.1) around the ICMP payload.
The important fields: Source IP (the outbound address of the interface chosen by the routing table), Destination IP (93.184.216.34 from DNS), Protocol=1 (ICMP), TTL=64 (the Linux default,
RFC 1122 §3.2.1.7 recommends 64), Header Checksum (RFC 1071).
TTL drops by 1 at every router (RFC 791 §3.2) — when TTL=0, the router drops the packet and sends an ICMP Time Exceeded (type=11) back to the sender.
This is the principle traceroute exploits: send packets with TTL=1, 2, 3... to receive Time Exceeded from each hop.
A packet is fragmented if its size > the path MTU (RFC 791 §3.2);
the Linux kernel enables Path MTU Discovery by default (sysctl net.ipv4.ip_no_pmtu_disc=0, RFC 1191) to set the DF bit and avoid fragmentation.
Understanding the IP header → you know how to debug: trace the Source IP being changed by NAT when it passes through a public router (the router replaces the Source IP with its own public IP, so the server sees the NAT box's IP, not the client's private IP).
Misunderstanding private IPs (RFC 1918: 10/8, 172.16/12, 192.168/16) vs public → wrongly configured firewalls.
When it breaks: Not knowing your machine's IP = not knowing the Source IP in the packet = you cannot debug 'why does the server refuse the connection'.
NAT changes the Source IP → the server sees an IP different from the client's. Confusing private and public IPs leads to wrong firewall configuration.
# See the machine's IP
ip addr show # Linux
ifconfig # Mac
ipconfig # Windows
# See the routing table — where will the machine send packets?
ip route # Linux
netstat -rn # Mac
route print # Windows
Observe with:
ip route get 8.8.8.8 — see which interface and gateway Linux picks to send a packet to 8.8.8.8. The output 'via X.X.X.X dev ethY src Z.Z.Z.Z' tells you the gateway, the NIC, and the source IP for this connection.
The kernel consults the routing table (ip route) to decide the next hop: the server 93.184.216.34 is not on the LAN → send via the default gateway (for example 192.168.1.1).
It needs the gateway's MAC to build the Ethernet frame. The kernel checks the ARP cache (ip neigh) — on a miss, it triggers an ARP request.
ARP (RFC 826): the host broadcasts an L2 frame (destination MAC = FF:FF:FF:FF:FF:FF) with the query "Who has 192.168.1.1? Tell 192.168.1.10".
Every host in the broadcast domain receives it, and only the gateway (192.168.1.1) replies with an ARP response carrying its MAC.
The kernel caches the (IP, MAC) pair in the ARP table for ~30s-1h depending on the OS, then refreshes it.
The Ethernet frame (IEEE 802.3): destination MAC = the gateway's MAC, source MAC = the NIC's MAC, EtherType = 0x0800 (IPv4), payload = the whole IP packet, and the FCS (CRC-32) at the end of the frame.
The destination MAC is ALWAYS the next hop's MAC, not the final server's MAC — confusing this leads to misreading packet captures in Wireshark.
ARP poisoning is an attack class inside a LAN: the attacker sends a fake ARP reply claiming their own MAC for the gateway's IP → hosts send traffic to the attacker's MAC = MITM (CAPEC-141 ARP Spoofing).
When it breaks: ARP poisoning is a common attack inside a LAN: the attacker sends a fake ARP reply → the host sends traffic to the attacker's MAC instead of the gateway → MITM.
In a cloud environment, ARP between VMs is usually managed by the cloud platform — you need to know this when debugging.
# See the ARP cache (IP ↔ MAC pairs known on the LAN)
ip neigh show # Linux
arp -a # Mac/Windows
# See the machine's MAC
ip link show
ifconfig | grep ether
Observe with:
ip neigh show — see the ARP table. If you see the gateway IP in the REACHABLE state, the Link layer to the gateway is OK. FAILED or INCOMPLETE = ARP cannot resolve = the Link layer has a problem.
A router receives the frame → checks the destination MAC (is it the router's own) → decapsulates Ethernet (strips the L2 header + FCS) → takes the IP packet → checks the destination IP → looks it up in the routing table (longest prefix match,
The route entry points to an outgoing interface + a next-hop IP. The router decrements TTL by 1 and recomputes the IP header checksum (RFC 1071).
The router resolves the next hop's MAC via ARP (if not cached) and builds a NEW Ethernet frame with destination MAC = the next hop's MAC and source MAC = the outgoing interface's MAC.
It sends it out the NIC. This repeats at every router on the path to the server's network — the hop count can be verified directly with traceroute or mtr from a specific client.
The key point: the IP header does not change across routers (except TTL + checksum), while the Ethernet header is RE-CREATED at every hop — because a MAC only has meaning within 1 broadcast domain.
Understanding this → traceroute displays IPs (L3) not MACs (L2), and ping -r (record route option) displays the routers' IPs, not MACs.
When it breaks: Not knowing traceroute → when debugging 'why is latency high' or 'where are packets dropped' you can only look without finding the bottleneck.
Traceroute reveals exactly which router is slow or dropping packets.
# See the real path, hop by hop
traceroute example.com # Linux/Mac
tracert example.com # Windows
# If traceroute stops halfway = a router on the path blocks ICMP/UDP
sudo traceroute -T -p 443 example.com
Observe with:
traceroute -n example.com (-n does not resolve hostnames, faster) — see the latency of each hop. If one hop suddenly jumps from 10ms to 200ms = the bottleneck is there. * * * = the router blocks ICMP, which does not mean it is down.
The server example.com receives the frame → checks the destination MAC (is it the server NIC's own) → decapsulates Ethernet → reads the IP header → checks the destination IP (is it the server's own) →
reads the Protocol field = 1 (ICMP) → passes it up to the ICMP handler in the kernel.
No userspace process is invoked.
The kernel ICMP handler (RFC 792 §Echo) receives the echo request (type=8),
creates an echo reply (type=0) with the identical identifier + sequence number + payload, swaps the source/destination IPs, and sends it down to the IP layer.
The reply goes back to the client through the server's routing table, and may take a DIFFERENT path from the outbound one (asymmetric routing).
A stateless firewall does not track the request↔reply pair → it drops the reply if the reply path goes through a different interface than the request path — you need a stateful firewall (conntrack in Linux netfilter) to handle it.
Because the kernel replies on its own and no app needs to be running, ping works even when nginx/ssh/mysql are all down, as long as the kernel is alive.
The debugging consequence: a successful ping only proves the host + kernel are OK, not the service. To verify the service, you must test L4 (nc -vz host port) and L7 (curl, a protocol command).
When it breaks: Not using tcpdump → you do not know whether the packet reaches the server → debugging blind.
When 'curl doesn't work', tcpdump on the server tells you immediately: does the packet arrive? Arrives with no reply = the process is dead. Does not arrive = a firewall blocks it before the server.
# On the server, watch incoming packets with tcpdump
sudo tcpdump -i any -n 'icmp'
# 2 lines of output per ping:
# IP <client> > <server>: ICMP echo request
# IP <server> > <client>: ICMP echo reply
Observe with:
sudo tcpdump -i any -n 'tcp port 80' — run it while the client does curl http://server. If you see a SYN arrive but no SYN-ACK, no process is listening. If you see no SYN at all = the packet has not arrived, blocked somewhere before.
Symptoms when it breaks:
tcpdump runs but shows no packets even though you know traffic is flowing: tcpdump -i eth0 captures nothing, but tcpdump -i any does — the interface is wrong.
Check: ip link show to see the correct interface name
sudo tcpdump reports 'eth0: No such device': ip link show does not list an interface named eth0 — the NIC may be named ens3, enp0s3, or another predictable name set by udev
Fix:
List the actual interfaces on the machine
ip link show
Use -i any to capture on every interface
sudo tcpdump -i any -n 'icmp' -c 10
Scripting it: Run it manually when debugging production traffic. -C 100 = rotate every 100MB, -W 5 = keep 5 files. Stop it with kill $PID.
Analyze later with: tcpdump -r /tmp/tcpdump-captures/capture.pcap0
#!/bin/bash
# Rotate the tcpdump capture by size — avoids filling the disk
# Use when you need a long-running capture (debugging production)
# Each file is at most 100MB, keeping the 5 most recent files
INTERFACE=${1:-any}
OUTDIR=${2:-/tmp/tcpdump-captures}
mkdir -p "$OUTDIR"
sudo tcpdump -i "$INTERFACE" -n \
-C 100 \
-W 5 \
-w "$OUTDIR/capture.pcap" \
&
echo "tcpdump PID=$! | captures in $OUTDIR | max 5x100MB"
The client kernel receives the ICMP echo reply, matches the identifier + sequence against the request it sent, and computes RTT = receive timestamp − send timestamp (the timestamp lives in the payload, embedded by the kernel when sending).
It updates the statistics (packets_received++) and passes the event up to the userspace ping process via recvmsg(). ping prints 64 bytes from 93.184.216.34: icmp_seq=1 ttl=54 time=12.3 ms.
The fields: 64 bytes = ICMP + payload (not counting the IP header), ttl=54 = the TTL remaining when it reached the client (if the server sent TTL=64 → it passed 10 hops), time=12.3 ms = the round-trip RTT.
The two most important metrics: packet loss % (after N packets, how many got no reply — 1-2% loss reduces TCP throughput because of retransmit window collapse,
RFC 5681 §3.1) and jitter (RTT variation — jitter > 30 ms causes audio/video codec buffer underrun in realtime apps: VoIP, video calls,
games).
Pinging an IP on the same LAN (<1 ms expected) verifies local L1-L3; pinging an IP in another AS (<200 ms intercontinental fiber) verifies the WAN path.
When it breaks: Not knowing how to read ping output → you ignore the important packet loss and jitter. 1-2% packet loss on TCP cuts speed sharply (TCP retransmission).
High jitter = instability, hurting video calls/realtime apps.
# Long-running ping to see jitter / packet loss
ping example.com
# Ping with a large size to test the MTU
ping -s 1472 example.com
Observe with:
ping -c 100 example.com — ping 100 packets to get accurate statistics. The end of the output has min/avg/max/mdev. A large mdev = high jitter = an unstable network. Packet loss > 0% = a serious problem.
This is a test case that ties the whole stack together: ping tests L3 (ICMP echo), while curl/a browser tests L3 + L4 + L7. A successful ping proves L1→L3 are OK and the server kernel can reply.
Curl needs more: L4 Transport (TCP, RFC 9293): a 3-way handshake to port 80/443 — SYN, SYN-ACK, ACK.
A firewall blocking the port → "connection timeout" (the SYN gets no SYN-ACK). The host is up but no process listens on the port → "connection refused" (the kernel replies with a TCP RST).
L7 Application (HTTP, RFC 9110): nginx/the app receives the TCP byte stream, parses the HTTP request, and returns a response.
An nginx upstream failure → 502; an app crash → 500; a badly formatted client request → 400.
Understanding this separation changes the debugging workflow completely: from "I can't reach the server" (vague) → "test each layer": ping (L3) → nc -vz host 443 (L4 + is the port open?)
→ curl -v (L7 + is the HTTP valid?). Knowing which layer fails tells you which tool to observe with (tcpdump for L3-L4, journalctl/the access log for L7).
When it breaks: Not knowing how to test each layer separately → when debugging you only know 'can't reach it' without knowing which layer the problem is at.
Worse, you may restart the whole system for nothing when all you needed was to open a firewall port.
# Test the Transport layer on its own (no HTTP needed)
nc -vz example.com 443 # Linux/Mac
Test-NetConnection example.com -Port 443 # Windows PowerShell
# Test the Application too
curl -v https://example.com
Observe with:
nc -vz <ip_vps> 80 — if 'succeeded' = Transport OK, nginx is listening. If 'refused' = nginx has not started or the port is wrong. If it times out after 5-10s = a firewall is blocking port 80.
Wrong: TCP/IP has 4 layers because the world abandoned the 7-layer OSI.
Right: OSI (ISO/IEC 7498-1) is a reference model used for analysis/teaching; TCP/IP (RFC 1122) is the actual implementation on the internet.
The two models co-exist and do not replace each other. Vendor docs (Cisco, AWS, Kubernetes) still use OSI terminology: "L7 firewall", "L4 load balancer", "L3 routing".
OSI Session/Presentation have no header of their own in the TCP/IP wire format — Application absorbs them into a single layer. That is why TCP/IP "merges into 4 layers" rather than dropping some.
When debugging AWS ALB (L7) vs NLB (L4), this OSI-based distinction is a prerequisite for reading the docs correctly.
Wrong: Layering is only a teaching concept; in practice network code still needs to know everything from the cable to HTTP.
Right: Layering = separation of concerns at the protocol design level.
The HTTP spec (RFC 9110) says nothing about Ethernet or WiFi — because layering lets HTTP run over any L2 (Ethernet, WiFi, 5G, Starlink, a VPN tunnel) without changing the spec.
Application code only calls the socket API (BSD sockets), and the kernel TCP/IP stack handles L2/L3/L4.
The concrete value: when you swap a copper cable for fiber, nginx does not recompile.
When a client moves from WiFi to 4G, the TCP connection can be kept (with MPTCP) because L4 does not know L2 changed. This is an invariant, not theory.
Wrong: Ping succeeding means the server is working.
Right: Ping tests L3 ICMP (RFC 792) — it only confirms that IP packets can reach the host and the kernel can reply.
The real service runs at L7, so you also need to test L4 (a TCP handshake to the right port) and L7 (a valid HTTP response).
A firewall can allow ICMP while blocking TCP :443. The host can be up and the kernel replying to ICMP — but if nginx has crashed, the client still gets 502 or connection refused.
Ping only proves L1-L3 are OK and says nothing about L4-L7.
Wrong: The encapsulation order can change depending on the protocol (for example, HTTPS "skips" TCP).
Right: The encapsulation order always ENDS at L2 Link because bits must leave the NIC → cable/WiFi with frame boundaries + MAC.
HTTPS does not "skip" TCP — TLS sits between TCP and HTTP, keeping the L4 port demux intact. A tunnel (VPN, WireGuard, GRE) just adds one more outer layer of encapsulation and does not skip any layer.
The physical constraint: the NIC only knows how to parse an Ethernet frame per IEEE 802.3 and does not know IP.
If the order disappeared → the NIC would not know where a frame starts or ends.
Understanding this invariant → when you see an unfamiliar packet capture (VXLAN, GENEVE), you know right away it is a tunnel overlay, not a "protocol that replaces TCP/IP".
1. The most basic command — check whether the target machine is alive + measure latency
ping -c 4 example.com
Observation: Look at time= (RTT) and packet loss. RTT <50ms = close, >200ms = far or slow. Packet loss > 0% is a worrying sign.
Press Ctrl+C to stop, and ping will print the min/avg/max statistics.
2. Turn a domain name into an IP — the basis of every connection
dig example.com +short
# or
nslookup example.com
Observation: dig example.com +short prints only the IP, nothing more. Try dig example.com (without +short) to see the TTL and the server being used.
If there is no output = DNS has failed completely.
3. See the machine's IP + MAC — know who the host is on the network
ip addr show # Linux
ifconfig # Mac
ipconfig /all # Windows
Observation: Find the interface with state UP and an inet (IPv4) address. Take care to distinguish private IPs (192.168.x.x, 10.x.x.x, 172.16-31.x.x) from public ones.
The MAC address is shown after 'ether' (Linux) or 'Physical Address' (Windows).
4. See the default gateway — the host's 'door out' to the internet
ip route # Linux
netstat -rn # Mac
route print # Windows
Observation: Look for the line 'default via X.X.X.X' (Linux) or the '0.0.0.0' destination (Windows). The IP after 'via' is the gateway.
Ping that gateway: if you cannot ping it = the Link/Internet to the gateway is dead = you cannot reach the internet.
5. See the real path of a packet through each router
traceroute example.com # Linux/Mac
tracert example.com # Windows
Observation: Each line is a router hop with its latency.
Look for the point where latency suddenly jumps — that is the bottleneck. '* * *' does not mean down, only that the router does not reply to ICMP. The last hop = the destination server or close to it.
6. Tell 'connection refused' from 'timeout' by experiment — core debugging
# Refused: the machine is alive, nobody listens on the port
nc -vz 127.0.0.1 65000
# Timeout: the IP does not exist
nc -vz -w 3 203.0.113.254 80
Observation: nc -vz 127.0.0.1 65000 will report 'refused' immediately (<1s). nc -vz -w 3 80 will wait 3 seconds and then time out.
The response speed is an important sign for telling them apart.
7. Watch packets in/out with tcpdump — a devops-level network debugging tool
sudo tcpdump -i any -n 'icmp' -c 10
Observation: While tcpdump is running, open another terminal and ping example.com. The output shows 2 lines per ping: 'echo request' (out) and 'echo reply' (back).
Seeing only the request with no reply = a firewall blocks the return traffic.
Question 1. When you type ping example.com, which layer of the 4-layer TCP/IP is NOT used?
Link
Internet
Transport
Application
Answer: Transport. ICMP (the protocol of ping) sits right at the Internet layer and does not go through Transport (TCP/UDP). That is why ping has no concept of a 'port'.
Link: Link is always used — without it, bits cannot get onto the cable/WiFi.
Internet: Internet is ping's main layer — the IP header and ICMP are both here.
Application: The ping command is itself a process at the Application layer calling down into the kernel.
Question 2. You deploy an app to a VPS. From the client machine: ping <ip_vps> is OK, but curl http://<ip_vps> reports 'connection refused'. Which layer is the problem at?
Link — the VPS network cable is loose
Internet — wrong routing
Transport — no process is listening on port 80
Application — it returns 500
Answer: Transport — no process is listening on port 80. Ping OK = Link + Internet are OK, and the VPS is alive.
'Connection refused' = the TCP SYN arrived but the VPS kernel returned an RST because no process is listening on port 80. Possibly nginx is not running / is running on the wrong port.
Link — the VPS network cable is loose: If Link were broken, ping would fail too.
Internet — wrong routing: If routing were wrong, ping would fail too.
Application — it returns 500: To receive a 500, the TCP connection must succeed first → you would not get 'refused'.
Question 3. How do the 4-layer TCP/IP and the 7-layer OSI differ?
TCP/IP is theory, OSI is what is actually deployed
TCP/IP merges OSI's L5/L6/L7 into Application, and L1+L2 into Link
They are exactly the same, only the names differ
Both have 4 layers
Answer: TCP/IP merges OSI's L5/L6/L7 into Application, and L1+L2 into Link. The 4-layer TCP/IP = Application (merging OSI L5+L6+L7) + Transport (L4) + Internet (L3) + Link (L1+L2).
This is the model that actually runs. OSI is a theoretical reference model.
TCP/IP is theory, OSI is what is actually deployed: The opposite — TCP/IP is practical, OSI is theoretical.
They are exactly the same, only the names differ: The number of layers differs.
Both have 4 layers: OSI has 7 layers.
Question 4. A host sends a frame out to the internet. What is the destination MAC address in the Ethernet frame?
The destination server's MAC
The gateway's MAC (the LAN router)
Broadcast FF:FF:FF:FF:FF:FF
The sending host's MAC
Answer: The gateway's MAC (the LAN router). A frame only travels within 1 LAN. To go outside it must rely on the gateway.
ARP can only ask for a MAC within the LAN, so the first frame has destination MAC = the gateway's MAC. The gateway strips the frame and builds a new frame with the next hop's MAC.
The destination server's MAC: The host does not know the MAC of a server on another network — ARP does not run across routers.
Broadcast FF:FF:FF:FF:FF:FF: Broadcast is only used for ARP/DHCP discovery.
The sending host's MAC: That is the source MAC, not the destination.
Question 5. curl example.com reports 'could not resolve host'. Which layer is the problem at?
Link — a loose cable
Internet — IP routing is broken
Application — DNS does not return an IP
Transport — the TCP handshake fails
Answer: Application — DNS does not return an IP. DNS is a protocol at the Application layer. 'Could not resolve host' = curl could not obtain an IP → it never got as far as Internet/Transport.
It is usually because the DNS server does not respond or /etc/resolv.conf is wrong.
Link — a loose cable: A Link failure gives a different error, usually 'network unreachable'.
Internet — IP routing is broken: It has not reached Internet yet — there is no IP to route.
Transport — the TCP handshake fails: It has not reached TCP yet — there is no destination IP to handshake with.
Question 6. Why does TCP/IP separate Transport (ports) from Internet (IP)?
For better security
Because one machine has 1 IP but runs many services — ports distinguish nginx:80, ssh:22, mysql:3306
Because routers need both the IP and the port to route
Because IPv4 does not have enough ports
Answer: Because one machine has 1 IP but runs many services — ports distinguish nginx:80, ssh:22, mysql:3306. The very reason Transport exists is multiple services on 1 host.
IP gets the packet to the right machine, the port gets the packet to the right process.
For better security: Ports do not add security — attackers scan ports very easily.
Because routers need both the IP and the port to route: Routers normally read only the IP (except advanced NAT).
Because IPv4 does not have enough ports: IP and port are 2 different concepts.
Question 7. You ping an IP and see a reply with ttl=54. What does this tell you?
The packet has 54 seconds left to live
The packet has passed through about 10 routers (if the destination OS sets the default TTL of 64)
The connection can be held 54 more times
It means nothing
Answer: The packet has passed through about 10 routers (if the destination OS sets the default TTL of 64). TTL decreases by 1 at each router.
Many OSes set the initial TTL = 64 (Linux/Mac) or 128 (Windows). With ttl=54 at the client, guessing the server uses 64 → it passed 10 hops.
This is a way to guess the OS type + the distance without traceroute.
The packet has 54 seconds left to live: The unit of TTL is 'hops', not seconds (despite the name Time To Live).
The connection can be held 54 more times: TTL is counted per packet, not per 'connection'.
It means nothing: It does mean something — it is exactly the number of hops traveled.
Question 8. You unplug the network cable / turn off WiFi. Which error appears EARLIEST when you run curl?
Connection timeout
Could not resolve host (DNS fail)
TLS handshake failed
Network is unreachable — reported immediately
Answer: Network is unreachable — reported immediately. A Link layer failure is recognized by the kernel right away (the interface state is down).
Curl asks the kernel to 'send' and the kernel replies 'there is no route' — there is nothing to wait for. The other errors all need a timeout or a response from outside.
Connection timeout: A timeout needs several seconds to tens of seconds of waiting.
Could not resolve host (DNS fail): A DNS failure also needs to wait for a timeout.
TLS handshake failed: TLS is at the Application layer, a long way before it would be reached.
How many layers does TCP/IP have? Name them from bottom to top.
4 layers: Link → Internet → Transport → Application. This is the REAL model of the internet. Remembering these 4 layers is enough to work with; the 7-layer OSI is only a theoretical reference.
What does the Link layer do?
Moves bits/frames between 2 devices on the SAME LAN. It uses MAC addresses. Corresponds to OSI L1 + L2. *Link fails = everything above is meaningless.
Always debug Link first (the NIC light, ip link, WiFi). *
What does the Internet layer do?
Routes packets ACROSS multiple networks using IP addresses. Protocols: IP, ICMP (ping). Corresponds to OSI L3. *The layer that creates the 'Inter-net' (internetworking).
Without it, every LAN is an island. *
What does the Transport layer do?
Splits data into segments (TCP) / datagrams (UDP) and attaches a PORT to distinguish services. Corresponds to OSI L4.
*One machine with many services → the port is the only way to tell nginx:80 from ssh:22 from mysql:3306. *
What does the Application layer include?
HTTP, DNS, SSH, TLS, FTP, SMTP... Every protocol devs code against every day. Corresponds to OSI L5+L6+L7. *Devs spend 90% of their work at this layer.
A 400/500 error is Application, NOT a network error. *
Which protocol does ping use? At which layer?
ICMP (Internet Control Message Protocol) — at the INTERNET layer, not going through Transport. *That is why ping has no port.
A firewall can let ping through but block TCP — leading to 'ping works, curl doesn't'. *
Ping works + curl reports 'connection refused' = ?
Link + Internet are OK. The problem is at Transport: the target machine is alive but no process is listening on that port.
*Common when deploying a VPS: you forgot to start nginx, or nginx listens on another port. Not a network error. *
Ping works + curl reports 'connection timeout' = ?
Link + Internet are OK, but the TCP SYN cannot reach a process. Usually a firewall blocks the port.
*Telling refused from timeout is a core debugging skill: refused = the machine is alive, timeout = a firewall or the network blocks it. *
Which layer is DNS at?
Application. DNS is a protocol at the Application layer, running on UDP port 53. The error 'could not resolve host' = DNS fail = it has not yet reached Internet/Transport. Debug with dig/nslookup.
When a frame leaves the LAN, what is the destination MAC?
The GATEWAY's MAC, NOT the destination server's MAC. ARP can only ask within the LAN. Beyond it, the gateway strips the frame and rebuilds it with a new MAC for the next hop.
What is TTL in the IP header for?
It limits the number of hops a packet passes through. Each router decrements it by 1, and at 0 the packet is dropped → preventing endless loops.
*Traceroute exploits TTL: it sends TTL=1,2,3... to 'lure' each router into reporting a Time Exceeded error → revealing the path. *
What is encapsulation?
Each layer wraps its own header around the packet from the layer above. Going down = adding a header. Going up = stripping a header.
*Layers are separated so that changing 1 layer does not affect the others. Switching from WiFi to cable does not require changing HTTP. *
Why did TCP/IP 'win' over OSI in practice?
TCP/IP had a working implementation (ARPANET → Internet). OSI came later, was too detailed, and had not spread in time. *Today: code and tools all run on TCP/IP.
OSI is still used as a 'common language' when saying 'the error is at which layer'. *
What is a gateway / default route?
The default router that receives every packet whose destination IP is OUTSIDE the LAN. View it with ip route. *A dead gateway = losing the whole internet even though WiFi still shows 'connected'.
The number 1 culprit when a host cannot reach the internet. *