Networking Fundamentals

The networking knowledge a security practitioner needs — OSI and TCP/IP, encapsulation, addressing and subnetting, TCP and UDP, common ports, DNS, DHCP, ARP, NAT, HTTP and network devices.

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

text
 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.

text
Application:  [          DATA          ]
Transport:    [TCP hdr][    DATA      ]
Network:      [IP hdr][TCP hdr][ DATA ]
Link:      [Eth hdr][IP hdr][TCP hdr][ DATA ][Eth trailer]


Addressing

AddressLayerScopeExample
MAC2Local network segment; burned in but spoofable00:1A:2B:3C:4D:5E
IPv43Routable, 32 bits192.168.1.10
IPv63Routable, 128 bits2001:db8::1
Port4Identifies the service/process, 0-65535443

Private ranges (RFC 1918) and special addresses

RangeCIDRNotes
10.0.0.0 - 10.255.255.25510.0.0.0/8Large internal networks
172.16.0.0 - 172.31.255.255172.16.0.0/12
192.168.0.0 - 192.168.255.255192.168.0.0/16Home/office
127.0.0.0/8loopback127.0.0.1 is the local host
169.254.0.0/16link-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.

text
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)

CIDRMaskAddresses
/8255.0.0.016,777,216
/16255.255.0.065,536
/24255.255.255.0256
/30255.255.255.2524 (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

TCPUDP
ConnectionConnection-oriented, reliableConnectionless, best effort
Ordering / retransmitYesNo
OverheadHigherLower
Used byHTTP(S), SSH, SMTP, databasesDNS, DHCP, VoIP, streaming, NTP, VPNs

Three-way handshake

text
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)

FlagMeaningSecurity relevance
SYNStart connectionSYN scans, SYN flood DoS
ACKAcknowledgeUsed by ACK scans to map firewall rules
FINGraceful closeFIN/Xmas/Null scans abuse unusual flags
RSTAbortClosed port reply in scans
PSH / URGPush data / urgentRarely used; flag anomalies stand out

Scan techniques built on these flags are covered in Nmap; flood attacks in Network Attacks.

Common ports and protocols

PortProtoServiceSecure? Alternative
20/21TCPFTPNo (clear text) -> SFTP (22) / FTPS (990)
22TCPSSH / SFTP / SCPYes
23TCPTelnetNo -> SSH
25TCPSMTP (server to server)Often unencrypted -> STARTTLS / 587, 465
53UDP/TCPDNSPlain -> DoT (853), DoH (443)
67/68UDPDHCPNo authentication
69UDPTFTPNo (no auth) -> SFTP
80TCPHTTPNo -> HTTPS
88TCP/UDPKerberosYes (ticket based)
110TCPPOP3No -> POP3S (995)
123UDPNTPUnauthenticated by default; abused for amplification
135/139/445TCPRPC, NetBIOS, SMBLegacy SMBv1 unsafe; do not expose
143TCPIMAPNo -> IMAPS (993)
161/162UDPSNMPv1/v2c clear text -> SNMPv3
389TCP/UDPLDAPNo -> LDAPS (636)
443TCPHTTPSYes (TLS)
514UDPSyslogNo -> TLS syslog (6514)
1433 / 3306 / 5432TCPMSSQL / MySQL / PostgreSQLNever expose to the internet
3389TCPRDPProtect with VPN/NLA/MFA
5900TCPVNCWeak 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

text
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

text
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

DeviceLayerRole
Hub1Repeats bits to all ports (obsolete; sniffable)
Switch2Forwards frames by MAC using a CAM table; VLANs split broadcast domains
Router3Forwards packets between networks by IP and routing table
Firewall3-7Filters traffic by policy; see Firewalls and IDS/IPS
IDS/IPS3-7Detects (and blocks) malicious traffic
Proxy / load balancer7Brokers and distributes application traffic
Access point1-2Wi-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

bash
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.