COMPUTER NETWORKS / 7. NETWORK SECURITY
Network Security — Firewalls, VPN, Attacks & Defense
How networks are attacked, protected, and secured in production
EXPLANATION
Network security is the practice of protecting your network and data from unauthorized access, attacks, and damage. Understanding attacks is prerequisite to building defenses. Common Network Attacks: Man-in-the-Middle (MITM): attacker positions themselves between client and server, relaying and potentially altering traffic. Defense: TLS (certificates prove server identity), HSTS (browsers force HTTPS), certificate pinning. DDoS (Distributed Denial of Service): flooding a server with so much traffic it can't serve legitimate requests. Types: volumetric (UDP flood, ICMP flood), protocol (SYN flood exhausts connection table), application layer (HTTP flood). Defense: rate limiting, CDN, anycast, scrubbing centers. SYN Flood: attacker sends thousands of SYN packets with spoofed source IPs. Server allocates state for each connection (SYN-RECEIVED) but never gets ACK. Connection table fills up. Defense: SYN cookies (server encodes state in the SYN-ACK without allocating memory). DNS Spoofing / Cache Poisoning: inject false DNS records into a resolver's cache. Users who ask that resolver get the attacker's IP. Defense: DNSSEC (DNS records are signed with public key cryptography). Port Scanning: systematically probing ports to discover which services are running. Not an attack itself but reconnaissance. Defense: firewall rules, fail2ban, rate limit connections per IP. Firewalls: filter traffic based on rules: • Packet filtering (Layer 3/4): allow/deny based on IP, port, protocol • Stateful: tracks connection state, only allows established connections in • Application (Layer 7): inspects HTTP content, blocks based on application rules • Cloud: AWS Security Groups, GCP Firewall Rules VPN (Virtual Private Network): creates an encrypted tunnel between two points. All traffic inside the tunnel appears to come from the VPN endpoint. Uses IPSec or OpenVPN (TLS over UDP). WireGuard is the modern, fast alternative. Zero Trust Security: never trust, always verify. Even traffic inside your network must authenticate. Every service-to-service call is authenticated. Microsegmentation limits blast radius of breaches. TLS best practices: • TLS 1.3 only (1.0 and 1.1 are deprecated, broken) • Strong cipher suites (AES-256-GCM, ChaCha20-Poly1305) • Perfect Forward Secrecy (ECDHE key exchange — compromise of private key doesn't expose past sessions) • HSTS with long max-age and includeSubDomains
DIAGRAM
FIREWALL ARCHITECTURE:
Internet
↓
[Firewall/WAF] ← blocks SYN floods, bad IPs, known malware
↓
DMZ (demilitarized zone)
[Web Server / Load Balancer / CDN]
↓
[Internal Firewall] ← only allows app→DB on port 5432
↓
Internal Network
[App Servers] [Databases] [Internal Services]
TLS ENCRYPTION:
Without TLS: Client → [username: alice, pw: secret123] → Server
↑ visible to anyone on network
With TLS: Client → [xK92#@mP0q...] → Server
↑ encrypted, unreadable in transit
COMMON ATTACK VECTORS:
SYN Flood → fill connection table → legitimate users can't connect
DNS Spoof → redirect users to fake site → steal credentials
MITM → intercept/modify traffic → session hijacking
Port Scan → reconnaissance for vulnerabilitiesCODE