You cannot defend or test what you cannot read. Almost every attack and every detection happens on the network, so the protocols below are the vocabulary of packet captures, firewall rules and scan results.
OSI vs TCP/IP
OSI TCP/IP Examples / PDU
7 Application \
6 Presentation >------- Application HTTP, DNS, SSH, TLS (data)
5 Session /
4 Transport --------- Transport TCP, UDP (segment/datagram)
3 Network --------- Internet IP, ICMP (packet)
2 Data Link \-------- Link Ethernet, Wi-Fi, ARP (frame)
1 Physical / cables, radio (bits)
Mnemonic (7 to 1): All People Seem To Need Data Processing. Security people use the layer numbers as shorthand: a "Layer 7 attack" targets the application, a "Layer 2 attack" is ARP or MAC spoofing, a "Layer 3 firewall" filters by IP.
Encapsulation
Each layer wraps the data from the layer above with its own header. The receiver unwraps in reverse.
Application: [ DATA ]
Transport: [TCP hdr][ DATA ]
Network: [IP hdr][TCP hdr][ DATA ]
Link: [Eth hdr][IP hdr][TCP hdr][ DATA ][Eth trailer]
Addressing
| Address | Layer | Scope | Example |
|---|---|---|---|
| MAC | 2 | Local network segment; burned in but spoofable | 00:1A:2B:3C:4D:5E |
| IPv4 | 3 | Routable, 32 bits | 192.168.1.10 |
| IPv6 | 3 | Routable, 128 bits | 2001:db8::1 |
| Port | 4 | Identifies the service/process, 0-65535 | 443 |
Private ranges (RFC 1918) and special addresses
| Range | CIDR | Notes |
|---|---|---|
| 10.0.0.0 - 10.255.255.255 | 10.0.0.0/8 | Large internal networks |
| 172.16.0.0 - 172.31.255.255 | 172.16.0.0/12 | |
| 192.168.0.0 - 192.168.255.255 | 192.168.0.0/16 | Home/office |
| 127.0.0.0/8 | loopback | 127.0.0.1 is the local host |
| 169.254.0.0/16 | link-local (APIPA) | Appears when DHCP fails |
Subnetting basics
CIDR notation /n says how many leading bits are the network part; the rest are host bits.
192.168.1.0/24 -> mask 255.255.255.0 -> 256 addresses, 254 usable hosts
192.168.1.0/26 -> mask 255.255.255.192 -> 64 addresses, 62 usable hosts
Usable hosts = 2^(32 - n) - 2 (network address + broadcast excluded)
| CIDR | Mask | Addresses |
|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 |
| /16 | 255.255.0.0 | 65,536 |
| /24 | 255.255.255.0 | 256 |
| /30 | 255.255.255.252 | 4 (point-to-point links) |
Subnets are also security boundaries: hosts in different subnets must pass a router or firewall, which is where filtering is applied (see Network Segmentation).
TCP, UDP and Ports
| TCP | UDP | |
|---|---|---|
| Connection | Connection-oriented, reliable | Connectionless, best effort |
| Ordering / retransmit | Yes | No |
| Overhead | Higher | Lower |
| Used by | HTTP(S), SSH, SMTP, databases | DNS, DHCP, VoIP, streaming, NTP, VPNs |
Three-way handshake
Client Server
| ---- SYN (seq=x) ------> |
| <--- SYN-ACK (seq=y, ack=x+1) |
| ---- ACK (ack=y+1) -----> |
| connection established |
| ---- FIN / ACK ... -----> | (graceful close) or RST (abort)
| Flag | Meaning | Security relevance |
|---|---|---|
| SYN | Start connection | SYN scans, SYN flood DoS |
| ACK | Acknowledge | Used by ACK scans to map firewall rules |
| FIN | Graceful close | FIN/Xmas/Null scans abuse unusual flags |
| RST | Abort | Closed port reply in scans |
| PSH / URG | Push data / urgent | Rarely used; flag anomalies stand out |
Scan techniques built on these flags are covered in Nmap; flood attacks in Network Attacks.
Common ports and protocols
| Port | Proto | Service | Secure? Alternative |
|---|---|---|---|
| 20/21 | TCP | FTP | No (clear text) -> SFTP (22) / FTPS (990) |
| 22 | TCP | SSH / SFTP / SCP | Yes |
| 23 | TCP | Telnet | No -> SSH |
| 25 | TCP | SMTP (server to server) | Often unencrypted -> STARTTLS / 587, 465 |
| 53 | UDP/TCP | DNS | Plain -> DoT (853), DoH (443) |
| 67/68 | UDP | DHCP | No authentication |
| 69 | UDP | TFTP | No (no auth) -> SFTP |
| 80 | TCP | HTTP | No -> HTTPS |
| 88 | TCP/UDP | Kerberos | Yes (ticket based) |
| 110 | TCP | POP3 | No -> POP3S (995) |
| 123 | UDP | NTP | Unauthenticated by default; abused for amplification |
| 135/139/445 | TCP | RPC, NetBIOS, SMB | Legacy SMBv1 unsafe; do not expose |
| 143 | TCP | IMAP | No -> IMAPS (993) |
| 161/162 | UDP | SNMP | v1/v2c clear text -> SNMPv3 |
| 389 | TCP/UDP | LDAP | No -> LDAPS (636) |
| 443 | TCP | HTTPS | Yes (TLS) |
| 514 | UDP | Syslog | No -> TLS syslog (6514) |
| 1433 / 3306 / 5432 | TCP | MSSQL / MySQL / PostgreSQL | Never expose to the internet |
| 3389 | TCP | RDP | Protect with VPN/NLA/MFA |
| 5900 | TCP | VNC | Weak by default -> tunnel via SSH/VPN |
Ranges: 0-1023 well-known, 1024-49151 registered, 49152-65535 ephemeral (client-side). See also SSH and Telnet.
Core Network Services
DNS — names to addresses
Browser -> stub resolver -> recursive resolver -> root -> TLD (.com) -> authoritative
\_ caches the answer for the record's TTL
Records: A/AAAA (IPv4/IPv6), CNAME (alias), MX (mail), NS (name server), TXT (SPF/DKIM/verification), PTR (reverse). Attacks: cache poisoning, DNS tunnelling/exfiltration, hijacking, subdomain takeover. Defences: DNSSEC, DNS filtering, logging queries. See Security Technologies: DNS Filtering.
DHCP — automatic addressing
The DORA exchange: Discover, Offer, Request, Acknowledge (broadcast, UDP 67/68). It hands out IP, mask, gateway and DNS. There is no authentication, so a rogue DHCP server can steer clients through an attacker's gateway; counter with DHCP snooping on switches.
ARP — IP to MAC on the local segment
"Who has 192.168.1.1?" is broadcast and the owner replies with its MAC. Replies are accepted without verification, enabling ARP spoofing for man-in-the-middle. Counter with dynamic ARP inspection, static entries for critical hosts and encrypted protocols. See Network Attacks and macof.
NAT — sharing public addresses
Inside 192.168.1.10:51000 --> [NAT router] --> 203.0.113.5:40001 --> Internet
PAT maps many private hosts to one public IP using port numbers. NAT hides internal addressing but is not a firewall; inbound reachability still depends on rules.
HTTP and HTTPS
Request/response protocol over TCP 80 (clear) or 443 (TLS). Request = method (GET, POST, ...) + path + headers + optional body; response = status code (2xx ok, 3xx redirect, 4xx client error, 5xx server error) + headers + body. HTTPS wraps this in TLS for confidentiality and server authentication (see Public Key Infrastructure). Web-layer risks are in Application Attacks.
Routing, Switching and Devices
| Device | Layer | Role |
|---|---|---|
| Hub | 1 | Repeats bits to all ports (obsolete; sniffable) |
| Switch | 2 | Forwards frames by MAC using a CAM table; VLANs split broadcast domains |
| Router | 3 | Forwards packets between networks by IP and routing table |
| Firewall | 3-7 | Filters traffic by policy; see Firewalls and IDS/IPS |
| IDS/IPS | 3-7 | Detects (and blocks) malicious traffic |
| Proxy / load balancer | 7 | Brokers and distributes application traffic |
| Access point | 1-2 | Wi-Fi to wired bridge; see Wireless Security |
Switching moves frames inside a network; routing moves packets between networks. A switch that has its CAM table flooded fails open and behaves like a hub. A VPN builds an encrypted tunnel across untrusted networks (VPN and Tunneling).
Seeing It on the Wire
ip addr # interfaces and addresses (Linux)
ip route # routing table
ss -tulpn # listening TCP/UDP sockets
dig example.com A # DNS lookup
tcpdump -i eth0 'tcp port 443' # capture traffic
Capturing and filtering packets is covered in Wireshark and tcpdump.
Key Points
- Know OSI layers 1-7 and how TCP/IP maps to them; each layer adds a header (encapsulation).
- CIDR defines the network boundary; use RFC 1918 ranges internally.
- TCP = handshake, flags, reliability; UDP = fast, stateless. Scans and floods abuse flags.
- Memorise the common ports and prefer their encrypted replacements.
- DNS, DHCP and ARP trust whoever answers first, which is why they are classic attack points.
- NAT is not security; switches work at layer 2, routers at layer 3.