Interview Focus Areas:
Network Hardware: components, functions, how they interact
Protocols: TCP/IP, HTTP, DNS, routing protocols
Network Troubleshooting: packet loss, latency, connectivity problems
Packet Analysis: Wireshark/tcpdump to identify packet loss and detect proxies (including transparent proxies)
Proxy Usage: caching, filtering, security
Answer: The OSI (Open Systems Interconnection) model is a conceptual framework that standardizes network communication into seven distinct layers, each with a well-defined responsibility.
Layer 7 — Application: The layer closest to the end user. It provides network services directly to applications. Protocols: HTTP, HTTPS, FTP, SMTP, DNS, SNMP, SSH. This is where browsers, email clients, and file-transfer applications operate.
Layer 6 — Presentation: Responsible for data translation, encryption/decryption, and compression. It ensures data from the application layer of one system can be read by the application layer of another. Examples: SSL/TLS encryption (conceptually sits here), JPEG/MPEG encoding, ASCII ↔ EBCDIC translation.
Layer 5 — Session: Manages sessions (connections) between applications. Establishes, maintains, and terminates communication sessions. Examples: RPC (Remote Procedure Call), NetBIOS, SQL sessions. In practice, TCP's connection state partially fulfills this role.
Layer 4 — Transport: End-to-end communication, segmentation, flow control, and error recovery. Protocols: TCP (connection-oriented, reliable) and UDP (connectionless, best-effort). Ports live at this layer. Responsible for multiplexing multiple application streams over a single network connection.
Layer 3 — Network: Logical addressing and routing. Determines the best path for data to travel across multiple networks. Protocols: IP (IPv4/IPv6), ICMP, OSPF, BGP. Devices: routers, Layer 3 switches.
Layer 2 — Data Link: Node-to-node delivery within a single network segment. Handles MAC addressing, framing, and error detection (CRC). Sub-layers: LLC (Logical Link Control) and MAC (Media Access Control). Protocols: Ethernet, Wi-Fi (802.11), PPP. Devices: switches, bridges.
Layer 1 — Physical: The raw transmission of bits over a physical medium. Defines electrical signals, cable types, pin layouts, voltages, and data rates. Examples: Ethernet cables (Cat5e/Cat6), fiber optics, Wi-Fi radio waves, repeaters, hubs.
Why interviewers care: The OSI model is the common language for debugging. When you say "Layer 3 issue," everyone knows you mean IP routing. When you say "Layer 4," they know TCP/UDP ports. Understanding which layer a failure is at dramatically narrows troubleshooting scope.
Answer: The TCP/IP model (also called the Internet model or DoD model) is the practical framework that actually governs the modern Internet, while OSI is a theoretical reference model.
TCP/IP has 4 layers:
Network Access / Link Layer — Combines OSI Layers 1 and 2 (Physical + Data Link). Handles hardware addressing and physical transmission.
Internet Layer — Corresponds to OSI Layer 3. IP, ICMP, ARP.
Transport Layer — Corresponds to OSI Layer 4. TCP and UDP.
Application Layer — Combines OSI Layers 5, 6, and 7. HTTP, DNS, SSH, SMTP, etc.
Key differences:
OSI is prescriptive and theoretical; TCP/IP is descriptive and emerged from real-world ARPANET protocols.
OSI strictly separates presentation and session from application; TCP/IP collapses them.
OSI was designed to be protocol-independent; TCP/IP is literally named after its two flagship protocols.
In practice, engineers use OSI layer numbering for troubleshooting conversations but implement TCP/IP stack layers in code.
Interview tip: Google engineers will reference OSI layer numbers constantly in design discussions ("this is a Layer 4 load balancer vs Layer 7"), so know both models cold.
Answer: Encapsulation is the process by which each layer of the network stack adds its own header (and sometimes trailer) to the data passed down from the layer above, wrapping it before transmission. De-encapsulation is the reverse process on the receiving end.
Encapsulation flow (sender):
Application data (e.g., HTTP request body) → Application Layer
Transport layer adds TCP/UDP header (source/dest port, sequence number) → creates a Segment
Network layer adds IP header (source/dest IP, TTL, protocol) → creates a Packet
Data Link layer adds Ethernet header (src/dst MAC) + Ethernet trailer (FCS/CRC) → creates a Frame
Physical layer converts to bits and transmits on the wire
De-encapsulation flow (receiver): Each layer strips its corresponding header, processes it, and passes the payload up to the next layer.
PDU names by layer:
Layer 7-5: Data
Layer 4: Segment (TCP) / Datagram (UDP)
Layer 3: Packet
Layer 2: Frame
Layer 1: Bits
Why it matters for troubleshooting: When you capture packets with tcpdump, you see all these layers stacked. Understanding encapsulation tells you exactly what headers to look at when diagnosing problems at specific layers.
Answer: These three devices operate at different OSI layers and serve fundamentally different purposes.
Hub (Layer 1 — Physical):
A dumb repeater. When it receives a signal on one port, it broadcasts that signal out every other port simultaneously.
All devices connected to a hub share the same collision domain — only one device can transmit at a time without causing a collision (CSMA/CD).
Creates one large collision domain. No intelligence; no MAC address awareness.
Rarely used today; replaced by switches.
Switch (Layer 2 — Data Link):
Uses MAC address tables (CAM tables) to learn which MAC addresses live on which ports.
Forwards frames only to the specific port where the destination MAC is connected. All other ports do not see the frame.
Each port is its own collision domain (full-duplex eliminates collisions entirely).
Still one broadcast domain by default (unless VLANs are configured).
Modern switches can also operate at Layer 3 (routing between VLANs).
Router (Layer 3 — Network):
Routes packets between different networks using IP addresses and routing tables.
Each interface on a router is a separate broadcast domain.
Performs NAT, filtering, QoS, and dynamic routing (OSPF, BGP).
Makes forwarding decisions based on destination IP, not MAC address.
Summary table:
| Feature | Hub | Switch | Router |
|---|---|---|---|
| OSI Layer | 1 | 2 | 3 |
| Addressing | None | MAC | IP |
| Collision Domains | 1 | Per port | Per interface |
| Broadcast Domains | 1 | 1 (default) | Per interface |
| Intelligent forwarding | No | Yes | Yes |
Answer: Collision domain: A network segment where two devices can simultaneously transmit and cause a collision. In half-duplex Ethernet, all devices on a shared medium (hub) are in the same collision domain. Each switch port is its own collision domain. With full-duplex, collisions are theoretically eliminated.
Broadcast domain: The set of all devices that receive a Layer 2 broadcast (destination MAC = FF:FF:FF:FF:FF:FF) sent by any single device. Switches forward broadcasts to all ports in the same VLAN, so by default an entire switch is one broadcast domain. Routers do NOT forward broadcasts — they terminate them. Each router interface (or VLAN with inter-VLAN routing) is a separate broadcast domain.
Example: A company with 200 workstations on a single flat switch has one broadcast domain. Every ARP request, DHCP discover, and NetBIOS name announcement hits all 200 machines. Segmenting with VLANs or routers reduces broadcast noise and improves performance.
Why Google cares: At scale, broadcast domain size directly affects network performance. Large broadcast domains create excessive ARP traffic, STP complexity, and security exposure.
Answer: ARP (Address Resolution Protocol) maps a known IP address to an unknown MAC address within a local network segment. It operates at the boundary of Layer 2 and Layer 3.
ARP workflow:
Host A wants to send a packet to 192.168.1.5 but only knows the IP.
Host A checks its ARP cache (arp -n or ip neigh show) for a cached mapping.
If not found, Host A broadcasts an ARP Request: "Who has 192.168.1.5? Tell 192.168.1.1."
The device with that IP (Host B) responds with a unicast ARP Reply: "192.168.1.5 is at AA:BB:CC:DD:EE:FF."
Host A caches this mapping and sends its frame to that MAC.
ARP cache inspection:
xxxxxxxxxxarp -n # Show ARP cache (classic)ip neigh show # Modern Linux equivalentip neigh show dev eth0 # Limit to specific interfaceARP Poisoning (ARP Spoofing): An attacker sends gratuitous ARP replies claiming that their MAC address corresponds to the IP of a legitimate host (e.g., the default gateway). Victims update their ARP cache with the attacker's MAC, directing all traffic through the attacker's machine — a classic Man-in-the-Middle (MITM) attack.
Defenses:
Dynamic ARP Inspection (DAI) on managed switches
Static ARP entries for critical hosts
802.1X port authentication
Network monitoring for duplicate IP/MAC pairs (detect with arping)
Answer: Half-duplex: A device can either transmit OR receive at any given moment, but not both simultaneously. Uses CSMA/CD (Carrier Sense Multiple Access with Collision Detection) to manage access to the shared medium. When two devices transmit simultaneously, a collision occurs; both back off for a random period (exponential backoff) and retry. Hubs force half-duplex. Maximum theoretical efficiency is about 50-60% of link capacity.
Full-duplex: A device can transmit and receive simultaneously using separate wire pairs (or different frequencies). No collisions are possible by design. Requires a point-to-point link (switch port to NIC). Modern switched Ethernet (100Mbps and above) negotiates full-duplex by default. Doubles theoretical throughput compared to half-duplex.
When you see half-duplex today:
Old equipment that doesn't support full-duplex negotiation
Duplex mismatch (one side set to auto, other hardcoded to half-duplex) — causes severe performance degradation, high retransmit rates, and CRC errors. Diagnosable with ethtool eth0 (shows "Duplex: Half" or "Duplex: Full") or by observing late collisions in switch port statistics.
Detection commands:
xxxxxxxxxxethtool eth0 # Shows duplex, speed, link statusip link show eth0 # Shows interface stateAnswer: TCP is a connection-oriented protocol. Before any data is exchanged, both endpoints must synchronize their Initial Sequence Numbers (ISNs) through a three-way handshake.
Step 1 — SYN (Client → Server):
Client sends a TCP segment with the SYN flag set.
Contains: Client's ISN (e.g., seq=1000), window size, MSS (Maximum Segment Size) option, SACK permitted, timestamps.
Client moves to SYN_SENT state.
Step 2 — SYN-ACK (Server → Client):
Server acknowledges the client's SYN and sends its own SYN.
Contains: Server's ISN (e.g., seq=5000), ACK number = client's ISN + 1 (ack=1001), server's window size and MSS.
Server moves to SYN_RECEIVED state.
Step 3 — ACK (Client → Server):
Client acknowledges the server's SYN.
Contains: seq=1001, ack=5001, no data payload typically.
Both sides move to ESTABLISHED state.
Why the three-way? Two-way would only synchronize one direction. Three-way ensures both sides have confirmed that both directions of communication work and that both ISNs are acknowledged.
SYN flood attack: Attackers send floods of SYN packets without completing the handshake, exhausting the server's half-open connection table (SYN backlog). Mitigated by SYN cookies, which allow the server to encode connection state in the ISN rather than storing it.
tcpdump to see handshake:
xxxxxxxxxxtcpdump -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) != 0' -n# Or simply:tcpdump -i eth0 'host 10.0.0.1 and port 80' -nAnswer: TCP teardown is asymmetric — each side closes independently, which is why it requires four steps (two FINs and two ACKs) rather than the three of the handshake.
Four-way teardown:
FIN (Active closer → Passive): Active side finishes sending, sends FIN. Moves to FIN_WAIT_1.
ACK (Passive → Active closer): Passive side ACKs the FIN, moves to CLOSE_WAIT. Active moves to FIN_WAIT_2. The passive side may continue sending data at this point (half-close).
FIN (Passive → Active closer): Passive side finishes sending, sends its own FIN. Moves to LAST_ACK.
ACK (Active closer → Passive): Active closer ACKs the final FIN. Moves to TIME_WAIT for 2×MSL (Maximum Segment Lifetime). Passive side receives ACK and moves to CLOSED.
TIME_WAIT (2×MSL, typically 60–120 seconds):
Reason 1 — Reliable ACK delivery: The last ACK from the active closer might be lost. If it is, the passive side will retransmit its FIN. TIME_WAIT ensures the active closer is still alive to re-send that final ACK.
Reason 2 — Prevent old duplicate segments: Ensures any delayed packets from the old connection expire before the same 4-tuple (src IP, src port, dst IP, dst port) can be reused for a new connection, preventing data corruption.
TIME_WAIT exhaustion: High-traffic servers (especially those initiating many short connections) can exhaust ephemeral ports because too many sockets are in TIME_WAIT. Solutions:
SO_REUSEADDR / SO_REUSEPORT socket options
net.ipv4.tcp_tw_reuse = 1 (sysctl) — reuse TIME_WAIT sockets for new connections where safe (requires timestamps)
Reduce MSL via net.ipv4.tcp_fin_timeout
Check TIME_WAIT count:
xxxxxxxxxxss -s # Summary including TIME_WAIT countss -tan state time-wait # List all TIME_WAIT socketsnetstat -an | grep TIME_WAIT | wc -lAnswer: Sliding Window (Flow Control): TCP uses a sliding window to control how much data the sender can have "in flight" (sent but not yet acknowledged) at any time. The receiver advertises its receive window size (rwnd) in every ACK — the amount of buffer space it currently has available. The sender must not have more unacknowledged bytes in flight than the receiver's advertised window. As the receiver processes data and frees buffer space, it advertises a larger window, allowing the sender to transmit more.
The window "slides" forward as data is acknowledged. The sender maintains:
SND.UNA: Oldest unacknowledged byte
SND.NXT: Next byte to send
SND.WND: Current window size
Flow Control (receiver-driven): Prevents the sender from overwhelming the receiver's buffer. Controlled by the receiver's rwnd advertisement.
Congestion Control (network-driven): Prevents the sender from overwhelming intermediate network links and routers. TCP infers network congestion from:
Packet loss (timeout or 3 duplicate ACKs)
ECN (Explicit Congestion Notification) marks from routers
TCP congestion control phases:
Slow Start: cwnd (congestion window) starts at ~1-10 MSS, doubles every RTT until it reaches ssthresh or detects congestion.
Congestion Avoidance: After reaching ssthresh, increase cwnd by 1 MSS per RTT (additive increase).
Fast Retransmit: On 3 duplicate ACKs (indicating a lost segment), retransmit without waiting for timeout. Set ssthresh = cwnd/2, cwnd = ssthresh (TCP Reno) or cwnd = ssthresh + 3 (cubic variant).
Fast Recovery: After fast retransmit, continue sending new segments using duplicate ACKs as a clock.
Effective send rate: min(cwnd, rwnd) — the smaller of what the network can handle and what the receiver can absorb.
Relevant tunables:
xxxxxxxxxxsysctl net.ipv4.tcp_rmem # Receive buffer min/default/maxsysctl net.ipv4.tcp_wmem # Send buffer min/default/maxsysctl net.ipv4.tcp_congestion_control # Algorithm (cubic, bbr, reno)Answer: Without SACK, TCP uses cumulative acknowledgments. If segment 5 in a sequence of 10 is lost, the receiver can only acknowledge up to segment 4. Even if segments 6–10 arrived fine, the sender must retransmit segment 5 and potentially all subsequent segments (Go-Back-N behavior in naive implementations). This wastes bandwidth.
SACK (RFC 2018): The receiver includes SACK blocks in ACK packets, explicitly telling the sender which non-contiguous ranges of data have been received. The sender can then retransmit only the missing segments (selective retransmit).
Example: Segments 1–4, 6–10 received; 5 is missing. Without SACK: sender retransmits from 5 onward. With SACK: receiver sends ACK=5 with SACK block {6–10}. Sender retransmits only segment 5.
Benefits:
Dramatically reduces retransmissions on lossy networks
Critical for high-bandwidth, high-latency paths (long-fat networks) where a single loss could otherwise stall an entire window
Negotiation: Both sides must advertise SACK support in their SYN/SYN-ACK options (SACK permitted option). Check with:
xxxxxxxxxxtcpdump -i eth0 -v 'tcp[tcpflags] & tcp-syn != 0'# Look for "sackOK" in the options fieldAnswer: Nagle's algorithm (RFC 896) addresses the "small packet problem" — without it, an application writing one byte at a time would generate one tiny TCP segment per byte, each carrying 40+ bytes of TCP/IP header overhead (extremely inefficient).
Nagle's rule: A TCP sender can have at most one outstanding unacknowledged small segment. New small data can only be sent if:
There is no unacknowledged data in flight, OR
The data to send fills at least one MSS
This coalesces small writes into fewer, larger segments, dramatically reducing the number of packets on the wire.
When to disable Nagle (TCP_NODELAY):
Interactive applications with strict latency requirements: SSH, Telnet, gaming clients, financial trading systems. Nagle can add up to one RTT of additional latency while it waits to accumulate data.
Request-response protocols where the request is small: If a client sends a small request and then waits for a response, Nagle might delay sending that request while waiting for an ACK that will never come (the server is waiting for the request).
Real-time streaming: Video conferencing, where you want each small audio/video chunk sent immediately.
Code example:
xxxxxxxxxximport socketsock = socket.socket()sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)Related: TCP_CORK (Linux) — opposite of TCP_NODELAY. Holds back data even more aggressively, waiting to fill a full MSS. Useful for bulk data transfer scenarios where you want to batch writes.
Answer:
TCP Keepalives: TCP has an optional keepalive mechanism (SO_KEEPALIVE socket option). After a connection has been idle for tcp_keepalive_time (default: 7200 seconds = 2 hours on Linux), the kernel sends a keepalive probe — a TCP segment with no data and ACK set, with seq number one less than the next expected byte. If the peer acknowledges it, the idle timer resets. If no response after tcp_keepalive_probes retries spaced tcp_keepalive_intvl apart, the connection is declared dead and an error is returned to the application.
Linux defaults:
xxxxxxxxxxsysctl net.ipv4.tcp_keepalive_time # 7200 (2 hours)sysctl net.ipv4.tcp_keepalive_intvl # 75 (seconds between probes)sysctl net.ipv4.tcp_keepalive_probes # 9 (probes before giving up)Problems with TCP keepalives:
2-hour default is far too long for most applications
Doesn't work through NAT gateways that time out flows (NAT tables typically expire after 5–30 minutes of inactivity)
Doesn't detect application-level failures (server alive but app hung)
Can't be sent with user data; tells you the TCP connection is alive, not that the application is responding
Application-level heartbeats:
Sent by the application itself at a much shorter interval (e.g., every 30 seconds)
Can carry payload data (e.g., ping/pong frames in WebSocket, PING frames in HTTP/2)
Can detect application hangs, not just dead TCP stacks
Work through NAT and stateful firewalls that would drop long-idle TCP flows
Can be used to measure round-trip latency at the application level
Best practice: Use both — TCP keepalives to clean up OS-level dead connections, application heartbeats for health monitoring.
Answer: TCP (Transmission Control Protocol):
Connection-oriented (requires handshake)
Reliable: guarantees delivery via acknowledgments and retransmissions
Ordered: segments are delivered in sequence order
Flow control and congestion control
Higher overhead: larger headers, connection state, handshake latency
Stream-oriented: no message boundaries
UDP (User Datagram Protocol):
Connectionless: no handshake
Best-effort: no delivery guarantees, no retransmission
No ordering guarantees
No flow or congestion control
Minimal overhead: 8-byte header vs TCP's 20+ bytes
Message-oriented: preserves application message boundaries
No head-of-line blocking
Choose TCP when:
Data integrity is critical: file transfers (FTP, HTTP downloads), database connections, email (SMTP, IMAP)
Order matters: web pages (HTTP/1.1), SSH sessions
You need exactly-once semantics
Choose UDP when:
Low latency matters more than reliability: DNS queries, online gaming, VoIP, video conferencing
Application can handle its own reliability: QUIC builds on UDP and implements its own reliability
Broadcasting or multicasting: discovery protocols, streaming media
High-frequency small messages where retransmission would be useless by the time it arrived (real-time sensor data, financial tick data)
Tunneling where the inner protocol is already reliable
Interesting cases:
QUIC (HTTP/3): Built on UDP, reimplements connection-level reliability with improved congestion control and 0-RTT connection establishment
DNS: Uses UDP for small queries (< 512 bytes), falls back to TCP for large responses (EDNS0 allows larger UDP, TCP for zone transfers)
NFS: Historically UDP, modern versions use TCP
Answer: MTU (Maximum Transmission Unit): The largest IP packet that can be sent without fragmentation over a given link. Standard Ethernet MTU is 1500 bytes. This includes the IP header (20 bytes minimum) and TCP header (20 bytes minimum), leaving 1460 bytes for TCP payload (MSS = MTU - IP header - TCP header).
When a packet exceeds MTU: If an IP packet is larger than the MTU of an outgoing link:
IPv4: The router can fragment the packet if the Don't Fragment (DF) bit is NOT set. Fragmentation splits the packet into smaller pieces, each with its own IP header. Reassembly happens at the destination.
IPv4 with DF=1: The router drops the packet and sends back an ICMP Type 3, Code 4 ("Fragmentation Needed") message to the source, including the MTU of the next-hop link.
IPv6: Routers never fragment. Only the source can fragment. If the packet is too big, the router sends an ICMPv6 Type 2 "Packet Too Big" message.
Problems with fragmentation:
Performance overhead at routers
Any fragment loss requires the entire original datagram to be retransmitted
Stateful firewalls may drop non-first fragments
VPN headers add overhead, reducing effective MTU (e.g., IPSec over Ethernet: effective MTU ~1400 bytes)
Path MTU Discovery (PMTUD): The mechanism for discovering the minimum MTU along an entire path from source to destination.
Source sends packets with DF=1 set at the MTU of its local interface (1500).
If a router along the path has a smaller MTU link, it drops the packet and sends ICMP "Fragmentation Needed" with the smaller MTU.
Source reduces its packet size and retries.
Process repeats until packets reach destination without ICMP errors.
PMTUD Black Holes: If ICMP is blocked by firewalls between source and destination, PMTUD breaks. The source keeps sending large packets that silently get dropped. Symptom: connection establishes fine (small SYN packets) but hangs when sending bulk data.
Diagnosis and fix:
xxxxxxxxxx# Check MTU on interfaceip link show eth0 | grep mtu
# Test with specific packet size (ping with specific size and DF bit)ping -M do -s 1472 192.168.1.1 # 1472 data + 28 IP/ICMP header = 1500
# Check path MTUtracepath 8.8.8.8 # Shows PMTU per hop
# Workaround: MSS clamping via iptablesiptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN \ -j TCPMSS --clamp-mss-to-pmtuAnswer: Purpose of sequence numbers:
Ordered delivery: Allow the receiver to reorder out-of-order segments
Duplicate detection: Identify and discard duplicate segments
Reliable delivery: Track which data has been acknowledged
Security: Prevent TCP injection attacks (an attacker would need to guess the ISN)
Structure: TCP uses a 32-bit sequence number, providing a range of 0 to 4,294,967,295 (4 billion). The sequence number refers to the byte offset of the first byte in the segment's data, not the segment number.
Initialization (ISN — Initial Sequence Number): ISNs should be random (RFC 6528) to prevent TCP injection attacks. Early implementations used a clock-based ISN that incremented by 128,000 every second and 64,000 for each new connection. Modern implementations use cryptographic randomness (ISN = MD5(srcIP, srcPort, dstIP, dstPort, secret) + timestamp).
Wrap-around: After reaching 2^32 - 1, the sequence number wraps back to 0. This is handled transparently by the TCP stack. At 1 Gbps, you would exhaust 32-bit sequence numbers in about 34 seconds. The PAWS (Protection Against Wrapped Segments) extension uses TCP timestamps to disambiguate segments with the same sequence number from different "generations" of the counter, critical for high-speed links.
Answer: DNS (Domain Name System) is a hierarchical, distributed database that maps domain names to IP addresses. A full resolution involves multiple recursive queries.
Full resolution for www.example.com:
Local cache check: The OS resolver checks its local DNS cache (populated from previous queries, TTL-honored). On Linux: /etc/hosts is checked first, then /etc/resolv.conf determines the recursive resolver to use.
Stub resolver → Recursive resolver: The client's stub resolver (OS) sends a recursive query to the configured recursive resolver (e.g., 8.8.8.8 for Google DNS, or the corporate DNS server). The stub resolver asks: "Resolve www.example.com for me completely."
Recursive resolver → Root nameservers: The recursive resolver checks its own cache. If no cache hit, it queries one of the 13 root nameserver clusters (A–M.root-servers.net). The query: "Who is authoritative for .com?" The root nameserver responds with the TLD nameservers for .com (e.g., a.gtld-servers.net).
Recursive resolver → TLD nameservers: The resolver queries the .com TLD nameserver: "Who is authoritative for example.com?" The TLD nameserver responds with the authoritative nameservers for example.com (e.g., ns1.example.com, ns2.example.com).
Recursive resolver → Authoritative nameserver: The resolver queries ns1.example.com: "What is the A record for www.example.com?" The authoritative server responds with the IP address and TTL.
Response returned to client: The recursive resolver caches the result (respecting TTL) and returns the IP to the client stub resolver, which caches it and returns it to the application.
Record types returned:
A record: IPv4 address
AAAA record: IPv6 address
CNAME: Alias to another domain name
NS: Authoritative nameserver records
SOA: Start of Authority (zone metadata)
Commands:
xxxxxxxxxx# Full recursive resolution tracedig +trace www.example.com
# Query specific DNS serverdig @8.8.8.8 www.example.com A
# Check all record typesdig www.example.com ANY
# Reverse DNSdig -x 8.8.8.8
# Query with specific optionsdig +short +nocmd www.example.comAnswer: Authoritative DNS server:
Holds the actual DNS zone records for a domain. This is the "source of truth."
Only answers queries for domains it is configured to host.
Does not perform recursive lookups for other domains.
Returns definitive (authoritative) answers with the AA (Authoritative Answer) flag set.
Examples: AWS Route 53, Cloudflare authoritative DNS, BIND configured as a primary/secondary server.
Recursive DNS resolver (recursive resolver / DNS recursor):
Receives queries from clients and performs the full resolution process on their behalf.
Queries root servers, TLD servers, and authoritative servers iteratively.
Caches responses according to TTL to avoid repeated lookups.
Returns non-authoritative answers to clients (AA flag not set).
Examples: 8.8.8.8 (Google), 1.1.1.1 (Cloudflare), 9.9.9.9 (Quad9), ISP-provided resolvers.
Forwarder: A DNS server that forwards all queries it can't answer from cache to another DNS server (usually the ISP's recursive resolver). Common in corporate environments where internal DNS servers forward external queries upstream.
Split-horizon DNS: A configuration where different answers are returned based on the query source. Internal clients receive internal IPs; external clients receive public IPs. Implemented using DNS views in BIND.
xxxxxxxxxx# Check if answer is authoritative (look for "aa" flag)dig www.example.com | grep -E "flags:|status:"
# Query authoritative server directlydig NS example.com # Find authoritative serversdig @ns1.example.com example.com # Query directlyAnswer:
| Record | Purpose | Example |
|---|---|---|
| A | Maps hostname to IPv4 address | www.example.com. 300 IN A 93.184.216.34 |
| AAAA | Maps hostname to IPv6 address | www.example.com. 300 IN AAAA 2606:2800:220:1:248:1893:25c8:1946 |
| CNAME | Alias from one name to another | blog.example.com. CNAME www.example.com. |
| MX | Mail exchanger for the domain | example.com. MX 10 mail.example.com. |
| NS | Authoritative nameserver for zone | example.com. NS ns1.example.com. |
| SOA | Start of Authority; zone metadata | Serial, refresh, retry, expire, minimum TTL |
| PTR | Reverse DNS (IP → hostname) | 34.216.184.93.in-addr.arpa. PTR www.example.com. |
| TXT | Arbitrary text; used for SPF, DKIM, domain verification | example.com. TXT "v=spf1 include:_spf.google.com ~all" |
| SRV | Service location (host + port) | _http._tcp.example.com. SRV 10 5 80 www.example.com. |
| CAA | Certificate Authority Authorization | example.com. CAA 0 issue "letsencrypt.org" |
| DNSKEY | Public key for DNSSEC | Zone signing key |
| DS | Delegation Signer for DNSSEC chain of trust | Hash of child zone's DNSKEY |
CNAME restrictions: A CNAME cannot coexist with other record types for the same name. This is why you can't use a CNAME for a zone apex (root domain). CDNs work around this with ALIAS/ANAME records (proprietary record type that resolves at the DNS server itself).
MX priority: Lower number = higher priority. If primary MX (priority 10) is down, mail servers will try priority 20, etc.
Answer: TTL (Time To Live) in DNS specifies (in seconds) how long a resolver or client may cache a DNS record before it must re-query the authoritative server.
High TTL (e.g., 86400 = 24 hours):
Pros: Reduces DNS query volume, reduces load on authoritative servers, faster resolution for repeat queries (cache hits), more resilient to nameserver outages
Cons: Changes propagate slowly — if you update an A record, clients that recently resolved it may have the old IP cached for up to the TTL duration. Critical during migrations.
Low TTL (e.g., 60 seconds):
Pros: Changes propagate nearly instantly, critical for failover scenarios (switch IPs quickly during incidents)
Cons: Higher query volume to authoritative servers, more latency for clients (cache misses more often), higher cost on DNS providers that charge per query
Best practice for planned changes (migrations, maintenance):
Lower TTL to 60–300 seconds several days before the planned change (this must be done in advance so the low TTL itself propagates)
Make the DNS change
Wait one old-TTL duration to ensure all caches have expired
After rollout is confirmed, restore TTL to normal (e.g., 3600 or 86400)
Checking TTL:
xxxxxxxxxxdig www.example.com | grep -A2 "ANSWER SECTION"# The number in the second column is the TTL (decrements in recursive resolvers)
# Check what TTL the authoritative server returns:dig @ns1.example.com www.example.comNegative TTL (NXDOMAIN caching): Controlled by the SOA record's minimum field. How long to cache "this domain does not exist" responses.
Answer: DNSSEC (DNS Security Extensions) adds cryptographic signatures to DNS responses, allowing resolvers to verify that the DNS data they received is authentic and has not been tampered with. It defends against DNS cache poisoning (Kaminsky attack) and man-in-the-middle attacks.
How DNSSEC works:
Zone administrators sign their zone records using a private key (Zone Signing Key, ZSK)
The signed records are published as RRSIG records alongside each RR set
The public key is published in a DNSKEY record in the zone
A hash of the child zone's DNSKEY is published as a DS record in the parent zone
This creates a chain of trust from the root zone (. trust anchor) down to individual zones
Chain of trust: root → TLD (e.g., .com) → SLD (e.g., example.com). Each level signs a DS record for the next level down.
What DNSSEC does NOT provide:
Confidentiality (responses are still visible to anyone on the path — use DNS over HTTPS/TLS for that)
Protection against compromised authoritative servers
Modern alternatives for DNS privacy:
DoH (DNS over HTTPS): DNS queries sent via HTTPS (port 443), looks like normal web traffic
DoT (DNS over TLS): DNS over TLS on port 853
DoQ (DNS over QUIC): DNS over QUIC protocol
Check DNSSEC:
xxxxxxxxxxdig +dnssec www.example.com # Shows RRSIG records if DNSSEC is enableddig +sigchase www.example.com # Full chain validation (some dig versions)Answer: DNS-based load balancing distributes traffic by returning different IP addresses in response to DNS queries.
Mechanisms:
Round-robin DNS: The authoritative server returns multiple A records in rotating order. Each client gets one IP from the rotation.
Geographic DNS (GeoDNS): Returns different IPs based on the client's geographic location (inferred from IP). CDNs and global services use this to direct users to their nearest data center.
Weighted DNS: Different IPs returned with different frequencies based on configured weights.
Health-checked DNS: Authoritative server or management plane monitors backend health and removes unhealthy IPs from responses. (AWS Route 53 health checks, for example.)
Limitations:
TTL caching: Clients cache DNS responses. If a server fails, you can't instantly redirect all clients — cached records persist until TTL expires. With 5-minute TTL, 5 minutes of downtime possible.
Client-side caching bypass: Some applications (especially Java) cache DNS results forever (ignoring TTL). Fix: set networkaddress.cache.ttl in JVM.
Sticky sessions: DNS provides no session affinity. The same client may resolve to different IPs over time.
No connection-level awareness: DNS doesn't know how many active connections each server has. Round-robin sends equal query volume, not equal traffic load.
Client IP visibility: The resolver that queries for the client may not be near the client (recursive resolvers like 8.8.8.8 are globally distributed, so GeoDNS works), but accuracy depends on EDNS Client Subnet (ECS) extension.
Not suitable for fine-grained traffic splitting: For A/B testing or canary deployments, DNS-based splitting is coarse (TTL granularity).
https://www.google.com in a browser? (Full end-to-end explanation)Answer: This is one of the most common interview questions. A complete answer covers every layer.
URL parsing: Browser parses the URL: scheme=https, host=www.google.com, port=443 (default for HTTPS), path=/ .
DNS resolution: Browser checks its DNS cache (short TTL in browsers, often 60 seconds). If no cache hit, queries the OS DNS resolver, which queries the recursive resolver. www.google.com resolves to one or more IP addresses (e.g., 142.250.x.x).
TCP connection (Layer 4): Browser establishes a TCP connection to the resolved IP on port 443. Three-way handshake (SYN → SYN-ACK → ACK). Modern browsers use TCP Fast Open to save one RTT if the client and server previously communicated.
TLS handshake (Layer 6/7):
ClientHello: Browser sends supported TLS versions, cipher suites, random value, SNI (Server Name Indication — the hostname, allows virtual hosting on HTTPS), supported extensions.
ServerHello: Server selects TLS version and cipher suite, sends server random value, session ID.
Server Certificate: Server sends its X.509 certificate chain.
Certificate validation: Browser verifies: certificate is signed by a trusted CA, not expired, hostname matches (CN or SAN), not revoked (OCSP/CRL check).
Key exchange: (Varies by TLS version)
TLS 1.2: Client generates pre-master secret, encrypts with server's public key (RSA) or uses ephemeral Diffie-Hellman. Session keys derived from pre-master secret + random values.
TLS 1.3: Ephemeral ECDHE only (perfect forward secrecy mandatory). Fewer round trips (1-RTT vs 2-RTT).
ChangeCipherSpec + Finished: Both sides send Finished messages to verify key derivation.
HTTP/2 (or HTTP/3) negotiation: During TLS, ALPN (Application-Layer Protocol Negotiation) extension selects HTTP/2 or HTTP/3. Most modern connections to Google use HTTP/2 or HTTP/3.
HTTP request: Browser sends an HTTP GET request: headers include Host, User-Agent, Accept, Accept-Encoding (gzip, br), Cookie, etc.
Server processing: Google's load balancer receives the request, routes to a backend, backend generates a response.
HTTP response: Server returns 200 OK with HTML content, compressed (gzip/brotli), possibly with HTTP/2 server push.
Browser rendering: Browser parses HTML, discovers sub-resources (CSS, JS, images), makes additional DNS+TCP+TLS connections or reuses existing connections (HTTP/2 multiplexing allows multiple streams over one connection).
Connection management: HTTP/1.1: Keep-Alive reuses TCP connection. HTTP/2: multiplexes many requests over one TCP connection. Connection eventually closes (timeout or FIN).
Answer: TLS 1.2 Handshake (2 RTTs for full handshake):
Round Trip 1:
Client → Server: ClientHello (max supported version, client random, session ID, cipher suites list, compression methods, extensions including SNI, ALPN)
Server → Client: ServerHello (chosen version, server random, session ID, chosen cipher suite) + Certificate (server's cert chain) + ServerKeyExchange (if DHE/ECDHE — server's DH params signed with private key) + ServerHelloDone
Round Trip 2:
Client → Server: ClientKeyExchange (client's DH public key or RSA-encrypted pre-master secret) + ChangeCipherSpec + Finished (HMAC of all handshake messages)
Server → Client: ChangeCipherSpec + Finished (HMAC verification)
After round trip 2: Connection established. Session resumption (via session ID or session ticket) can reduce this to 1 RTT.
TLS 1.3 Handshake (1 RTT, 0-RTT possible for resumption):
Round Trip 1:
Client → Server: ClientHello (with supported_versions, key_share extension containing client's DH public key, psk_key_exchange_modes)
Server → Client: ServerHello (with key_share — server's DH public key) + {EncryptedExtensions} + {Certificate} + {CertificateVerify} + {Finished} (already encrypted with derived keys)
After Round Trip 1: Server can already send application data. Client sends {Finished} and then application data.
TLS 1.3 improvements over 1.2:
1-RTT vs 2-RTT: Faster connection establishment
0-RTT session resumption: Client can send application data in the first flight using a Pre-Shared Key from a previous session (with replay attack risks — must be idempotent requests)
Mandatory perfect forward secrecy: Only ECDHE and DHE key exchanges allowed. RSA key exchange removed. Even if the server's private key is later compromised, past sessions can't be decrypted.
Reduced cipher suites: Removed weak/broken algorithms (RC4, 3DES, MD5, SHA-1, export-grade ciphers, RSA without forward secrecy). Only 5 cipher suites: AES-128-GCM, AES-256-GCM, ChaCha20-Poly1305, AES-128-CCM, AES-128-CCM-8.
Encrypted handshake: Certificate and most handshake messages are encrypted (server's cert is private from passive observers)
Removed session renegotiation and compression (both were attack vectors)
Debug TLS:
xxxxxxxxxx# Check TLS version and cipher suiteopenssl s_client -connect www.example.com:443 -tls1_3openssl s_client -connect www.example.com:443 | grep -E "Protocol|Cipher"
# Check certificate chainopenssl s_client -connect www.example.com:443 -showcerts
# Test TLS 1.3 0-RTTcurl --tls13-ciphers TLS_AES_128_GCM_SHA256 https://www.example.comAnswer: SNI (Server Name Indication) is a TLS extension (RFC 6066) that allows a client to specify which hostname it is connecting to at the beginning of the TLS handshake, before any certificates are presented.
Problem it solves: A single server/load balancer may host many websites, each with its own TLS certificate (virtual hosting). Before SNI, the server had to pick which certificate to send without knowing which domain the client wanted, because the Host header (which identifies the virtual host in HTTP) is inside the encrypted connection — but the server needs to present the right certificate before encryption is established. Classic chicken-and-egg problem.
How it works: The client includes the target hostname in the server_name extension of the ClientHello message, which is sent before any encryption. The server reads this, selects the appropriate certificate, and proceeds with the TLS handshake.
Privacy implication: SNI is sent in cleartext in TLS 1.2 and 1.3. Anyone on the network path (ISPs, firewalls) can see which hostname you're connecting to even if the content is encrypted. This is used for:
Content filtering (block specific domains at the firewall)
TLS inspection/interception by corporate proxies
Censorship (SNI-based blocking)
ESNI / ECH (Encrypted Client Hello): A newer extension (RFC draft) that encrypts the SNI. The client fetches a public key from DNS (via HTTPS record type) and encrypts the ClientHello using it. Still being deployed.
Relevant for proxy detection: A transparent TLS-intercepting proxy will receive the SNI, terminate the TLS connection from the client, make its own TLS connection to the server, and re-encrypt traffic. The client will see a different certificate (usually from the proxy's CA) unless the proxy's CA is trusted by the client. This is the basis for corporate SSL inspection.
Answer: HTTP/1.0:
Non-persistent connections: each request requires a new TCP connection (DNS + TCP handshake + HTTP request = high latency overhead)
No Host header (no virtual hosting)
Simple: request → response → close
HTTP/1.1:
Persistent connections (Keep-Alive): Default. Multiple requests over one TCP connection.
Pipelining: Client can send multiple requests without waiting for responses. In practice, rarely used due to head-of-line blocking (a slow response blocks all subsequent responses on the connection).
Host header: Required. Enables virtual hosting.
Chunked transfer encoding: Stream response body without knowing total length.
Cache control headers: ETag, Last-Modified, Cache-Control.
Still fundamentally serial: one outstanding request at a time per connection (without pipelining). Browsers work around this by opening 6 TCP connections per origin.
HTTP/2 (RFC 7540):
Multiplexing: Multiple independent streams (requests/responses) over a single TCP connection. No head-of-line blocking at the application layer.
Binary framing: Instead of text, HTTP/2 encodes messages in binary frames. More efficient parsing.
Header compression (HPACK): HTTP headers (often large due to cookies) are compressed using a shared dynamic table. Reduces overhead dramatically.
Server Push: Server can proactively send resources (CSS, JS) before the client requests them.
Stream prioritization: Client assigns weights/dependencies to streams.
Still has TCP-level head-of-line blocking: If a TCP segment is lost, all HTTP/2 streams on that connection are blocked until the segment is retransmitted.
HTTP/3 (RFC 9114):
Based on QUIC (UDP): Eliminates TCP head-of-line blocking. Each QUIC stream is independent at the transport level; a lost UDP packet only blocks the stream it belongs to.
Integrated TLS 1.3: QUIC has TLS 1.3 built in. Handshake is 1-RTT (0-RTT for session resumption).
Connection migration: QUIC connections are identified by a Connection ID, not by IP:port tuple. If the client moves from Wi-Fi to LTE, the connection survives (no TCP teardown/re-establish needed).
Reduced latency: 0-RTT resumption + no separate TCP+TLS handshakes.
Currently used by ~25-30% of web traffic.
Answer: HTTP status codes are three-digit numbers. The first digit indicates the class:
1xx — Informational:
100 Continue: Server received request headers; client should proceed with body
101 Switching Protocols: Server is switching protocols as requested (e.g., WebSocket upgrade)
2xx — Success:
200 OK: Standard success response
201 Created: Resource was created (response to POST)
204 No Content: Success but no body (DELETE requests)
206 Partial Content: Response to Range request (video streaming, resumable downloads)
3xx — Redirection:
301 Moved Permanently: Resource permanently at new URL; browser caches this redirect
302 Found (Temporary Redirect): Temporary; don't cache
304 Not Modified: Conditional GET; cached version is still valid; no body
307 Temporary Redirect: Like 302 but preserves HTTP method (don't change POST to GET)
308 Permanent Redirect: Like 301 but preserves method
4xx — Client Error:
400 Bad Request: Malformed request syntax
401 Unauthorized: Authentication required (misleadingly named — should be "unauthenticated")
403 Forbidden: Authenticated but not authorized
404 Not Found: Resource doesn't exist
405 Method Not Allowed: HTTP method not supported for this resource
408 Request Timeout: Server timed out waiting for client
409 Conflict: Request conflicts with current state (e.g., edit conflict)
410 Gone: Resource permanently deleted (stronger signal than 404)
429 Too Many Requests: Rate limiting
451 Unavailable For Legal Reasons: (The Fahrenheit 451 reference)
5xx — Server Error:
500 Internal Server Error: Generic server-side failure
502 Bad Gateway: Upstream server returned invalid response (load balancer seeing backend failure)
503 Service Unavailable: Server temporarily unavailable (overloaded or in maintenance)
504 Gateway Timeout: Upstream server didn't respond in time
530: Used by Cloudflare for a variety of edge-specific errors (not standard)
Answer:
Same-Origin Policy (SOP): Browsers enforce a security boundary: JavaScript running on https://a.com cannot make XMLHttpRequest/fetch calls to https://b.com and read the response. This prevents malicious scripts from stealing data from other sites where the user is authenticated (CSRF-style attacks).
CORS: A mechanism that allows servers to explicitly grant permission to cross-origin requests. It works through HTTP headers.
Simple requests (GET/HEAD/POST with specific content types):
Browser sends the request with an Origin: https://a.com header
Server responds with Access-Control-Allow-Origin: https://a.com (or * for any origin)
Browser allows JavaScript to read the response if the ACAO header is present and matches
Preflight requests (non-simple: custom headers, PUT/DELETE/PATCH, JSON body):
Browser sends OPTIONS preflight with headers:
Origin: https://a.com
Access-Control-Request-Method: DELETE
Access-Control-Request-Headers: X-Custom-Header, Content-Type
Server responds:
Access-Control-Allow-Origin: https://a.com
Access-Control-Allow-Methods: GET, POST, DELETE
Access-Control-Allow-Headers: X-Custom-Header, Content-Type
Access-Control-Max-Age: 86400 (cache preflight for 24 hours)
Browser sends the actual request if preflight succeeds
Credentials (cookies):
By default, CORS requests don't include cookies
To include cookies: fetch(url, {credentials: 'include'}) + server must return Access-Control-Allow-Credentials: true AND Access-Control-Allow-Origin must be a specific origin (not *)
CORS misconfiguration risks:
Access-Control-Allow-Origin: * with Access-Control-Allow-Credentials: true is invalid (browsers reject it)
Reflecting the Origin header blindly without validation allows any site to read responses
Answer: When a router receives an IP packet, it must determine where to forward it. The process is:
Extract destination IP from the packet header.
Longest Prefix Match (LPM): Look up the routing table for the most specific matching route. The route with the longest subnet mask (highest prefix length) that matches the destination IP wins. For example, if the routing table has both 10.0.0.0/8 and 10.1.0.0/16, a packet destined for 10.1.1.1 will match 10.1.0.0/16 (more specific).
Administrative Distance (AD): If multiple routing protocols advertise the same prefix, the one with the lowest AD wins. AD values: Connected (0), Static (1), EIGRP (90), OSPF (110), RIP (120), eBGP (20), iBGP (200).
Metric: Within the same routing protocol, the route with the lowest metric is preferred. OSPF uses cost (based on bandwidth), RIP uses hop count, EIGRP uses composite metric.
Next hop resolution: The winning route specifies a next-hop IP address. The router looks up the next-hop IP in the ARP table (or Neighbor table for IPv6) to find the MAC address for the Layer 2 frame.
Frame construction: Router decrements TTL by 1 (drops packet and sends ICMP Time Exceeded if TTL reaches 0), recalculates IP header checksum, constructs new Ethernet frame with its own src MAC and next-hop dst MAC, and transmits on the appropriate interface.
View routing table:
xxxxxxxxxxip route show # Linux routing tableip route get 8.8.8.8 # Which route would be used for this destinationroute -n # Classic syntax (numeric, no DNS resolution)Special routes:
Default route (0.0.0.0/0): Matches everything; used when no more-specific route exists. "Gateway of last resort."
Host route (/32): Matches exactly one IP address. Highest specificity.
Summary route: Aggregates multiple networks into one advertisement.
Answer: OSPF (Open Shortest Path First) is a link-state interior gateway protocol (IGP) that uses Dijkstra's Shortest Path First (SPF) algorithm. Unlike distance-vector protocols (RIP), OSPF routers have a complete map of the network topology within their area.
Neighbor Discovery and Adjacency Formation:
Routers send Hello packets (multicast to 224.0.0.5) out OSPF-enabled interfaces every Hello interval (10 seconds on broadcast, 30 on non-broadcast).
Hello packets contain: Router ID, Area ID, Hello/Dead intervals, Authentication, DR/BDR info, neighbor list.
Two routers become neighbors when they see each other's Router ID in the received Hello's neighbor list.
Not all neighbors become adjacent (full database synchronization). On multi-access networks (Ethernet), routers elect a Designated Router (DR) and Backup DR (BDR) to reduce the number of adjacencies. All routers form full adjacency with only the DR/BDR.
Database Synchronization:
Adjacent routers exchange DBD (Database Description) packets — summaries of their LSDB (Link-State Database).
Routers identify missing LSAs and request them with LSR (Link State Request) packets.
Missing LSAs are sent in LSU (Link State Update) packets.
Acknowledged with LSAck packets.
When fully synchronized, adjacency state = Full.
SPF Calculation: Each router runs Dijkstra's algorithm on its complete LSDB to compute the shortest path tree to every destination, placing the best routes into the routing table.
LSA Types:
Type 1 (Router LSA): Each router's links and states within an area
Type 2 (Network LSA): Generated by DR for multi-access networks
Type 3 (Summary LSA): Inter-area routes, generated by ABR
Type 5 (AS External LSA): Routes from other routing protocols, generated by ASBR
OSPF Areas:
Area 0 (backbone area) must be contiguous and all other areas must connect to it.
Stub areas: Don't accept Type 5 LSAs. Use default route instead.
Totally Stub: Only default route.
NSSA: Can accept external routes via Type 7 LSAs.
Metric: Cost = reference bandwidth / interface bandwidth. Default reference: 100 Mbps. A 100 Mbps link has cost 1; a 10 Mbps link has cost 10.
xxxxxxxxxx# Verify OSPF neighborsshow ip ospf neighbor # Cisco IOS# On Linux (FRRouting/Quagga):vtysh -c "show ip ospf neighbor"Answer: BGP (Border Gateway Protocol) is the routing protocol of the Internet — the "glue" that holds the Internet together. It is a path-vector exterior gateway protocol (EGP) used to exchange routing information between Autonomous Systems (ASes).
Key differences from OSPF:
| Feature | OSPF | BGP |
|---|---|---|
| Type | Link-state IGP | Path-vector EGP |
| Scale | Hundreds of routers (single AS) | Hundreds of thousands of prefixes (global Internet) |
| Metric | Cost (bandwidth-based) | AS Path attributes (policy-driven) |
| Convergence | Fast (seconds) | Slow (minutes in worst case) |
| Transport | IP (protocol 89) | TCP port 179 |
| Peering | Automatic (Hello multicast) | Manual (must configure neighbors) |
| Use case | Within an organization's AS | Between ISPs, ASes |
Why BGP for the Internet:
Policy-based routing: BGP allows operators to express complex business policies (prefer certain providers, avoid certain ASes, implement traffic engineering). OSPF only minimizes a simple metric.
Scale: The global Internet routing table has ~900,000+ IPv4 prefixes. OSPF would require every router to store and compute SPF on all of these — computationally and memory infeasible. BGP routers store the table but don't run SPF.
Autonomy: Each AS sets its own routing policies independently. OSPF within an AS is fine, but cross-AS routing needs AS-level autonomy.
Aggregation: BGP naturally supports route aggregation and summarization at AS boundaries.
iBGP vs eBGP:
eBGP: Between routers in different ASes. Usually directly connected (TTL=1 by default, ebgp-multihop for non-adjacent). Routes learned via eBGP get their AS Path prepended.
iBGP: Between routers within the same AS. All iBGP routers must be fully meshed (or use Route Reflectors / Confederations) because iBGP routes are not re-advertised to other iBGP peers (split horizon rule).
BGP Attributes (for path selection):
Weight (Cisco proprietary, local significance)
Local Preference (preferred exit from AS, higher = better)
Locally Originated (prefer routes originated locally)
AS Path length (shorter = better)
Origin (IGP > EGP > Incomplete)
MED (Multi-Exit Discriminator, lower = better, suggests preferred entry point into AS)
eBGP over iBGP
IGP metric to next hop
Answer: VLAN (Virtual Local Area Network): A logical segmentation of a physical network. Devices in the same VLAN communicate as if they're on the same switch, regardless of physical location. Devices in different VLANs cannot communicate at Layer 2 without a router (or Layer 3 switch).
Benefits:
Security: Isolate sensitive segments (finance, management) from general users
Broadcast containment: Each VLAN is its own broadcast domain, reducing unnecessary broadcast traffic
Flexibility: Group users logically regardless of physical location
Simplified management: Apply consistent policies per VLAN
802.1Q VLAN Tagging: Without tagging, frames don't carry VLAN information. When a frame needs to traverse a trunk link (carrying multiple VLANs between switches), 802.1Q inserts a 4-byte tag into the Ethernet frame header:
xxxxxxxxxx[ Dest MAC (6) | Src MAC (6) | 802.1Q Tag (4) | EtherType (2) | Payload | FCS ]
802.1Q tag structure (4 bytes):
TPID (Tag Protocol Identifier): 0x8100 — indicates this is a tagged frame
PCP (Priority Code Point): 3 bits — 802.1p QoS priority (0–7)
DEI (Drop Eligible Indicator): 1 bit — formerly CFI
VID (VLAN ID): 12 bits — VLAN number (1–4094, 0 and 4095 reserved)
Access vs Trunk ports:
Access port: Belongs to one VLAN. Frames are untagged when sent to the end device. The switch adds/removes the tag transparently.
Trunk port: Carries frames from multiple VLANs, all tagged (except possibly the native VLAN). Used between switches, or between switch and router (for Router-on-a-Stick).
Native VLAN: On a trunk port, frames in the native VLAN are sent untagged (for compatibility with devices that don't understand 802.1Q). Default native VLAN is VLAN 1. Security best practice: change native VLAN to an unused VLAN to prevent VLAN hopping attacks.
Linux VLAN configuration:
xxxxxxxxxx# Create VLAN interfaceip link add link eth0 name eth0.100 type vlan id 100ip link set eth0.100 upip addr add 192.168.100.1/24 dev eth0.100
# View VLANscat /proc/net/vlan/configip -d link show eth0.100Answer: The Problem: Ethernet networks need redundant links for high availability. But redundant switch links create Layer 2 loops. Without loop prevention, a broadcast frame would circulate forever (broadcast storm), consuming all bandwidth and crashing the network within seconds. There are no TTLs in Layer 2 frames.
STP (IEEE 802.1D): Spanning Tree Protocol prevents loops by logically blocking redundant paths while keeping them available as backups. STP creates a loop-free tree topology.
STP Operation:
Root Bridge Election: The switch with the lowest Bridge ID (BID = priority + MAC address) becomes the Root Bridge. All ports on the Root Bridge are in Designated (forwarding) state.
Root Port Selection: Every non-root switch elects one Root Port — the port with the lowest-cost path to the Root Bridge (cost is based on link bandwidth).
Designated Port Selection: For each network segment, one switch's port becomes the Designated Port (forwarding). The other switch's port becomes Non-Designated (Blocked).
Port States: Blocking → Listening (15s) → Learning (15s) → Forwarding. Total convergence: ~30–50 seconds.
STP Port Roles:
Root Port (RP): Best path to Root Bridge
Designated Port (DP): Forwarding port on each segment
Non-Designated Port: Blocked to prevent loops
STP Variants:
RSTP (Rapid STP, 802.1w): Converges in seconds instead of 30–50 seconds. Introduces new port roles (Alternate, Backup) and states.
MSTP (Multiple STP, 802.1s): Maps multiple VLANs to fewer STP instances (reduces number of STP trees running on a switch).
PVST+ (Cisco): Per-VLAN Spanning Tree Plus — one STP instance per VLAN, allows load balancing across VLANs.
STP Security Issues:
Root Bridge hijacking: An attacker connects a device with priority 0, becomes Root Bridge, and all traffic flows through it.
Mitigation: BPDU Guard (disables port if it receives a BPDU on an access port), Root Guard (prevents superior BPDUs from making a port the Root Port), BPDU Filter.
Answer: NAT (Network Address Translation) modifies IP address (and sometimes port) information in packet headers as they pass through a router. Primarily used to allow multiple devices on a private network to share a single public IP address.
How NAT works (NAPT/PAT — the most common form):
Internal host (192.168.1.10:54321) sends packet to 8.8.8.8:53.
NAT router replaces source IP:port with its public IP:unique port (e.g., 203.0.113.1:45678) and records this mapping in the NAT table.
Packet arrives at destination as from 203.0.113.1:45678.
Response comes back to 203.0.113.1:45678.
NAT router looks up 45678 in NAT table, translates destination back to 192.168.1.10:54321, and forwards internally.
NAT Types:
SNAT (Source NAT): Modifies the source address. Used for outbound traffic from private network to Internet. Also called Masquerade (when the public IP is dynamic).
DNAT (Destination NAT): Modifies the destination address. Used for inbound traffic — port forwarding. "Forward all TCP connections to port 80 on my public IP to 192.168.1.100:80."
Static NAT (1:1 NAT): One private IP maps to one specific public IP. Used for servers that need a stable public IP.
Full Cone NAT: Any external host can send packets to the translated address/port. (Most permissive)
Restricted Cone NAT: External host can only send if the internal host has previously sent a packet to that external host's IP.
Port Restricted Cone NAT: Must have sent to the exact IP:port combination.
Symmetric NAT: Different external mappings are created for each destination. Makes P2P applications and VoIP difficult (ICE/STUN/TURN required).
NAT Drawbacks:
Breaks end-to-end connectivity model
Protocols that embed IP addresses in payload (FTP, SIP) require ALG (Application Level Gateway)
Complicates VPNs and firewalling
A non-issue with IPv6 (enough addresses for every device)
Linux NAT with iptables:
xxxxxxxxxx# SNAT (masquerade — for dynamic IP)iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# SNAT (for static public IP)iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 203.0.113.1
# DNAT (port forwarding: external:80 → internal:8080)iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 \ -j DNAT --to-destination 192.168.1.100:8080Answer: Unmanaged switch:
Plug-and-play; no configuration interface
Forwards frames based on MAC learning (basic Layer 2)
No VLANs, no spanning tree configuration, no QoS
No monitoring or telemetry
Suitable for small home/office setups where simplicity is paramount
Managed switch:
Full configuration via CLI, web GUI, or SNMP
VLAN support (802.1Q): Segment traffic, create access/trunk ports
STP/RSTP control: Configure root bridge priority, port costs, BPDU guard
QoS (Quality of Service): Prioritize voice/video traffic, configure queues
Port mirroring (SPAN): Copy traffic from one port to another for analysis (used with Wireshark/IDS)
SNMP monitoring: Export counters, interface statistics, error rates to NMS
LACP/802.3ad: Link aggregation — bond multiple physical links for higher throughput and redundancy
Port security: Limit MAC addresses per port, sticky MAC learning, violation actions (shutdown, restrict, protect)
ACLs at Layer 2: Filter by MAC address, EtherType
DHCP snooping: Validate DHCP messages, prevent rogue DHCP servers
Dynamic ARP Inspection (DAI): Validate ARP packets against DHCP snooping database
802.1X port-based authentication: Authenticate devices before allowing network access
Layer 3 switch (multilayer switch): Has additional routing capabilities. Can route between VLANs at wire speed in hardware (ASIC-based), much faster than routing through an external router. Replaces the need for a "Router-on-a-Stick" architecture.
Answer: A NIC is the hardware component that connects a computer to a network. It operates at Layer 1 and Layer 2.
Core functions:
Physical transmission: Converts digital data to electrical signals (copper) or light pulses (fiber)
MAC addressing: Each NIC has a burned-in 48-bit MAC address (OUI + device-specific)
Frame construction: Adds Ethernet headers, FCS (CRC) trailer
Interrupt handling: Notifies the CPU when frames arrive (or uses polling at high speeds — NAPI in Linux)
Performance features relevant to Google-scale:
Hardware offload: Modern NICs offload computation from the CPU:
TSO (TCP Segmentation Offload): NIC breaks large TCP segments into MTU-sized pieces, freeing CPU from segmenting
LRO (Large Receive Offload) / GRO (Generic Receive Offload): NIC or kernel driver coalesces multiple received segments into one large buffer before handing to the OS
Checksum offload: NIC computes TCP/IP checksums in hardware
RSS (Receive Side Scaling): Distributes received packets across multiple CPU cores using hardware hashing (src/dst IP/port) to avoid single-core bottleneck
SR-IOV (Single Root I/O Virtualization): NIC presents multiple virtual functions (VFs) to VMs, giving near-native performance in virtualized environments
Check NIC offload settings:
xxxxxxxxxxethtool -k eth0 # List all offload featuresethtool -K eth0 tso off # Disable TSO (useful for debugging)ethtool -i eth0 # Driver and firmware versionethtool -S eth0 # Interface statistics (errors, drops)ethtool eth0 # Speed, duplex, link statusRing buffers: NIC has TX and RX ring buffers. If the ring buffer fills up (CPU too slow to drain packets), packets are dropped at the NIC level before they even reach the kernel. Increase with ethtool -G eth0 rx 4096.
Answer: A router makes forwarding decisions based on destination IP address to route packets between networks. A firewall makes permit/deny decisions based on security policy — it's a policy enforcement point, not a routing device (though modern "next-gen" firewalls do both).
Stateless (packet filter) firewall:
Examines each packet independently based on static rules: source IP, destination IP, protocol, source port, destination port, TCP flags.
No memory of previous packets — doesn't track connection state.
Fast, low memory requirements.
Must explicitly allow both directions of traffic or use rules based on port ranges.
Example: iptables -A INPUT -p tcp --dport 80 -j ACCEPT (plus a corresponding rule for the return traffic).
Weakness: Cannot distinguish a legitimate TCP connection response from an unsolicited packet with ACK set.
Stateful (connection tracking) firewall:
Maintains a state table of all established connections.
When a new TCP SYN arrives and matches a permit rule, the connection state is recorded.
Return traffic (SYN-ACK, ACK, data) is automatically permitted if it matches an existing connection state — no need for explicit return rules.
Can detect TCP state anomalies (e.g., SYN-ACK without prior SYN, unexpected RST).
More secure against spoofed packets.
Example: iptables with ESTABLISHED,RELATED matching (-m state --state ESTABLISHED,RELATED -j ACCEPT).
Next-Generation Firewall (NGFW):
Layer 7 inspection: identifies application regardless of port (e.g., detect BitTorrent on port 443)
IDS/IPS integration
User-identity-based policies (Palo Alto, Cisco Firepower)
SSL/TLS inspection (MITM to decrypt and inspect HTTPS traffic)
Linux iptables example (stateful):
xxxxxxxxxx# Allow established connections (return traffic)iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow new inbound SSHiptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
# Allow new inbound HTTP/HTTPSiptables -A INPUT -p tcp -m multiport --dports 80,443 -m state --state NEW -j ACCEPT
# Default denyiptables -P INPUT DROPiptables -P FORWARD DROPAnswer: A load balancer distributes incoming network traffic across multiple backend servers to improve performance, availability, and scalability.
Layer 4 Load Balancer (Transport Layer):
Operates on IP address and TCP/UDP port information only. Cannot see application-layer data.
Makes routing decisions based on src/dst IP, src/dst port, protocol.
Typical implementation: NAT-based (DSR or NAT mode) or IP tunneling.
Extremely fast — decisions are made in hardware or kernel-bypass (DPDK, XDP).
Cannot perform content-based routing (can't look at URL paths or HTTP headers).
Examples: AWS NLB, LVS (Linux Virtual Server), hardware load balancers in DSR mode.
DSR (Direct Server Return): Backend servers respond directly to the client (bypassing the load balancer for the return path) by using the VIP as their own IP. Dramatically reduces load balancer load for asymmetric traffic (large downloads).
Layer 7 Load Balancer (Application Layer):
Full HTTP/HTTPS termination. The load balancer is a full TCP/TLS proxy.
Can route based on: URL path, HTTP headers (Host, Cookie), query parameters, request body.
Supports: SSL termination, HTTP compression, caching, WebSocket upgrade, gRPC.
Can do health checks at the application level (check if /health returns 200).
More CPU-intensive than L4 due to full packet parsing.
Examples: NGINX, HAProxy (L7 mode), AWS ALB, Google Cloud Load Balancing, Envoy.
Load balancing algorithms:
Round Robin: Requests distributed sequentially. Simple, works well for uniform requests.
Weighted Round Robin: Servers get proportional share based on weight. Useful for heterogeneous backends.
Least Connections: Send to the server with fewest active connections. Better for long-lived connections.
Weighted Least Connections: Combines connection count and server weight.
IP Hash: Hash source IP to consistently route the same client to the same server (basic session persistence). Breaks if server pool changes.
Consistent Hashing: Uses a hash ring — adding/removing servers only remaps a small fraction of traffic (used by CDNs and distributed caches).
Random: Random selection with two choices, pick the less loaded one (Power of Two Choices) — near-optimal in practice.
EWMA (Exponentially Weighted Moving Average): Route to server with lowest recent response time (used by Envoy).
Answer: A proxy is an intermediary that acts on behalf of another party in a network communication.
Forward Proxy:
Sits between clients and the Internet. Clients are configured (explicitly) to use the proxy.
Client sends request to proxy; proxy forwards to target server on client's behalf.
The target server sees the proxy's IP, not the client's IP (anonymization).
Use cases:
Content filtering (block social media, malware sites)
Caching (cache frequently accessed resources, reduce bandwidth)
Bypassing geo-restrictions
Logging/monitoring of outbound traffic
Anonymity (TOR is an extreme example)
Examples: Squid, corporate web proxy, HTTP_PROXY/HTTPS_PROXY environment variables.
Reverse Proxy:
Sits between the Internet and backend servers. Clients don't know it exists.
Accepts connections from external clients and forwards to internal backends.
Use cases:
Load balancing across multiple backend servers
SSL termination (offload TLS processing from backend servers)
Caching static content (CDN-like behavior)
WAF (Web Application Firewall)
Hiding backend topology
A/B testing, canary deployments
Rate limiting, DDoS protection
Examples: NGINX (most common), HAProxy, Apache mod_proxy, Envoy, AWS ALB.
Transparent Proxy:
A proxy that intercepts traffic without client configuration. The client doesn't know there's a proxy.
Typically implemented using iptables/firewall rules to redirect traffic to the proxy process (e.g., all TCP port 80 traffic redirected to port 3128 on the gateway).
Used by ISPs for caching, corporate networks for monitoring, and attackers for MITM.
Detection: Compare source IP at server to what client expects; observe unexpected certificates in HTTPS; check for Via/X-Forwarded-For headers in HTTP responses; timing anomalies.
Answer:
CIDR (Classless Inter-Domain Routing) notation expresses an IP address and its subnet mask together. Format: IP/prefix_length. Example: 192.168.1.0/24.
The prefix length indicates how many bits (from the left) are the network portion. The remaining bits are the host portion.
Example: 192.168.10.50/26
Prefix length = 26, so network bits = 26, host bits = 32 - 26 = 6.
Subnet mask: 26 bits set to 1: 11111111.11111111.11111111.11000000 = 255.255.255.192
Network address: AND the IP with the subnet mask:
192.168.10.50 = 11000000.10101000.00001010.00110010
255.255.255.192 = 11111111.11111111.11111111.11000000
AND = 11000000.10101000.00001010.00000000 = 192.168.10.0
Broadcast address: Set all host bits to 1: 192.168.10.00111111 = 192.168.10.63
Host range: Network + 1 to Broadcast - 1: 192.168.10.1 – 192.168.10.62
Number of hosts: 2^6 - 2 = 64 - 2 = 62 usable host addresses
Common prefix lengths:
| CIDR | Mask | Hosts | Usage |
|---|---|---|---|
| /8 | 255.0.0.0 | 16M | Large orgs, Class A |
| /16 | 255.255.0.0 | 65534 | Medium orgs |
| /24 | 255.255.255.0 | 254 | Common LAN |
| /25 | 255.255.255.128 | 126 | Half-split /24 |
| /26 | 255.255.255.192 | 62 | |
| /28 | 255.255.255.240 | 14 | Small subnets |
| /30 | 255.255.255.252 | 2 | Point-to-point links |
| /31 | 255.255.255.254 | 2 (RFC 3021) | P2P, no broadcast |
| /32 | 255.255.255.255 | 1 | Host route, loopback |
Quick calculation:
xxxxxxxxxxipcalc 192.168.10.50/26 # ipcalc toolpython3 -c "import ipaddress; n=ipaddress.ip_network('192.168.10.0/26'); print(n.network_address, n.broadcast_address, n.num_addresses)"Answer: RFC 1918 defines three blocks of IPv4 addresses reserved for private use. These addresses are not routed on the public Internet:
| Range | CIDR | Size |
|---|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | 16,777,216 addresses |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | 1,048,576 addresses |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | 65,536 addresses |
Why they exist:
IPv4 exhaustion: IPv4 provides only ~4.3 billion addresses, insufficient for every device. Private ranges allow organizations to use any addressing internally, with NAT mapping to one or a few public IPs.
Security by default: Private addresses are not routable from the Internet, providing implicit separation between internal and external networks.
Cost: Organizations don't need to purchase public IP address space for every device.
Other special ranges:
127.0.0.0/8: Loopback (127.0.0.1 most common)
169.254.0.0/16: Link-local (APIPA — automatically assigned when DHCP fails)
100.64.0.0/10: Shared address space (RFC 6598) — for ISP CGN (Carrier-Grade NAT)
0.0.0.0/8: "This" network
255.255.255.255: Limited broadcast
IPv6 equivalents:
fc00::/7 (fc00::/8 and fd00::/8): Unique local addresses (RFC 4193) — equivalent to RFC 1918
fe80::/10: Link-local addresses (automatically assigned)
::1/128: Loopback
Answer: To divide a /24 into 4 equal subnets, we need 2 additional bits (2² = 4). New prefix: /24 + 2 = /26.
Each /26 has 2^6 = 64 addresses, 62 usable hosts.
| Subnet | Network | Range | Broadcast |
|---|---|---|---|
| Subnet 1 | 10.0.0.0/26 | 10.0.0.1 – 10.0.0.62 | 10.0.0.63 |
| Subnet 2 | 10.0.0.64/26 | 10.0.0.65 – 10.0.0.126 | 10.0.0.127 |
| Subnet 3 | 10.0.0.128/26 | 10.0.0.129 – 10.0.0.190 | 10.0.0.191 |
| Subnet 4 | 10.0.0.192/26 | 10.0.0.193 – 10.0.0.254 | 10.0.0.255 |
Mental model: Each subnet starts at a multiple of 64: 0, 64, 128, 192.
For any subnetting problem:
Number of subnets needed → log₂(n) additional bits borrowed from host portion
New prefix = old prefix + borrowed bits
Block size = 256 / number of subnets (for a /24 → /26: 256/4 = 64)
Answer: This is a broad, open-ended problem. Good troubleshooting is systematic, top-down or bottom-up, and eliminates possibilities efficiently.
Step 1: Clarify and scope
Slow for whom? One user, one site, all users, one application?
Which applications? All applications or specific ones (HTTP, SSH, video conferencing)?
When did it start? Any recent changes (deployments, config changes, hardware)?
How slow? Quantify: latency increase? Throughput decrease? Both?
Network path: local LAN, WAN, specific destination?
Step 2: Isolate the layer
Layer 1 — Physical:
xxxxxxxxxxethtool eth0 # Check link speed, duplex, carrierip link show # Check for UP/DOWN statecat /proc/net/dev # Check for hardware errors (RX/TX errors, drops)ethtool -S eth0 | grep -i err # NIC statistics for errorsLayer 2 — Data Link:
xxxxxxxxxxip neigh show # ARP table — any incomplete/stale entries?bridge fdb show # MAC table on bridges# Check for duplex mismatch: one side shows half-duplex while other is fullLayer 3 — Network:
xxxxxxxxxxping -c 10 <gateway> # Test basic L3 connectivity, measure RTT and losstraceroute -n <destination> # Find where latency is introducedmtr <destination> # Continuous traceroute with statisticsip route show # Verify routes are correctLayer 4 — Transport:
xxxxxxxxxxss -s # Connection summary (TIME_WAIT, CLOSE_WAIT counts)ss -tin # TCP socket info with internal TCP state# Look for retransmit counters increasingwatch -n1 'ss -s'Layer 7 — Application:
xxxxxxxxxxcurl -w "@curl-format.txt" -o /dev/null -s http://target/ # Detailed timing breakdown# curl-format includes: time_namelookup, time_connect, time_appconnect, time_pretransfer, time_starttransfer, time_totalStep 3: Check system resources
xxxxxxxxxxtop / htop # CPU saturation?free -m # Memory pressure causing swap?iostat -x 1 # Disk I/O (if NFS or disk-backed service)netstat -i # Interface error countersStep 4: Packet capture
xxxxxxxxxxtcpdump -i eth0 -n -c 1000 'host <target>' # Capture traffic to suspect host# Look for: retransmissions, duplicate ACKs, zero windows, RSTs, ICMP errorsStep 5: Compare against baseline If you have monitoring (Prometheus, Grafana, Google's Monarch), compare current metrics against historical baseline. Changes often coincide with network events.
Answer: Packet loss causes TCP retransmissions, increased latency, and reduced throughput. Here's a systematic approach:
Step 1: Confirm and quantify packet loss
xxxxxxxxxx# Basic connectivity testping -c 100 -i 0.2 <destination> # Send 100 pings, report loss %ping -f -c 10000 <destination> # Flood ping (may need root)
# Better: mtr for continuous per-hop statisticsmtr --report --report-cycles 100 <destination># Shows: packet loss, avg/min/max latency per hopStep 2: Locate where loss is occurring (per-hop)
xxxxxxxxxxmtr -n <destination> # Identifies which hop starts showing loss# Key interpretation: if hop 5 shows 5% loss but hops 6-10 show 0%,# the loss at hop 5 is just rate-limiting of ICMP (not real packet loss)# Real loss = loss that persists through all subsequent hopsStep 3: Distinguish loss types
NIC/driver level drops:
xxxxxxxxxxethtool -S eth0 | grep -i 'drop\|miss\|error'cat /proc/net/dev # RX/TX errors and dropsKernel queue drops (softirq, ring buffer):
xxxxxxxxxxnetstat -s | grep -i 'failed\|error\|drop\|overflow'# "receive buffer errors" = socket receive buffer full (application too slow)# "segments retransmitted" = TCP retransmissionscat /proc/net/softnet_stat # Per-CPU softirq stats (drops column)Traffic shaping / QoS drops:
xxxxxxxxxxtc -s qdisc show dev eth0 # Show queuing discipline stats (drops)Step 4: Capture and analyze with tcpdump/Wireshark
xxxxxxxxxxtcpdump -i eth0 -w /tmp/capture.pcap 'host <target>' -c 50000
# In Wireshark:# Filter: tcp.analysis.retransmission# Filter: tcp.analysis.duplicate_ack# Filter: tcp.analysis.fast_retransmission# Filter: tcp.analysis.lost_segment# Statistics > TCP Stream Graphs > Time-Sequence Graph (shows gaps)Step 5: Identify the cause
Random loss: Line quality issue, congestion, faulty cable/transceiver, duplex mismatch
Burst loss: Buffer overflow at a congestion point
Unidirectional loss: Asymmetric routing issue, one-way firewall rule
Application-specific loss: MTU black hole, firewall blocking specific flows
tcpdump signs of loss:
xxxxxxxxxx# Look for retransmissions (same sequence number sent twice)tcpdump -i eth0 -n 'tcp' | grep 'seq'
# Calculate retransmission rate (from netstat)netstat -s | grep retransmitAnswer: Latency has many possible root causes at different layers. Systematic investigation:
Establish baseline RTT:
xxxxxxxxxxping -c 20 <destination># Note: min RTT ≈ propagation delay (physics limit, ~1ms/100km for fiber)# avg - min = queuing + processing delayPropagation delay (unavoidable physics): Speed of light in fiber ≈ 200,000 km/s. NYC to London (~5500 km) ≈ 27ms one-way minimum. If measured latency < theoretical minimum, something is wrong (proxy caching? Anycast?). If much higher, look for sub-optimal routing.
xxxxxxxxxxtraceroute -n <destination> # Geographic hops?mtr -n <destination> # Which hop adds significant latency?Queuing delay (congestion): Symptoms: latency varies with time of day, high throughput correlates with high latency, TCP throughput well below link capacity.
xxxxxxxxxx# Bandwidth test to saturate linkiperf3 -c <server> -t 30 # TCP throughput test# While running, check:tc -s qdisc show dev eth0 # Queue statsDNS lookup delay:
xxxxxxxxxxtime dig www.example.com # How long does DNS take?curl -w "%{time_namelookup}\n" -o /dev/null -s http://target/TCP connection setup delay:
xxxxxxxxxxcurl -w "%{time_connect}\n" -o /dev/null -s http://target/# If high: could be SYN backlog on server, firewall policy delay, etc.
# Check for SYN backlog (server side)ss -lnt | grep ':80'netstat -s | grep 'SYNs to LISTEN'TLS handshake overhead:
xxxxxxxxxxcurl -w "%{time_appconnect} - %{time_connect}\n" -o /dev/null -s https://target/# Difference = TLS handshake timeApplication processing time (TTFB):
xxxxxxxxxxcurl -w "%{time_starttransfer} - %{time_appconnect}\n" -o /dev/null -s https://target/# High TTFB = slow application, not networkHead-of-line blocking (HTTP/1.1): Each TCP connection can only process one request at a time. Slow upstream resource blocks all resources queued behind it. Solution: HTTP/2 multiplexing or multiple parallel connections.
Bandwidth delay product:
xxxxxxxxxx# BDP = bandwidth * RTT# Example: 1Gbps link, 100ms RTT: BDP = 125MB# TCP window must be >= BDP to fully utilize the linksysctl net.core.rmem_max # Must be >= BDPsysctl net.ipv4.tcp_window_scaling # Should be 1 (enabled)Answer: Traceroute discovers the path packets take through the network by sending probes with incrementally increasing TTL values. When a router decrements TTL to 0, it drops the packet and sends an ICMP Time Exceeded back to the source. By recording which router sent the ICMP reply, traceroute builds a path map.
Mechanism:
Send probe with TTL=1 → first router drops it, sends ICMP TTL Exceeded → record router 1's IP and RTT
Send probe with TTL=2 → second router sends ICMP → record router 2
Continue until destination reached (ICMP Port Unreachable for UDP probes, or ICMP Echo Reply for ICMP probes)
Linux traceroute variants:
xxxxxxxxxxtraceroute -n 8.8.8.8 # UDP probes (default on Linux), -n = no DNS resolutiontraceroute -I 8.8.8.8 # ICMP Echo probes (like Windows tracert)traceroute -T -p 80 8.8.8.8 # TCP SYN probes (port 80) — bypasses ICMP blockstraceroute -T -p 443 8.8.8.8 # TCP probes to HTTPS
mtr -n 8.8.8.8 # Interactive, continuous — much more usefulSample output interpretation:
xxxxxxxxxx1 10.0.0.1 1.2 ms2 192.0.2.1 5.1 ms3 * * * # No response4 198.51.100.1 50.2 ms5 8.8.8.8 52.1 ms
Asterisks (* * *):
Router does not send ICMP TTL Exceeded (ICMP rate limiting or firewall drops)
Does NOT necessarily mean packet loss at that hop — if subsequent hops respond, packets are getting through
Some routers deprioritize ICMP generation under load
Misleading results:
ICMP rate limiting: Routers often rate-limit ICMP TTL Exceeded responses. Probes may time out even when data flows fine.
Asymmetric routing: Forward and return paths may be different. Traceroute shows the return path of ICMP replies, which may differ from the data path.
MPLS networks: Traffic travels inside MPLS tunnels; intermediate LSRs are invisible (may see two hops with large RTT jump).
Anycast: The final hop might be a different physical host depending on load, so RTT to destination may be inconsistent.
Per-flow load balancing (ECMP): Each traceroute probe may take a different path if ECMP hashes differently. Paris-traceroute fixes this by keeping the 5-tuple constant.
xxxxxxxxxx# Paris-traceroute: maintains flow identity across probesparis-traceroute 8.8.8.8# Or use:mtr --mpls --show-ips -n 8.8.8.8ss and how does it compare to netstat? Show common use cases.Answer:
ss (socket statistics) is the modern replacement for netstat. It uses the kernel's netlink socket interface rather than reading /proc/net/tcp (which requires parsing text files), making it significantly faster, especially on systems with many connections.
Common ss invocations:
xxxxxxxxxx# All TCP connections (numeric, all states)ss -tan
# All listening socketsss -tlnp # TCP listening, with process name (-p)ss -ulnp # UDP listening
# Established connections onlyss -tn state established
# Connection summary by statess -s
# Filter by portss -tn dport = :443ss -tn sport = :80
# Filter by addressss -tn dst 10.0.0.1
# Show TCP internal info (RTT, congestion window, retransmits)ss -tin# Output includes: rto, rtt, cwnd, ssthresh, bytes_acked, bytes_received, segs_out, segs_in, retrans
# Count connections by statess -tan | awk '{print $1}' | sort | uniq -c | sort -rn
# Monitor connections to a specific portwatch -n1 'ss -tn dport = :80 | wc -l'
# Unix domain socketsss -x
# Show connections with process info (requires root for other users' processes)ss -tnpss -tin internals explained:
xxxxxxxxxxState Recv-Q Send-Q Local:Port Peer:PortESTAB 0 0 10.0.0.1:58234 8.8.8.8:443cubic wscale:7,7 rto:204 rtt:3.5/0.75 ato:40 mss:1448 pmtu:1500rcvmss:1448 advmss:1448 cwnd:10 bytes_acked:2048 bytes_received:4096segs_out:10 segs_in:8 send 33.1Mbps lastsnd:100 lastrcv:50 lastack:50retrans:0/0 rcv_rtt:5.2 rcv_space:29200 rcv_ssthresh:29200
Recv-Q: bytes received but not yet read by application (backlog)
Send-Q: bytes sent but not acknowledged
rtt: current smoothed RTT
cwnd: congestion window in MSS units
retrans:0/0: current/total retransmissions
netstat equivalents:
xxxxxxxxxxnetstat -tulnp → ss -tulnpnetstat -s → ss -s (+ nstat for per-protocol counters)netstat -rn → ip route shownetstat -i → ip -s link show