Introduction to Computer Networks
A computer network is a set of devices (nodes) connected by communication links that enable data exchange and resource sharing.
Network Types
**PAN** (Personal Area Network): ~10m range
**LAN** (Local Area Network): Building/campus
**MAN** (Metropolitan Area Network): City-wide
**WAN** (Wide Area Network): Country/global
OSI Model (7 Layers)
| Layer | Function | Example Protocols |
|-------|----------|------------------|
| 7. Application | User interface | HTTP, FTP, SMTP, DNS |
| 6. Presentation | Data formatting, encryption | SSL/TLS |
| 5. Session | Session management | NetBIOS, RPC |
| 4. Transport | End-to-end delivery | TCP, UDP |
| 3. Network | Routing, logical addressing | IP, ICMP, ARP |
| 2. Data Link | Framing, MAC addressing | Ethernet, PPP |
| 1. Physical | Raw bit transmission | Cables, hubs |
TCP/IP Model (4 Layers)
**Network Interface**: Physical + Data Link
**Internet**: IP, routing
**Transport**: TCP, UDP
**Application**: HTTP, FTP, SMTP, DNS
TCP vs UDP
| Feature | TCP | UDP |
|---------|-----|-----|
| Connection | Connection-oriented | Connectionless |
| Reliability | Guaranteed delivery | No guarantee |
| Ordering | In-order delivery | No ordering |
| Speed | Slower | Faster |
| Use Cases | Web, email, file transfer | Streaming, gaming, VoIP |
TCP Three-Way Handshake
Client sends SYN (seq=x)
Server replies SYN-ACK (seq=y, ack=x+1)
Client sends ACK (ack=y+1)
Routing Protocols
Interior Gateway Protocols
**RIP** (Routing Information Protocol): Distance vector, hop count
**OSPF** (Open Shortest Path First): Link state, Dijkstra algorithm
**EIGRP**: Cisco proprietary, hybrid
Exterior Gateway Protocols
**BGP** (Border Gateway Protocol): Path vector, internet backbone
Network Security
Threats
Eavesdropping, Man-in-the-Middle
Denial of Service (DoS)
Packet sniffing, IP spoofing
Security Measures
**Firewalls**: Filter traffic based on rules
**Encryption**: SSL/TLS, IPsec
**Authentication**: Passwords, certificates
**IDS/IPS**: Detect and prevent intrusions
Common Attacks & Protections
**XSS**: Sanitize user input
**SQL Injection**: Parameterized queries
**CSRF**: Anti-CSRF tokens
**DDoS**: Rate limiting, CDN