Computer Networks
OSI/TCP-IP · protocols · security
0 / 13 revised
OSI vs TCP/IP Model 🎯
CN
▾
Quick Recall
OSI=7 layers (theoretical); TCP/IP=4 layers (practical); map: App+Pres+Sess→Application
| OSI Layer | Function | Protocol | PDU | TCP/IP |
|---|---|---|---|---|
| 7 Application | User interface | HTTP, FTP, SMTP, DNS | Data | Application |
| 6 Presentation | Encryption, compression | SSL/TLS, JPEG | Data | |
| 5 Session | Session management | NetBIOS, RPC | Data | |
| 4 Transport | Reliable delivery | TCP, UDP | Segment | Transport |
| 3 Network | Routing, logical addressing | IP, ICMP, ARP | Packet | Internet |
| 2 Data Link | Framing, MAC | Ethernet, Wi-Fi | Frame | Network Access |
| 1 Physical | Bits on wire | Cables, signals | Bits |
Encapsulation / Decapsulation
CN
▾
Quick Recall
Data→Segment→Packet→Frame→Bits (going down); reverse going up
Sending: Each layer adds its header (and trailer at data link).
Application data → TCP adds port header (segment) → IP adds IP header (packet) → Ethernet adds MAC header + trailer (frame) → Physical sends bits.
Receiving: Each layer strips its header and passes payload up.
Application data → TCP adds port header (segment) → IP adds IP header (packet) → Ethernet adds MAC header + trailer (frame) → Physical sends bits.
Receiving: Each layer strips its header and passes payload up.
TCP vs UDP 🎯
CN
▾
Quick Recall
TCP = reliable, ordered, connection-oriented; UDP = fast, fire-and-forget
| TCP | UDP | |
|---|---|---|
| Connection | Connection-oriented (3-way handshake) | Connectionless |
| Reliability | Guaranteed (ACK, retransmit) | No guarantee |
| Ordering | Ordered (sequence numbers) | No ordering |
| Flow Control | Yes (sliding window) | No |
| Speed | Slower (overhead) | Faster |
| Header | 20-60 bytes | 8 bytes |
| Use cases | HTTP, SSH, email, file transfer | DNS, video streaming, gaming, VoIP |
TCP 3-Way Handshake 🎯
CN
▾
Quick Recall
SYN → SYN-ACK → ACK (open); FIN → ACK → FIN → ACK (close)
Connection setup (3-way):
1. Client → SYN (seq=x) → Server
2. Server → SYN-ACK (seq=y, ack=x+1) → Client
3. Client → ACK (ack=y+1) → Server
Connection teardown (4-way):
1. Client → FIN → Server
2. Server → ACK → Client
3. Server → FIN → Client
4. Client → ACK → Server (enters TIME_WAIT)
Flow control: Sliding window — receiver advertises window size.
Congestion control: Slow Start (exponential) → Congestion Avoidance (linear/AIMD). On loss: halve window (fast recovery) or reset to 1 (timeout).
1. Client → SYN (seq=x) → Server
2. Server → SYN-ACK (seq=y, ack=x+1) → Client
3. Client → ACK (ack=y+1) → Server
Connection teardown (4-way):
1. Client → FIN → Server
2. Server → ACK → Client
3. Server → FIN → Client
4. Client → ACK → Server (enters TIME_WAIT)
Flow control: Sliding window — receiver advertises window size.
Congestion control: Slow Start (exponential) → Congestion Avoidance (linear/AIMD). On loss: halve window (fast recovery) or reset to 1 (timeout).
IP Addressing & Subnetting 🎯
CN
▾
Quick Recall
IPv4=32-bit; CIDR /n → 2^(32-n) - 2 usable hosts; subnet mask determines network portion
| Class | Range | Default Mask | Networks |
|---|---|---|---|
| A | 1-126.x.x.x | /8 (255.0.0.0) | 128 |
| B | 128-191.x.x.x | /16 (255.255.0.0) | 16K |
| C | 192-223.x.x.x | /24 (255.255.255.0) | 2M |
Subnetting example: 192.168.1.0/26 → mask 255.255.255.192 → 2^6-2 = 62 hosts per subnet, 4 subnets.
IPv4 vs IPv6: 32-bit vs 128-bit; IPv6 has no NAT needed, no broadcast, built-in IPSec.
DNS, DHCP, NAT 🎯
CN
▾
Quick Recall
DNS resolves names→IP; DHCP auto-assigns IP; NAT maps private→public IP
DNS resolution flow: Browser cache → OS cache → Recursive resolver → Root NS → TLD NS (.com) → Authoritative NS → IP returned.
Record types: A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail), NS (nameserver).
DHCP: DORA process — Discover → Offer → Request → Acknowledge. Leases IP for a period.
NAT: Translates private IP:port → public IP:port. Allows many devices to share one public IP. Types: Static, Dynamic, PAT (port address translation).
Record types: A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail), NS (nameserver).
DHCP: DORA process — Discover → Offer → Request → Acknowledge. Leases IP for a period.
NAT: Translates private IP:port → public IP:port. Allows many devices to share one public IP. Types: Static, Dynamic, PAT (port address translation).
HTTP / HTTPS 🎯
CN
▾
Quick Recall
HTTP=stateless request-response; HTTPS=HTTP+TLS; know methods & status codes
Methods:
Status codes: 200 OK, 201 Created, 301 Moved, 304 Not Modified, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Server Error, 503 Unavailable.
HTTP/1.1: Keep-alive, pipelining. HTTP/2: Multiplexing, header compression, server push. HTTP/3: QUIC (UDP-based), faster handshake.
| Method | Use | Idempotent? |
|---|---|---|
| GET | Read resource | Yes |
| POST | Create resource | No |
| PUT | Replace resource | Yes |
| PATCH | Partial update | No |
| DELETE | Remove resource | Yes |
HTTP/1.1: Keep-alive, pipelining. HTTP/2: Multiplexing, header compression, server push. HTTP/3: QUIC (UDP-based), faster handshake.
ARP & ICMP
CN
▾
Quick Recall
ARP resolves IP→MAC (broadcast who-has); ICMP for diagnostics (ping, traceroute)
ARP: "Who has 192.168.1.5? Tell 192.168.1.1" → broadcast on LAN → target replies with MAC. Cached in ARP table.
ICMP: Control/error messages. Echo request/reply (ping), Destination Unreachable, Time Exceeded (traceroute uses TTL expiry), Redirect.
ICMP: Control/error messages. Echo request/reply (ping), Destination Unreachable, Time Exceeded (traceroute uses TTL expiry), Redirect.
Network Devices 🎯
CN
▾
Quick Recall
Hub=broadcast all; Switch=MAC-based forward; Router=IP-based forward between networks
| Device | Layer | Intelligence |
|---|---|---|
| Hub | L1 Physical | Broadcasts to all ports (dumb) |
| Bridge | L2 Data Link | Filters by MAC, connects 2 segments |
| Switch | L2 Data Link | MAC table, forwards to specific port |
| Router | L3 Network | IP routing between networks |
| Gateway | L7 Application | Protocol translation |
Network Topologies
CN
▾
Quick Recall
Star=central hub; Bus=single cable; Ring=circular; Mesh=every node connected
| Topology | Pros | Cons |
|---|---|---|
| Star | Easy to manage, fault isolation | Central point of failure |
| Bus | Simple, cheap | Single cable failure = all down |
| Ring | Equal access, ordered | One break disrupts all |
| Mesh | Highly redundant | Expensive, complex |
Error Detection
CN
▾
Quick Recall
Parity=1 bit; Checksum=sum-based; CRC=polynomial division (strongest)
Parity bit: Even/odd parity — detects single-bit errors only.
Checksum: Sum of data segments; used in IP/TCP headers. Catches most errors.
CRC (Cyclic Redundancy Check): Treats data as polynomial, divides by generator polynomial — remainder is CRC. Detects burst errors. Used in Ethernet.
Checksum: Sum of data segments; used in IP/TCP headers. Catches most errors.
CRC (Cyclic Redundancy Check): Treats data as polynomial, divides by generator polynomial — remainder is CRC. Detects burst errors. Used in Ethernet.
SSL/TLS & Encryption 🎯
CN
▾
Quick Recall
TLS handshake: agree cipher → exchange keys → symmetric encrypt data
Symmetric: Same key for encrypt/decrypt (AES). Fast. Challenge: key exchange.
Asymmetric: Public key encrypts, private key decrypts (RSA). Slow. Used for key exchange.
TLS handshake:
Asymmetric: Public key encrypts, private key decrypts (RSA). Slow. Used for key exchange.
TLS handshake:
- Client Hello (supported ciphers)
- Server Hello (chosen cipher + certificate)
- Client verifies cert, generates pre-master secret, encrypts with server's public key
- Both derive session key → switch to symmetric encryption
Common Ports Table
CN
▾
Quick Recall
HTTP=80, HTTPS=443, SSH=22, DNS=53, FTP=21, SMTP=25
| Port | Protocol | Use |
|---|---|---|
| 20/21 | FTP | File transfer (data/control) |
| 22 | SSH | Secure shell |
| 23 | Telnet | Remote login (insecure) |
| 25 | SMTP | Send email |
| 53 | DNS | Domain name resolution |
| 80 | HTTP | Web (unencrypted) |
| 110 | POP3 | Receive email |
| 143 | IMAP | Email access |
| 443 | HTTPS | Web (encrypted) |
| 3306 | MySQL | Database |
| 5432 | PostgreSQL | Database |