Foundations ยท Chapter 3

Networking essentials

IP addresses, ports, DNS, TCP and HTTP: the plumbing every attack and every defense runs on, with tools to see it for yourself.

About 4 min read

You can't secure what you can't see, and almost everything you'll protect talks over a network. This chapter is the minimum model you need in your head.

The layers, practically

Forget memorizing seven OSI layers. Keep four in mind:

Layer Question it answers Examples
Link How do machines on the same network reach each other? Ethernet, Wi-Fi, MAC addresses, ARP
Internet How does a packet find a machine anywhere? IP addresses, routing
Transport Which program on that machine, and is delivery reliable? TCP, UDP, ports
Application What are the two programs saying? HTTP, DNS, SSH, SMTP, TLS

IP addresses and private ranges

An IPv4 address is four numbers 0โ€“255: 192.168.1.20. Some ranges are private and never appear on the public internet:

  • 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16: home and office networks, Docker networks, cloud VPCs.
  • 127.0.0.1: this machine (loopback). A service bound here is invisible from outside.
  • 169.254.169.254: the cloud metadata service on AWS, Azure and GCP. Remember it for chapter 6.

/24 is CIDR notation: the first 24 bits are the network, so 192.168.1.0/24 is 256 addresses.

ifconfig            # macOS: your interfaces and addresses
ip a                # Linux equivalent
netstat -rn         # routing table

Ports, TCP and UDP

A port picks the program on a machine. Learn the common ones by heart:

Port Service Port Service
21 FTP 445 SMB (Windows shares)
22 SSH 3306 MySQL
25 SMTP 3389 RDP
53 DNS 5432 PostgreSQL
80 / 443 HTTP / HTTPS 6379 Redis
110 / 143 POP3 / IMAP 8080 / 8443 Alternate web ports

TCP sets up a connection with a three-way handshake (SYN โ†’ SYN-ACK โ†’ ACK) and guarantees ordered delivery. UDP just sends; DNS and video streaming use it.

DNS

DNS turns names into addresses. Record types worth knowing:

  • A / AAAA: name โ†’ IPv4 / IPv6
  • CNAME: name โ†’ another name
  • MX: where mail goes
  • TXT: free text, used for SPF, DKIM, domain verification
  • NS: who's authoritative for the domain
dig nlpointer.com          # A record
dig nlpointer.com MX
dig +short TXT nlpointer.com

Defensive note: dangling CNAME records that point at deleted cloud resources can let someone else claim the resource and serve content on your subdomain ("subdomain takeover"). Audit your DNS when you delete things.

HTTP in one screen

HTTP is text. A request:

POST /api/v1/auth/login HTTP/1.1
Host: api.example.com
Content-Type: application/json
Cookie: theme=dark

{"username":"tomas","password":"..."}

A response:

HTTP/1.1 200 OK
Set-Cookie: session=abc123; HttpOnly; Secure; SameSite=Lax
Content-Type: application/json

{"ok":true}

Status codes: 2xx fine, 3xx redirect, 4xx your fault (401 not logged in, 403 not allowed, 404 not found, 429 slow down), 5xx server's fault.

curl -i https://nlpointer.com shows you the response headers of your own site. Do it now and look for Strict-Transport-Security, Content-Security-Policy and X-Content-Type-Options.

TLS

HTTPS is HTTP inside TLS. TLS gives you confidentiality, integrity and proof of the server's identity via a certificate. It doesn't protect against a vulnerable application; it only protects the pipe.

openssl s_client -connect nlpointer.com:443 -servername nlpointer.com </dev/null | openssl x509 -noout -dates -subject

Seeing traffic yourself

  • Browser DevTools โ†’ Network tab. Every request your browser makes. Start here.
  • Wireshark. Captures packets on your own machine. Try capturing while you load a plain http:// site and follow the TCP stream; you'll see why HTTPS matters.
  • nmap. Discovers hosts and open ports. Use it only on your own lab network:
nmap -sV 127.0.0.1          # which services run on your own Mac?
nmap -sn 172.30.0.0/24      # which hosts are up in the lab's Docker network?

Running nmap on your own Mac is a great first exercise: you'll often find services you forgot were listening.

Firewalls and segmentation

The cheapest security control is "this can't reach that". Databases shouldn't be on the internet. Admin panels shouldn't be on the public network. In the Hacking Lab, the vulnerable machines sit on an internal Docker network with no route out, the same idea at small scale.

Check yourself

  1. Why is a service on 127.0.0.1:5432 safer than one on 0.0.0.0:5432?
  2. What's the difference between a 401 and a 403?
  3. What does HttpOnly on a cookie prevent?
  4. Run nmap -sV 127.0.0.1 on your Mac. What did you find, and do you need all of it?

Practise only on systems you own or are explicitly allowed to test: your home lab, CTF platforms and authorized engagements. Testing anyone else's system without permission is a crime in most countries, including under the US Computer Fraud and Abuse Act. Your reading progress stays in this browser.