Theme
Computer Networks: Complete MCQ Revision Notes β
Legend: β = asked very often Β· β οΈ = trap Β· All numerical examples were checked by running code. (Cryptography and network security are in the separate file 04_Crypto_Network_Security_Revision.md.)
Contents
- Basics (types, topologies, switching, delays)
- OSI and TCP/IP models, devices
- Physical layer
- Data link layer (framing, errors, ARQ, MAC protocols, Ethernet, Wi-Fi, ARP)
- Network layer (IPv4, subnetting, header, fragmentation, IPv6, ICMP, NAT, DHCP, routing)
- Transport layer (UDP, TCP, congestion control)
- Application layer (ports, DNS, HTTP, email, FTP, SNMP)
- Rapid-fire trap list
1. Basics β
- By scale: PAN (~10 m; Bluetooth), LAN (building/campus; Ethernet, Wi-Fi), MAN (city; cable TV, WiMAX), WAN (country/global; the Internet). Also CAN (campus), SAN (storage).
1.1 Topologies ββ β
| Topology | Links for n devices | Notes |
|---|---|---|
| Mesh (full) | n(n β 1)/2 links; n β 1 ports per device | Most robust, most expensive |
| Star | n links (to a hub/switch) | Central device failure kills the network; easy to install and troubleshoot |
| Bus | 1 backbone + n drop lines | Cheap; backbone failure kills everything; collisions |
| Ring | n links | Token passing; one break can stop the ring (dual ring in FDDI) |
| Tree, hybrid |
- Transmission modes: simplex (one way: keyboard, TV broadcast), half-duplex (both ways, one at a time: walkie-talkie), full-duplex (both ways at once: telephone).
1.2 Switching ββ β
| Circuit switching | Packet switching (datagram) | Virtual circuit |
|---|---|---|
| Dedicated path reserved; setup phase; telephone network | Each packet routed independently; no setup; the Internet (IP) | Setup phase, then all packets follow the same path; VCI labels; ATM, Frame Relay, MPLS |
| Guaranteed bandwidth, wasted when idle | Efficient; packets may be reordered or lost; store-and-forward | In-order delivery |
Message switching = store-and-forward of whole messages (old telegraph networks).
1.3 Delays βββ β
- Transmission delay = L / R (packet size in bits / link bandwidth).
- Propagation delay = d / s (distance / signal speed β 2 Γ 10βΈ m/s in cable and fiber, 3 Γ 10βΈ m/s in air).
- Plus queuing delay and processing delay. Store-and-forward over N links: end-to-end β NΒ·(L/R) + NΒ·d_prop (ignoring queuing and processing).
- RTT β 2 Γ propagation delay (plus other delays). Bandwidthβdelay product = bandwidth Γ propagation delay = the most bits that can be "in the pipe".
- Throughput = actual data rate (β€ bandwidth); the bottleneck link sets end-to-end throughput.
- Standards bodies: IEEE (802.x LANs), IETF (RFCs, Internet protocols), ISO (OSI model), ITU-T (telecom), ANSI, W3C (web), IANA/ICANN (IP addresses, port numbers, domain names), regional registries (APNIC for Asia-Pacific).
2. OSI and TCP/IP Models βββ β
OSI (ISO, 7 layers). Bottom-up mnemonic: "Please Do Not Throw Sausage Pizza Away".
| # | Layer | PDU | Key functions | Protocols / devices |
|---|---|---|---|---|
| 7 | Application | Data / message | Network services for user applications | HTTP, FTP, SMTP, DNS, Telnet, SSH, SNMP, DHCP |
| 6 | Presentation | Data | Translation (formats, ASCII β EBCDIC), encryption/decryption, compression | SSL/TLS (often mapped here), JPEG, MPEG, GIF, MIME |
| 5 | Session | Data | Dialog control (half/full duplex), synchronization (checkpoints), session setup/teardown, token management | NetBIOS, RPC |
| 4 | Transport | Segment (TCP) / datagram (UDP) | Process-to-process (end-to-end) delivery, port addressing, segmentation and reassembly, end-to-end flow and error control, connection control | TCP, UDP, SCTP |
| 3 | Network | Packet (datagram) | Logical (IP) addressing, routing, host-to-host delivery, fragmentation | IP, ICMP, IGMP, OSPF; router, L3 switch |
| 2 | Data link | Frame | Framing, physical (MAC) addressing, hop-to-hop flow and error control (CRC trailer), media access control. Sublayers: LLC (802.2) + MAC | Ethernet, PPP, HDLC, 802.11; switch, bridge, NIC |
| 1 | Physical | Bit | Bit transmission, encoding/signaling, data rate, bit synchronization, physical topology, transmission mode, connectors | Cables, RJ-45, hub, repeater, modem |
Quick "which layer?" answers ββ:
Routing β Network Β· framing β Data link Β· dialog control / synchronization / token management β Session Β· encryption, compression, translation β Presentation Β· end-to-end delivery and port numbers β Transport Β· MAC address β Data link Β· IP address β Network Β· voltages / bit encoding β Physical.
Error detection: data link (CRC trailer) and transport (TCP/UDP checksum). Congestion control: transport (TCP), also network. Only the data link layer adds a trailer.
TCP/IP model: Application (= OSI 5β7) | Transport | Internet | Network access / link (= OSI 1β2). Kurose and Forouzan teach a 5-layer version: Application, Transport, Network, Link, Physical. TCP/IP came first (ARPANET/DoD); OSI is a reference model.
Encapsulation: each layer adds a header (data link adds header + trailer); the receiver decapsulates.
Addresses: physical/MAC (48-bit, L2, changes at every hop), logical/IP (32-bit IPv4, 128-bit IPv6, L3, end-to-end except with NAT), port (16-bit, L4, identifies the process), application-specific (URL, email).
2.1 Devices βββ β
| Device | Layer | Collision domains | Broadcast domains | Notes |
|---|---|---|---|---|
| Repeater | 1 | Doesn't split | Doesn't split | Regenerates the signal (an amplifier also boosts noise) |
| Hub | 1 | One for all ports | One | Multiport repeater; half duplex |
| Bridge | 2 | Splits (one per port) | One | Filters by MAC; joins LAN segments |
| Switch | 2 (L3 switches exist) | One per port | One (unless VLANs) | Multiport bridge; MAC/CAM table; full duplex |
| Router | 3 | One per interface | One per interface (stops broadcasts) | Routes by IP; joins different networks |
| Gateway | Up to 7 | Protocol converter between different architectures | ||
| Modem | 1 | Modulatorβdemodulator: digital β analog | ||
| NIC | 1 and 2 | Holds the MAC address | ||
| Brouter | 2 and 3 | Bridge + router | ||
| Firewall | 3 / 4 / 7 | Filters traffic |
Example: a router with 2 interfaces, each to a switch with 5 hosts β 2 broadcast domains, 12 collision domains (each switch: 5 host ports + 1 uplink). With hubs instead of switches β 2 collision domains.
3. Physical Layer β
- Guided media: twisted pair (UTP/STP; twisting reduces crosstalk/EMI; RJ-45; Cat5e β 1 Gbps, Cat6 β 10 Gbps up to ~55 m, Cat6a β 10 Gbps at 100 m), coaxial (BNC; cable TV, old 10Base2/10Base5 Ethernet), fiber optic (light by total internal reflection; single-mode: thin core, laser, long distance; multimode: LED, shorter runs; immune to EMI, highest bandwidth, lowest attenuation, hard to tap).
- Unguided media: radio waves (3 kHzβ1 GHz; omnidirectional; pass through walls), microwaves (1β300 GHz; unidirectional, line of sight; satellite and cellular), infrared (300 GHzβ400 THz; short range; blocked by walls; remotes).
- Impairments: attenuation (loss of energy, in dB; fixed with amplifiers/repeaters), distortion (frequency components arrive at different times), noise (thermal, induced, crosstalk, impulse).
- dB = 10Β·logββ(P2/P1). SNR_dB = 10Β·logββ(SNR).
3.1 Capacity formulas βββ β
- Nyquist (noiseless channel): max bit rate = 2Β·BΒ·logβ(L) (B = bandwidth in Hz, L = signal levels). 3 kHz with 2 levels β 6 kbps; with 4 levels β 12 kbps.
- Shannon (noisy channel): capacity C = BΒ·logβ(1 + SNR) (SNR as a ratio, not dB). B = 3,000 Hz, SNR = 3,162 (β 35 dB) β β 34.9 kbps. B = 4 kHz, SNR = 63 β 4,000 Γ 6 = 24 kbps. SNR = 0 β C = 0.
- Shannon gives the upper limit; Nyquist tells how many levels you need.
- Bit rate = baud rate Γ logβ(L) (baud = signal elements per second).
3.2 Encoding, modulation, multiplexing β
- Line coding: NRZ-L, NRZ-I, RZ, Manchester (a transition in the middle of every bit β self-clocking; 10 Mbps Ethernet; needs twice the bandwidth), Differential Manchester (Token Ring), AMI (bipolar), B8ZS/HDB3 (scrambling). Block coding: 4B/5B (Fast Ethernet), 8B/10B (Gigabit over fiber), 64B/66B (10 GbE).
- Digital β analog modulation: ASK, FSK, PSK, QAM (amplitude + phase; most bandwidth-efficient). Analog β analog: AM, FM, PM. Analog β digital: PCM (sample at β₯ 2 Γ the highest frequency, the Nyquist sampling theorem), delta modulation.
- Multiplexing: FDM (analog; radio/TV), WDM (optical FDM), TDM (synchronous = fixed slots; statistical = slots on demand), CDMA (codes).
- Spread spectrum: FHSS (Bluetooth), DSSS (802.11b).
4. Data Link Layer βββ β
4.1 Framing β
- Character count; byte stuffing (flag + ESC byte; PPP); bit stuffing (HDLC flag 01111110; after five consecutive 1s insert a 0); physical-layer coding violations.
- Bit-stuffing example (checked): 011111110 β 0111110110.
4.2 Error detection and correction βββ β
- Single-bit error vs burst error (length = first to last corrupted bit).
- Parity: simple even/odd parity detects all odd numbers of bit errors and misses even numbers. 2-D parity detects all 1-, 2- and 3-bit errors and can correct single-bit errors; misses some 4-bit patterns.
- Internet checksum: 16-bit one's-complement sum, then complemented. Used by the IPv4 header, TCP, UDP, ICMP. The receiver's sum including the checksum must be all 1s.
- CRC ββ: generator polynomial of degree r (r + 1 bits). The sender appends r zeros, divides by the generator using mod-2 (XOR) division, and sends the r-bit remainder (the CRC) after the data. The receiver divides the codeword; remainder 0 β no error detected.
- Detects all single-bit errors; all double-bit errors (with a suitable generator); all odd-numbered errors if (x + 1) is a factor; all bursts of length β€ r. Ethernet uses CRC-32.
- Example (checked): data 1101011111, generator 10011 (xβ΄ + x + 1) β CRC 0010 β send 11010111110010.
- Example: data 1101, generator 1011 (xΒ³ + x + 1) β CRC 001 β send 1101001.
- Hamming distance rules ββ: to detect s errors you need d_min β₯ s + 1; to correct t errors you need d_min β₯ 2t + 1.
- Hamming code: check bits r for m data bits satisfy 2^r β₯ m + r + 1 (m = 4 β r = 3, giving Hamming(7,4); m = 7 β 4; m = 8 β 4; m = 16 β 5; m = 32 β 6). Parity bits sit at positions 1, 2, 4, 8, β¦; parity bit p covers positions whose binary index includes p. The syndrome gives the error position. Example (even parity): data 1011 β codeword 0110011. Single-error correction (SEC); SEC-DED with one extra parity bit.
- Forward error correction (FEC) vs retransmission (ARQ).
4.3 Flow and error control (ARQ) βββ β
Let Tt = transmission time = L/B, Tp = propagation delay, a = Tp/Tt, k = sequence-number bits.
| Protocol | Sender window | Receiver window | Retransmits | Efficiency (no errors) |
|---|---|---|---|---|
| Stop-and-wait | 1 | 1 | The same frame on timeout; 1-bit sequence numbers (0/1) | Ξ· = 1 / (1 + 2a) |
| Go-Back-N | β€ 2^k β 1 | 1 | The lost frame and everything after it; cumulative ACKs | Ξ· = N / (1 + 2a) (max 1) |
| Selective Repeat | β€ 2^(kβ1) | = sender window | Only lost/corrupted frames; NAKs; receiver buffers and reorders | Ξ· = W / (1 + 2a) (max 1) |
- Throughput = Ξ· Γ bandwidth. Full utilization needs W β₯ 1 + 2a. Bits needed: GBN 2^k β₯ W + 1; SR 2^k β₯ 2W.
- Example (checked): 1 Mbps, 1,000-bit frames (Tt = 1 ms), Tp = 2 ms β a = 2 β stop-and-wait Ξ· = 1/5 = 20% (200 kbps); full use needs a window of 5.
- Piggybacking: ACKs carried inside data frames (full duplex).
4.4 Multiple access βββ β
Random access
- Pure ALOHA: send any time; vulnerable time = 2Β·T_fr; S = GΒ·e^(β2G); max 18.4% at G = 0.5.
- Slotted ALOHA: send only at slot boundaries; vulnerable time = T_fr; S = GΒ·e^(βG); max 36.8% at G = 1.
- CSMA (listen before talking): 1-persistent (send as soon as idle; used by Ethernet; most collisions), non-persistent (wait a random time if busy), p-persistent (slotted; send with probability p).
- CSMA/CD (wired Ethernet, 802.3): detect the collision while sending β jam signal β binary exponential backoff. Requirement Tt β₯ 2Β·Tp, so minimum frame size = 2Β·TpΒ·B. Classic Ethernet: 512 bits = 64 bytes (slot time 51.2 Β΅s at 10 Mbps). Efficiency β 1/(1 + 6.44a) (Kurose approximates 1/(1 + 5a)).
- Example (checked): 10 Mbps, 2 km cable, 2 Γ 10βΈ m/s β Tp = 10 Β΅s β L_min = 2 Γ 10 Β΅s Γ 10 Mbps = 200 bits.
- Binary exponential backoff: after the nth collision pick K from {0, β¦, 2^n β 1} (n capped at 10, so K β€ 1023) and wait K Γ slot time; give up after 16 attempts.
- CSMA/CA (wireless 802.11): collisions can't be detected reliably (hidden-station problem, half-duplex radios), so they are avoided: IFS (DIFS/SIFS), random backoff (contention window), ACKs, optional RTS/CTS with NAV (virtual carrier sensing).
Controlled access: reservation, polling (primary/secondary; poll and select), token passing (Token Ring 802.5, Token Bus 802.4, FDDI). Channelization: FDMA, TDMA, CDMA.
4.5 Ethernet (IEEE 802.3) βββ β
- Frame: Preamble 7 B + SFD 1 B | Destination MAC 6 | Source MAC 6 | Type/Length 2 | Data 46β1500 | CRC 4. Frame size excluding preamble/SFD = 64 to 1,518 bytes (1,522 with an 802.1Q tag). MTU = 1,500 bytes. Jumbo frames β 9,000.
- Connectionless and unreliable at L2 (no ACKs).
- Variants: 10Base5 (thick coax, 500 m), 10Base2 (thin coax, 185 m), 10Base-T (twisted pair, 100 m), 10Base-F (fiber); Fast Ethernet 100Base-TX; Gigabit 1000Base-T (Cat5e), 1000Base-SX/LX (fiber); 10GBase-T. "10Base-T" = 10 Mbps, baseband, twisted pair. Classic 5-4-3 rule: β€ 5 segments, 4 repeaters, 3 populated segments.
- MAC address: 48 bits (6 bytes, hex, e.g., 00:1A:2B:3C:4D:5E). First 24 bits = OUI (vendor). Broadcast = FF:FF:FF:FF:FF:FF. Least significant bit of the first byte: 0 = unicast, 1 = multicast.
- Switches: learn source MACs into the MAC (CAM) table; forward/filter by destination; flood unknown unicast and broadcast frames. Store-and-forward vs cut-through vs fragment-free switching.
- STP (802.1D Spanning Tree Protocol): stops loops and broadcast storms in redundant switched networks; elects the root bridge (lowest bridge ID = priority + MAC); blocks redundant ports. RSTP (802.1w) converges faster.
- VLAN (802.1Q): logical broadcast domains on one switch; 4-byte tag with a 12-bit VLAN ID (4,094 usable). Trunk vs access ports. Traffic between VLANs needs a router or L3 switch.
- IEEE numbers: 802.1 (bridging: 802.1Q VLAN, 802.1D STP, 802.1X port-based authentication/EAP), 802.2 LLC, 802.3 Ethernet, 802.4 Token Bus, 802.5 Token Ring, 802.11 Wi-Fi, 802.15.1 Bluetooth, 802.15.4 Zigbee, 802.16 WiMAX.
4.6 Wireless LAN (802.11) β β
| Standard | Band | Max rate |
|---|---|---|
| 802.11b | 2.4 GHz | 11 Mbps |
| 802.11a | 5 GHz | 54 Mbps |
| 802.11g | 2.4 GHz | 54 Mbps |
| 802.11n (Wi-Fi 4) | 2.4 / 5 GHz | 600 Mbps (MIMO) |
| 802.11ac (Wi-Fi 5) | 5 GHz | ~6.9 Gbps (MU-MIMO) |
| 802.11ax (Wi-Fi 6/6E) | 2.4 / 5 (+ 6 GHz for 6E) | ~9.6 Gbps (OFDMA) |
| 802.11be (Wi-Fi 7) | 2.4 / 5 / 6 GHz | ~46 Gbps |
- BSS (stations + access point), IBSS (ad hoc), ESS (several BSSs joined by a distribution system), SSID. MAC: CSMA/CA (DCF) or polling (PCF). An 802.11 frame can carry up to 4 address fields.
- Bluetooth (802.15.1): piconet = 1 master (primary) + up to 7 active slaves (up to 255 parked); scatternet = connected piconets; 2.4 GHz with FHSS.
4.7 HDLC and PPP β
- HDLC: bit-oriented. Frame types: I-frames (information), S-frames (supervisory: RR, RNR, REJ, SREJ), U-frames (unnumbered: link management). Modes NRM, ABM, ARM.
- PPP: byte-oriented, point-to-point (dial-up, DSL via PPPoE). LCP (link setup and negotiation), NCP (network-layer configuration, e.g., IPCP). Authentication PAP (plaintext, 2-way) and CHAP (challengeβresponse, 3-way, repeated periodically). No flow control or sequence numbers by default.
4.8 ARP family ββ β
- ARP: IP address β MAC address inside a LAN. Request is broadcast, reply is unicast; results cached (with timeout). Carried directly in an Ethernet frame (EtherType 0x0806).
- Gratuitous ARP (announce your own IP/MAC, detect conflicts); proxy ARP (a router answers for hosts on another network); ARP spoofing/poisoning attack.
- RARP (MAC β IP; obsolete) β BOOTP β DHCP. IPv6 replaces ARP with NDP (Neighbor Discovery, over ICMPv6).
- Layer: Forouzan treats ARP as a network-layer helper protocol; many MCQs accept "data link" or "between L2 and L3". Go by the options given.
5. Network Layer βββ β
5.1 IPv4 addressing β
- 32 bits, dotted decimal, 2^32 β 4.3 billion addresses; network part + host part.
| Class | Leading bits | First octet | Default mask | Networks | Hosts per network |
|---|---|---|---|---|---|
| A | 0 | 0β127 (1β126 usable) | /8 (255.0.0.0) | 2^7 = 128 (126 usable) | 2^24 β 2 = 16,777,214 |
| B | 10 | 128β191 | /16 (255.255.0.0) | 2^14 = 16,384 | 2^16 β 2 = 65,534 |
| C | 110 | 192β223 | /24 (255.255.255.0) | 2^21 = 2,097,152 | 2^8 β 2 = 254 |
| D | 1110 | 224β239 | n/a | Multicast | n/a |
| E | 1111 | 240β255 | n/a | Reserved / experimental | n/a |
Special addresses ββ:
- Network address: host bits all 0 (not assignable). Directed broadcast: host bits all 1 (all hosts on that network). Limited broadcast: 255.255.255.255 (local network only; routers don't forward it).
- 0.0.0.0: "this host" / unspecified (source address in DHCP Discover) or the default route 0.0.0.0/0.
- Loopback 127.0.0.0/8 (127.0.0.1 = localhost). Link-local / APIPA 169.254.0.0/16 (self-assigned when DHCP fails).
- Multicast 224.0.0.0/4 (224.0.0.1 all hosts, 224.0.0.5/.6 OSPF, 224.0.0.9 RIPv2).
- Private (RFC 1918) β: 10.0.0.0/8, 172.16.0.0/12 (172.16.0.0β172.31.255.255), 192.168.0.0/16. CGNAT shared space: 100.64.0.0/10.
5.2 Subnetting and CIDR βββ β
- Mask /n = n network bits. Usable hosts = 2^(32 β n) β 2 (exceptions: /31 point-to-point links have 2 usable (RFC 3021); /32 = a single host).
- Borrowing s bits creates 2^s subnets (very old texts used 2^s β 2, excluding "subnet zero").
- Block size (magic number) = 256 β mask value in the interesting octet.
| CIDR | Mask | Block size | Usable hosts |
|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /23 | 255.255.254.0 | 2 (3rd octet) | 510 |
| /22 | 255.255.252.0 | 4 (3rd octet) | 1,022 |
| /20 | 255.255.240.0 | 16 (3rd octet) | 4,094 |
- Network address = IP AND mask. Broadcast = network OR (NOT mask). First host = network + 1; last host = broadcast β 1.
Examples (checked):
- 192.168.10.77/27 β network 192.168.10.64, broadcast .95, hosts .65β.94 (30 hosts).
- 172.16.45.200/20 β network 172.16.32.0, broadcast 172.16.47.255.
- At least 50 subnets from 172.16.0.0/16 with the most hosts per subnet β borrow 6 bits (64 subnets) β /22 = 255.255.252.0, 1,022 hosts each.
- A class C network split into β₯ 5 subnets β borrow 3 bits β /27 β 8 subnets Γ 30 hosts.
- 500 hosts per subnet β 2^9 β 2 = 510 β /23 (255.255.254.0).
- Supernetting / route aggregation: 192.168.0.0/24 + .1.0 + .2.0 + .3.0 β 192.168.0.0/22 (the blocks must be contiguous, aligned, and a power of 2 in number).
- VLSM: give the largest subnets out first. Longest prefix match: a router uses the most specific matching route.
- Wildcard mask (Cisco ACLs/OSPF) = inverted subnet mask (/24 β 0.0.0.255).
5.3 IPv4 header (20β60 bytes) βββ β
| Field | Bits | Notes |
|---|---|---|
| Version | 4 | 4 |
| HLEN (IHL) | 4 | Header length in 4-byte words: 5 (20 B) to 15 (60 B) |
| DSCP/ECN (ToS) | 8 | QoS |
| Total length | 16 | Header + data; max 65,535 bytes |
| Identification | 16 | Same value in every fragment of one datagram |
| Flags | 3 | Reserved, DF (don't fragment), MF (more fragments) |
| Fragment offset | 13 | In units of 8 bytes |
| TTL | 8 | Decremented at each hop; at 0 β discard + ICMP Time Exceeded. Typical starting values: 64 (Linux/macOS), 128 (Windows), 255 (routers) |
| Protocol | 8 | 1 ICMP, 2 IGMP, 6 TCP, 17 UDP, 41 IPv6-in-IPv4, 50 ESP, 51 AH, 88 EIGRP, 89 OSPF |
| Header checksum | 16 | Header only; recomputed at every router (TTL changes) |
| Source / destination IP | 32 + 32 | |
| Options | 0β40 B | Record route, timestamp, source routing |
5.4 Fragmentation βββ β
- Needed when a datagram is larger than the next link's MTU. In IPv4, routers or the source may fragment; reassembly happens only at the final destination. DF = 1 and too big β drop + ICMP "fragmentation needed" (used by Path MTU Discovery).
- Each fragment gets its own IP header. Data in every fragment except the last must be a multiple of 8 bytes. Offset = (byte position of the fragment's data in the original payload) / 8. MF = 1 on every fragment except the last.
- Example (checked) β: a 4,000-byte datagram (20 B header + 3,980 B data) over MTU 1,500 β max 1,480 data bytes per fragment β 3 fragments:
| Fragment | Data bytes | Total length | Offset | MF |
|---|---|---|---|---|
| 1 | 1,480 | 1,500 | 0 | 1 |
| 2 | 1,480 | 1,500 | 185 | 1 |
| 3 | 1,020 | 1,040 | 370 | 0 |
5.5 IPv6 βββ β
- 128-bit addresses (2^128): 8 groups of 4 hex digits. Leading zeros in a group can be dropped, and one run of consecutive zero groups can be replaced by "::" (only once). 2001:0db8:0000:0000:0000:ff00:0042:8329 β 2001:db8::ff00:42:8329.
- Fixed 40-byte base header: Version (4), Traffic class (8), Flow label (20), Payload length (16), Next header (8), Hop limit (8), Source (128), Destination (128). Options go in extension headers (hop-by-hop, routing, fragment, AH, ESP, destination options).
- Differences from IPv4 ββ: no header checksum; routers never fragment (only the source does, using the fragment extension header and Path MTU discovery; minimum MTU 1,280 B); no broadcast (multicast and anycast instead); IPsec support built in; auto-configuration (SLAAC, EUI-64 interface IDs); NDP (ICMPv6) replaces ARP; hop limit replaces TTL; flow label for QoS.
- Address types: unicast (global 2000::/3, link-local fe80::/10, unique local fc00::/7), multicast ff00::/8 (ff02::1 = all nodes), anycast (delivered to the nearest member). Loopback ::1; unspecified ::; IPv4-mapped ::ffff:a.b.c.d.
- Transition: dual stack, tunneling (6to4, Teredo), translation (NAT64/DNS64).
5.6 ICMP ββ β
- Error reporting and diagnostics for IP; carried inside IP (protocol 1); no port numbers.
- Types: 0 Echo Reply, 3 Destination Unreachable (net, host, protocol, port unreachable; fragmentation needed), 4 Source Quench (deprecated), 5 Redirect, 8 Echo Request, 11 Time Exceeded (TTL hit 0 or reassembly timeout), 12 Parameter Problem.
- No ICMP error is generated for: an ICMP error message, a non-first fragment, datagrams to multicast/broadcast addresses, special addresses (127.x, 0.0.0.0).
- ping = echo request/reply. traceroute (UNIX: UDP probes to high ports with TTL 1, 2, 3, β¦; routers return Time Exceeded, the destination returns Port Unreachable). tracert (Windows: ICMP echo).
- IGMP (protocol 2): hosts report multicast group membership to local routers.
5.7 NAT and DHCP ββ β
- NAT translates private β public addresses at the border router. Static NAT (1:1), dynamic NAT (pool), PAT / NAPT / NAT overload (many private hosts share one public IP using port numbers, as in home routers). Saves IPv4 addresses and hides internal hosts; breaks the end-to-end principle and causes trouble for P2P, IPsec AH and inbound connections (needs port forwarding).
- DHCP gives automatic IP configuration (IP, mask, gateway, DNS, lease). Runs over UDP: server port 67, client port 68. DORA: Discover (client broadcast, from 0.0.0.0 to 255.255.255.255) β Offer (server) β Request (client broadcast naming the chosen server) β Ack (server).
- Renewal at T1 = 50% of the lease (unicast to the server); rebinding at T2 = 87.5% (broadcast). A DHCP relay agent forwards across subnets. Successor of BOOTP. Attacks: DHCP starvation, rogue DHCP server (defense: DHCP snooping).
5.8 Routing βββ β
- Routing (control plane: build routing tables) vs forwarding (data plane: send each packet to an output port using the forwarding table). SDN moves the control plane into a central controller.
- Static (manual) vs dynamic (protocols); default route 0.0.0.0/0.
- Link state: every router learns the whole topology by flooding LSAs and runs Dijkstra; fast convergence; more CPU and memory.
- Distance vector: each router knows only its neighbors' vectors; BellmanβFord; periodically sends its whole table to neighbors; slow convergence; count-to-infinity problem.
- Path vector (BGP): carries the full AS path β loop prevention; policy-based. Flooding: send on every link; robust; used to spread link-state advertisements.
- Count-to-infinity fixes: split horizon, poison reverse (advertise β back to the neighbor you learned the route from), hold-down timers, triggered updates, route poisoning, maximum hop count.
| Protocol | Type | Metric | Runs over | Facts |
|---|---|---|---|---|
| RIP v1/v2 | Distance vector | Hop count; max 15, 16 = infinity | UDP 520 | Updates every 30 s; v2 is classless (CIDR), multicasts to 224.0.0.9, supports authentication; RIPng for IPv6 |
| OSPF | Link state | Cost (β 1/bandwidth) | IP protocol 89 (no TCP/UDP) | Dijkstra; areas with backbone area 0; DR/BDR on multi-access links; hello packets; 224.0.0.5/.6; fast convergence; OSPFv3 for IPv6 |
| IS-IS | Link state | Cost | Directly over L2 | Used by ISPs |
| EIGRP | Advanced distance vector ("hybrid") | Bandwidth + delay | IP protocol 88 | Cisco-originated (published as RFC 7868); DUAL algorithm; loop-free |
| BGP-4 | Path vector | Path attributes / policy | TCP 179 | Between autonomous systems (the Internet's routing protocol); eBGP between ASes, iBGP inside one |
- Interior gateway protocols (IGP: RIP, OSPF, IS-IS, EIGRP) work inside one AS; exterior (EGP: BGP) between ASes.
- Administrative distance (Cisco; lower = more trusted): connected 0, static 1, eBGP 20, EIGRP 90, OSPF 110, IS-IS 115, RIP 120, iBGP 200.
- Autonomous system (AS) = networks under one administration, identified by an ASN (16-bit, now 32-bit).
- Multicast routing: DVMRP, MOSPF, PIM-DM/SM. MPLS: label switching between L2 and L3 ("layer 2.5"), used by ISPs for traffic engineering and VPNs.
6. Transport Layer βββ β
- Process-to-process delivery. Port numbers are 16 bits (0β65535): well-known 0β1023, registered 1024β49151, dynamic/ephemeral 49152β65535. Socket = IP address + port.
- Demultiplexing: a UDP socket is identified by (destination IP, destination port); a TCP socket by the 4-tuple (source IP, source port, destination IP, destination port), which is why one web server has many sockets on port 443.
6.1 UDP ββ β
- Connectionless, unreliable (no ACK/retransmission), no flow or congestion control, no ordering, message-oriented (keeps message boundaries), low overhead, supports broadcast and multicast.
- 8-byte header: source port, destination port, length (header + data), checksum. The checksum is optional in IPv4 (0 = unused) and mandatory in IPv6; it covers a pseudo-header (source/destination IP, protocol, length) + header + data.
- Max UDP payload over IPv4 = 65,535 β 20 β 8 = 65,507 bytes.
- Used by DNS (queries), DHCP, TFTP, SNMP, RIP, NTP, Syslog, VoIP/RTP, video streaming, online games, QUIC/HTTP/3.
6.2 TCP βββ β
- Connection-oriented, reliable, in-order byte stream, full duplex, point-to-point only (no broadcast/multicast), flow control, congestion control, error control (checksum, ACKs, retransmission). Sequence numbers count bytes, not segments.
- Header 20β60 bytes: source port 16 | destination port 16 | sequence number 32 | acknowledgment number 32 (= next byte expected; cumulative) | HLEN 4 (in 4-byte words) | reserved | flags URG, ACK, PSH, RST, SYN, FIN (+ ECE, CWR) | window size 16 (receive window; max 65,535, or up to ~1 GB with the window-scale option) | checksum 16 (mandatory) | urgent pointer 16 | options (MSS, window scale, SACK, timestamps, NOP).
- MSS = max TCP payload per segment: typically 1,460 on Ethernet (1,500 β 20 β 20); 536 by default if not negotiated.
- Three-way handshake βββ: client β SYN (seq = x) β server β SYN+ACK (seq = y, ack = x + 1) β client β ACK (seq = x + 1, ack = y + 1). SYN and FIN each consume one sequence number; a pure ACK consumes none. ISNs are random (for security). The client's first data byte has seq = x + 1.
- Termination: FIN β ACK β FIN β ACK (4-way; or 3-way using FIN+ACK); half-close is possible. The side that closes first (active closer) waits in TIME_WAIT for 2 Γ MSL, so the last ACK gets through and old duplicates expire.
- States: CLOSED, LISTEN, SYN_SENT, SYN_RCVD, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, CLOSE_WAIT, CLOSING, LAST_ACK, TIME_WAIT.
- RST aborts a connection or refuses one (closed port). SYN flood: attacker sends many SYNs and leaves half-open connections β defenses: SYN cookies, backlog limits.
- Sequence-number wrap-around time = 2^32 bytes Γ· bandwidth in bytes/s (1 Gbps β ~34 s; timestamps/PAWS protect against old segments).
- Flow control: the receiver advertises rwnd; data in flight β€ min(rwnd, cwnd). Zero window β persist timer sends probes. Silly window syndrome: sender-side fix = Nagle's algorithm (hold small data until an ACK arrives or a full MSS is ready); receiver-side fix = Clark's solution (advertise 0 until a useful window opens) / delayed ACK.
- Max throughput β window / RTT (64 KB window, 100 ms RTT β ~5.24 Mbps).
- Error control: cumulative ACKs; retransmit on timeout or after 3 duplicate ACKs (fast retransmit); SACK option; out-of-order segments are usually buffered.
- RTO estimation (Jacobson/Karels): EstimatedRTT = (1 β Ξ±)Β·EstimatedRTT + Ξ±Β·SampleRTT (Ξ± = 0.125); DevRTT = (1 β Ξ²)Β·DevRTT + Ξ²Β·|SampleRTT β EstimatedRTT| (Ξ² = 0.25); RTO = EstimatedRTT + 4Β·DevRTT. Karn's algorithm: ignore RTT samples from retransmitted segments and double the RTO after each timeout (exponential backoff).
- Timers: retransmission, persistence, keepalive, TIME_WAIT (2MSL).
6.3 TCP congestion control βββ β
- cwnd = sender's congestion window; ssthresh = slow-start threshold.
- Slow start: cwnd starts at 1 MSS (modern stacks up to 10) and grows by 1 MSS per ACK, i.e., it doubles every RTT (exponential), until ssthresh.
- Congestion avoidance: once cwnd β₯ ssthresh, +1 MSS per RTT (linear, additive increase).
- Timeout (Tahoe and Reno): ssthresh = cwnd / 2, cwnd = 1 MSS, back to slow start.
- 3 duplicate ACKs: Tahoe β same as a timeout (cwnd = 1). Reno β fast retransmit + fast recovery: ssthresh = cwnd / 2, cwnd = ssthresh (+3), continue in congestion avoidance.
- AIMD (additive increase, multiplicative decrease) gives the sawtooth. Modern algorithms: CUBIC (Linux default), BBR (model-based). ECN marks packets instead of dropping them.
- Example (checked): ssthresh = 16, cwnd per RTT = 1, 2, 4, 8, 16, 17, 18, 19, 20 β timeout β ssthresh = 10, cwnd = 1, 2, 4, 8, 10, 11, β¦ (exponential growth is capped at ssthresh).
- Other congestion control: choke packets, backpressure, RED (random early detection), admission control.
- Traffic shaping β: leaky bucket (output at a constant rate, smooths bursts; overflow discarded) vs token bucket (tokens arrive at rate Ο into a bucket of size C; allows bursts up to C). Max burst duration S = C / (M β Ο), M = max output rate. Example: C = 500 KB, M = 12 MB/s, Ο = 2 MB/s β S = 50 ms.
- QoS: IntServ (RSVP, per-flow reservation) vs DiffServ (DSCP classes, per-hop behavior).
6.4 TCP vs UDP βββ β
| TCP | UDP | |
|---|---|---|
| Connection | Connection-oriented (handshake) | Connectionless |
| Reliability | Reliable, ordered, ACKed | Best effort, unordered |
| Flow / congestion control | Yes | No |
| Header | 20β60 bytes | 8 bytes |
| Data unit | Byte stream (segments) | Messages (datagrams), boundaries kept |
| Broadcast / multicast | No | Yes |
| Speed | Slower | Faster, lower latency |
| Used by | HTTP/1.1, HTTP/2, HTTPS, FTP, SMTP, SSH, Telnet, POP3, IMAP, BGP | DNS, DHCP, TFTP, SNMP, RIP, NTP, VoIP, streaming, games, QUIC |
- SCTP: message-oriented and reliable; multi-homing and multi-streaming; 4-way handshake with a cookie; used for telephony signaling and WebRTC data channels.
- QUIC: runs over UDP (port 443); built-in TLS 1.3; 0-RTT/1-RTT setup; independent streams, so no head-of-line blocking between streams; connection migration; the basis of HTTP/3.
7. Application Layer βββ β
7.1 Port numbers (memorize) βββ β
| Port | Protocol | Transport |
|---|---|---|
| 20 / 21 | FTP data / control | TCP |
| 22 | SSH, SCP, SFTP | TCP |
| 23 | Telnet | TCP |
| 25 | SMTP (relay); 587 submission; 465 SMTPS | TCP |
| 53 | DNS | UDP for queries; TCP for zone transfers and large responses |
| 67 / 68 | DHCP server / client | UDP |
| 69 | TFTP | UDP |
| 80 | HTTP | TCP |
| 88 | Kerberos | UDP/TCP |
| 110 | POP3 (995 = POP3S) | TCP |
| 123 | NTP | UDP |
| 143 | IMAP (993 = IMAPS) | TCP |
| 161 / 162 | SNMP agent / trap | UDP |
| 179 | BGP | TCP |
| 389 | LDAP (636 = LDAPS) | TCP/UDP |
| 443 | HTTPS (TCP); HTTP/3 (UDP via QUIC) | TCP/UDP |
| 445 | SMB | TCP |
| 514 | Syslog | UDP |
| 520 | RIP | UDP |
| 853 | DNS over TLS | TCP |
| 1433 / 1521 / 3306 / 5432 | SQL Server / Oracle / MySQL / PostgreSQL | TCP |
| 3389 | RDP | TCP |
| 5060 / 5061 | SIP / SIP over TLS | UDP/TCP |
| 6379 / 27017 | Redis / MongoDB | TCP |
| 8080 | Alternate HTTP / proxy | TCP |
7.2 DNS βββ β
- A distributed, hierarchical database mapping names β IP addresses. Hierarchy: root (.) β TLDs (generic: .com, .org, .net, .edu; country-code: .in, .uk; infrastructure: .arpa) β second-level domains (example.com) β subdomains.
- Servers: root servers (13 named identities, aβm.root-servers.net, with hundreds of anycast instances), TLD servers, authoritative servers (primary/secondary hold the zones), local recursive resolver (ISP, 8.8.8.8, 1.1.1.1). Answers are cached for their TTL.
- Recursive query: the server must return the final answer (typically host β local resolver). Iterative query: the server returns its best referral (typically resolver β root β TLD β authoritative).
- Resource records ββ: A (name β IPv4), AAAA (β IPv6), CNAME (alias β canonical name), MX (mail exchanger, with preference), NS (authoritative name server), PTR (IP β name; reverse lookup in in-addr.arpa / ip6.arpa), SOA (start of authority: serial, refresh, β¦), TXT (SPF, DKIM, verification), SRV (service location), CAA.
- Message = header + question + answer + authority + additional (same format for query and reply). UDP 53 (classic limit 512 bytes, larger with EDNS0), else TCP; zone transfers (AXFR/IXFR) use TCP.
- Limits: a label β€ 63 characters; a full name β€ 253 characters.
- Attacks: DNS spoofing / cache poisoning (Kaminsky), DNS amplification DDoS, DNS tunneling. Protection: DNSSEC (authenticity and integrity via signatures; no confidentiality), DoT (853), DoH (443).
- Tools: nslookup, dig, host.
7.3 HTTP βββ β
- The web's protocol: clientβserver, request/response, stateless (state via cookies, sessions, tokens). URL = scheme://host:port/path?query#fragment.
- Versions: HTTP/1.0 (non-persistent by default: one object per TCP connection); HTTP/1.1 (persistent connections by default, pipelining, mandatory Host header, chunked transfer); HTTP/2 (binary framing, multiplexed streams over one TCP connection, HPACK header compression, server push); HTTP/3 (over QUIC/UDP).
- Response time: non-persistent β 2Β·RTT + transmission time per object (one RTT for TCP setup, one for request/response); persistent β 1 RTT per object after the first.
- Methods: GET (retrieve; safe and idempotent; parameters in the URL), HEAD (headers only), POST (submit/create; not idempotent), PUT (replace/create at a URI; idempotent), PATCH (partial update; not necessarily idempotent), DELETE (idempotent), OPTIONS (allowed methods; CORS preflight), TRACE (loop-back), CONNECT (tunnel, e.g., HTTPS through a proxy).
- Status codes βββ:
- 1xx informational: 100 Continue, 101 Switching Protocols (e.g., WebSocket upgrade).
- 2xx success: 200 OK, 201 Created, 202 Accepted, 204 No Content.
- 3xx redirection: 301 Moved Permanently, 302 Found, 303 See Other, 304 Not Modified, 307 Temporary Redirect, 308 Permanent Redirect.
- 4xx client error: 400 Bad Request, 401 Unauthorized (= not authenticated), 403 Forbidden (authenticated but not allowed), 404 Not Found, 405 Method Not Allowed, 408 Request Timeout, 409 Conflict, 413 Payload Too Large, 429 Too Many Requests.
- 5xx server error: 500 Internal Server Error, 501 Not Implemented, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout.
- Cookies:
Set-Cookieheader in the response β stored by the browser βCookieheader in later requests. Attributes: Expires/Max-Age, Domain, Path, Secure, HttpOnly, SameSite. Kurose's four components: header in the response, header in the request, cookie file on the client, back-end database at the server. - Web caching / proxy servers cut response time and access-link traffic. Conditional GET (If-Modified-Since / If-None-Match + ETag) β 304 Not Modified.
- HTTPS = HTTP over TLS (port 443). WebSocket: full-duplex over one TCP connection (ws:// on 80, wss:// on 443) after an HTTP Upgrade.
- REST: stateless, resources identified by URIs, standard methods. CORS relaxes the browser's same-origin policy.
7.4 Email ββ β
- Parts: user agents (Outlook, Gmail web), mail servers (MTAs) with mailboxes and queues. SMTP pushes mail (user agent β server and server β server). Access protocols pull mail: POP3, IMAP, or HTTP (webmail).
- SMTP: TCP 25 (relay), 587 (submission with authentication); persistent connections; commands HELO/EHLO, MAIL FROM, RCPT TO, DATA (ends with a line containing "."), QUIT; reply codes (220, 250, 354, 550, β¦); originally 7-bit ASCII only.
- MIME extends email to non-ASCII text, attachments, images, audio (Content-Type: text/html, image/jpeg, multipart/mixed; Content-Transfer-Encoding: base64, which adds ~33% size, or quoted-printable).
- POP3 (110): download-and-delete or download-and-keep; stateless across sessions; simple. IMAP (143): mail stays on the server; folders; partial fetch; sync across devices.
- Email security: SPF, DKIM, DMARC (anti-spoofing); PGP and S/MIME (end-to-end); STARTTLS.
7.5 FTP and other protocols ββ β
- FTP uses two TCP connections: control on port 21 (persistent; control is "out-of-band") and data on port 20 in active mode (a new data connection for each file). FTP is stateful (remembers the user and current directory). ASCII vs binary transfer modes. Active mode: server opens the data connection from port 20 to the client. Passive mode: client connects to a port the server chooses (firewall-friendly). Credentials travel in plaintext β use SFTP (over SSH) or FTPS (over TLS).
- TFTP: UDP 69, no authentication, very simple (boot images, router configs).
- Telnet (23): remote login in plaintext using an NVT (Network Virtual Terminal). SSH (22): encrypted remote login, tunneling and port forwarding.
- SNMP: managerβagent model; MIB (Management Information Base), SMI; operations Get, GetNext, GetBulk, Set, Trap/Inform; UDP 161 (agent) / 162 (trap). v1/v2c use plaintext community strings; v3 adds authentication and encryption.
- NTP (UDP 123, stratum levels), LDAP (directory, 389), SIP (VoIP signaling) + RTP/RTCP (media), DHCP (section 5.7).
- P2P: BitTorrent (tracker, .torrent file, chunks, rarest-first, tit-for-tat), DHTs. CDNs cache content close to users (often via DNS redirection).
- Socket API: TCP server: socket() β bind() β listen() β accept() β recv()/send() β close(). TCP client: socket() β connect() β send()/recv() β close(). UDP: socket() β bind() (server) β sendto()/recvfrom(); no listen/accept/connect needed.
- Tools: ping (ICMP echo), traceroute/tracert (TTL), nslookup/dig (DNS), ipconfig/ifconfig/ip addr, netstat/ss (connections and ports), arp -a (ARP cache), route / ip route, nmap (port scanning), tcpdump/Wireshark (packet capture), curl/wget.
8. Rapid-fire trap list βββ β
- Physical β bits; data link β frames; network β packets; transport β segments/datagrams.
- A router splits broadcast domains; a switch splits collision domains; a hub splits nothing.
- Repeater/hub = L1; bridge/switch = L2; router = L3; gateway = up to L7.
- Encryption, compression, translation β presentation; dialog control and synchronization β session.
- MAC 48 bits; IPv4 32; IPv6 128; port 16.
- Pure ALOHA 18.4%; slotted ALOHA 36.8%.
- CSMA/CD for wired, CSMA/CA for wireless.
- Ethernet frame 64β1,518 bytes; payload 46β1,500.
- GBN window β€ 2^k β 1; SR β€ 2^(kβ1).
- Stop-and-wait Ξ· = 1/(1 + 2a).
- Hamming: 2^r β₯ m + r + 1. Detect d errors β distance d + 1; correct t β 2t + 1.
- CRC: append (degree of generator) zeros before dividing.
- Usable hosts = 2^h β 2.
- 127.x loopback; 169.254.x APIPA; 10/8, 172.16/12, 192.168/16 private.
- IPv4 header 20β60 bytes; IPv6 fixed 40 bytes; IPv6 has no checksum and no broadcast.
- Fragment offset in 8-byte units; reassembly only at the destination; IPv6 routers never fragment.
- TTL drops by 1 per hop; traceroute relies on it.
- RIP: hop count, max 15, UDP 520. OSPF: Dijkstra, IP protocol 89. BGP: path vector, TCP 179.
- Link state = Dijkstra; distance vector = BellmanβFord (count-to-infinity).
- TCP header 20β60 bytes; UDP 8 bytes.
- SYN and FIN each consume a sequence number.
- TIME_WAIT = 2 MSL, at the active closer.
- Timeout β cwnd = 1; 3 duplicate ACKs (Reno) β cwnd halves.
- DNS: UDP 53 (TCP for zone transfers). DHCP: UDP 67/68. FTP: TCP 20/21.
- HTTP is stateless (cookies add state); HTTP/1.1 persistent by default; HTTP/3 runs over QUIC/UDP.
- SMTP pushes; POP3/IMAP pull.
- 401 = not authenticated; 403 = authenticated but forbidden.
- ARP: IP β MAC (broadcast request, unicast reply).
- NAT/PAT shares one public IP using ports.
- Shannon for noisy channels; Nyquist for noiseless ones.