Computer networks: addresses, subnets, routing, and DNS for security work
How a packet finds its way: IPv4 and IPv6 addresses, CIDR subnets, gateways, NAT, and DNS, with the commands that show each on your own machine.
Diagram
What happens when a browser opens a name
Step 1 of 4
Resolve
The resolver turns a name into an address.
dig +short www.example.com A 93.184.215.14
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Subnets set who is local
- What fails
- Hosts in the same subnet talk directly; everything else goes through a router that can filter.
- Who is affected
- Every host on a flat network if one is compromised.
- What you would notice
- Servers, laptops, and cameras all in one /16.
- What you change
- Segment by role and put filtering at the boundaries.
The gateway and resolver are trusted
- What fails
- Whoever answers as gateway or DNS server sees or steers traffic.
- Who is affected
- Every client that accepts the answer.
- What you would notice
- A second DHCP server or an unexpected resolver in ip route or resolvectl output.
- What you change
- Pin resolvers, enable DHCP snooping, and alert on new gateways.
Reading an address and prefix
An IPv4 address with a prefix such as 192.168.56.20/24 says the first 24 bits name the network and the last 8 name the host, so the subnet holds 192.168.56.0 to 192.168.56.255. A /16 holds 65,536 addresses. IPv6 uses 128-bit addresses, normally a /64 per subnet, and hosts often have several addresses at once, including a link-local fe80:: address.
Private ranges are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. 127.0.0.0/8 is loopback. 169.254.0.0/16 is link-local and is also where many cloud metadata services live, which matters for SSRF.
$ ipcalc 10.20.0.0/22 Network: 10.20.0.0/22 HostMin: 10.20.0.1 HostMax: 10.20.3.254 Hosts/Net: 1022
DNS records you will meet
A and AAAA map names to IPv4 and IPv6 addresses. CNAME aliases one name to another, and a dangling CNAME is how subdomain takeovers happen. MX names mail servers. TXT holds SPF, DKIM, DMARC, and verification tokens. NS delegates a zone. Use dig against your own domains to see what you publish.
$ dig +noall +answer example.org MX TXT example.org. 300 IN MX 10 mail.example.org. example.org. 300 IN TXT "v=spf1 include:_spf.mailprovider.example -all"
From an address to a service
An address reaches a host; a port reaches a program. The pair of addresses and ports identifies each connection, which is what firewalls, NAT tables, and packet captures key on. The ports and protocols lesson goes into the common services.
Check yourself
Recognition and the fix. Nothing here is a procedure.
How many addresses does a /24 IPv4 subnet contain?
Go deeper
Specific techniques, exercises, and glossary cards for this topic.
- 01Which resolver and which DHCP server you trustHosts believe the answers they are given for names and for their own address. Includes the diagram and a defensive fix.
- 02Keep the management plane off the guest networkSSH, hypervisors, database ports, and switch admin interfaces are not guest services. Includes the diagram and a defensive fix.
- 03Network protocols for defenders: what each layer tells you in a captureEthernet, IP, TCP, UDP, DNS, TLS, and HTTP as they appear in a packet capture: the fields worth reading at each layer, a worked tcpdump trace of one web request, and which protocols leak what. Includes the diagram and a defensive fix.
- 04Ports and protocols: TCP, UDP, common services, and what a listening port tells youHow TCP and UDP ports identify services, the ports worth recognizing on sight, and how to list what your own machine is listening on and why each listener exists. Includes the diagram and a defensive fix.
- 05Man-in-the-middle attacks: where interception happens and what stops itInterception can happen on the local link, in DNS, at a rogue Wi-Fi access point, or through a trusted proxy. Includes the diagram and a defensive fix.
- 06Denial of service and DDoS: volumetric, protocol, and application floodsThe three families of denial-of-service attack, what each exhausts (bandwidth, connection state, or application work), how botnets and reflection amplify them, and the layered defenses from upstream scrubbing to rate limits. Includes the diagram and a defensive fix.
- 07ARP spoofing: detecting forged neighbor replies on a LANARP has no authentication, so any host on a VLAN can claim to be the gateway. Includes the diagram and a defensive fix.
- 08DNS spoofing and cache poisoning: forged answers and how DNSSEC helpsForged DNS answers send users to the wrong address. Includes the diagram and a defensive fix.
- 09TCP/IP weaknesses: spoofing, fragmentation, and session hijacking explainedIP was designed without authentication, which allows spoofed source addresses, fragment tricks, and TCP reset or hijack attacks. Includes the diagram and a defensive fix.
- 10Port scanning and network mapping with Nmap: scope, options, and reading resultsHow to map hosts and services on networks you are authorized to test: discovery, TCP connect and SYN scans, version detection, and reading open, closed, and filtered states. Includes the diagram and a defensive fix.
- 11Network traffic analysis: from packet capture to findings with Zeek and WiresharkHow to capture and analyze traffic for an investigation: where to capture, how to keep evidence intact, how Zeek turns pcaps into connection, DNS, and TLS logs, and a worked example that finds a beaconing host. Includes the diagram and a defensive fix.
- 12ICMP redirects: why hosts should ignore route hints from the LANICMP redirect messages tell a host to use a different gateway, and a forged one can reroute traffic. Includes the diagram and a defensive fix.
- 13hping3 in a lab: crafting TCP packets to see SYN floods and firewall behaviorhping3 builds custom TCP, UDP, and ICMP packets, which makes it a teaching tool for how SYN floods fill connection tables and how firewalls answer. Includes the diagram and a defensive fix.
- 14Yersinia and layer 2 protocol risks: STP, DTP, CDP, and DHCP on switchesYersinia is a lab framework for testing layer 2 protocols such as STP, DTP, CDP, and DHCP. Includes the diagram and a defensive fix.
- 15BGP hijacking: route origin validation with RPKI and monitoringBGP routers trust announcements from peers, so a wrong origin or more-specific prefix can pull traffic away. Includes the diagram and a defensive fix.
- 16Egress filtering: controlling what can leave your networkMost networks filter inbound traffic carefully and let everything out. Includes the diagram and a defensive fix.
- 17Downgrade attacks: forcing weaker protocols and how modern TLS prevents itA downgrade pushes two parties onto an older, weaker protocol or cipher than both support. Includes the diagram and a defensive fix.
- 18Zero trust, practically: identity, device, and per-request decisionsZero trust replaces “inside the network means trusted” with a decision on every request based on user, device, and context. Includes the diagram and a defensive fix.
Exercises
- 01Terminal mission: Database ports published to the worldA Compose file publishes ports for five services. Work out which ones listen on every interface, which are bound to localhost only, and why the host firewall does not save you.
- 02Terminal mission: TLS 1.0 hiding in an includeThe main TLS settings look fine, but one server block includes an old snippet. Follow nginx includes to find the site that still allows TLS 1.0 and a 3DES cipher.
Glossary
- 01Denial of serviceTraffic, expensive requests, or a fragile protocol state exhausts a service so legitimate users cannot use it.
- 02ARP spoofingOn a local network, a host claims to be the gateway and sees traffic that was not meant for it.
- 03DNS spoofingA resolver is fed a lie, and a name points at the wrong address.
- 04BGP hijackingA network announces address space it does not own, and some of the internet believes it.