Skip to content

Networking Services

DNS is a globally distributed service that translates human-readable domain names (like example.com) into IP addresses (like 93.184.216.34). Without DNS, you’d need to memorize IP addresses to browse the web.

  • User-friendly - you type github.com instead of 140.82.121.4
  • Abstraction - an organization can move servers, change IPs, and users never notice (just update the DNS record)
  • Load balancing - one domain can resolve to multiple IPs (DNS round robin), distributing traffic across servers
  • Email routing - MX records tell the internet which mail server handles @yourdomain.com
  • CDN delivery - DNS can return the nearest edge server based on the user’s location (GeoDNS)
  • Security - DNSSEC adds cryptographic signatures to DNS responses, preventing spoofing and cache poisoning

DNS Server Types

There are 5 types of DNS servers, each with a specific role in the resolution chain:

Server TypeRoleExample
Caching name serverStores previous lookups for TTL duration. Speeds up repeat queries.Your router, local DNS cache
Recursive resolverDoes the full lookup on your behalf - walks the tree from root to authoritativeISP DNS, 8.8.8.8 (Google), 1.1.1.1 (Cloudflare)
Root name serverFirst step - directs resolver to the correct TLD server. 13 root authorities (A through M), distributed globally via Anycasta.root-servers.net through m.root-servers.net
TLD name serverManages a top-level domain (.com, .org, .uk, etc.) and knows which authoritative server handles each domain in that TLDVerisign operates .com and .net TLD servers
Authoritative name serverThe final authority - holds the actual DNS records (A, MX, CNAME, etc.) for a specific domainYour hosting provider’s nameservers

The Full DNS Resolution Process

When you type www.example.com in your browser, here’s what happens:

  1. Local hosts file - OS checks /etc/hosts (Linux/Mac) or C:\Windows\System32\drivers\etc\hosts (Windows) first. If there’s a match, resolution stops here.
  2. Local DNS cache - OS checks its own cache of recent lookups
  3. Recursive resolver - query goes to your configured DNS resolver (usually your ISP’s, or 8.8.8.8 / 1.1.1.1)
  4. Root server - resolver asks a root server “who handles .com?”
  5. TLD server - root directs to .com TLD server. Resolver asks “who handles example.com?”
  6. Authoritative server - TLD directs to example.com’s authoritative nameserver. Resolver asks “what’s the IP for www.example.com?”
  7. IP returned - authoritative server responds with the IP address
  8. Caching - resolver caches the result for the record’s TTL (Time To Live) duration
  9. Response to client - resolver sends the IP back to your browser

TTL (Time To Live) is a value in seconds set by the domain owner. It tells resolvers how long to cache a record before re-querying. Low TTL (60-300s) = faster propagation of changes. High TTL (3600-86400s) = less DNS traffic but slower change propagation.


DNS primarily uses UDP (port 53) instead of TCP. Why?

  • A DNS query + response usually fits in a single UDP datagram - no handshake overhead needed
  • No connection setup/teardown = far fewer packets. A recursive lookup via TCP requires ~44 packets minimum; via UDP, only ~8
  • DNS implements its own retry logic at the application layer - if no response arrives, the resolver simply asks again. No need for TCP’s reliability guarantees

Record TypePurposeExample
AMaps domain to IPv4 addressexample.com -> 93.184.216.34
AAAAMaps domain to IPv6 addressexample.com -> 2606:2800:220:1:...
CNAMEAlias - points one name to anotherwww.example.com -> example.com
MXMail server for the domain (with priority)example.com -> mail.example.com (priority 10)
NSAuthoritative nameservers for the zoneexample.com -> ns1.example.com
SOAStart of Authority - zone metadata (primary NS, admin email, serial, refresh intervals)One per zone
PTRReverse lookup - IP to domain name34.216.184.93.in-addr.arpa -> example.com
TXTArbitrary text - used for SPF, DKIM, domain verificationv=spf1 include:_spf.google.com ~all
SRVService location (host + port for specific services)_sip._tcp.example.com -> sipserver.example.com:5060

A single domain can have multiple A records - this is DNS round robin, a basic form of load balancing where each query returns the records in a different order, distributing traffic across servers.


Anatomy of a Domain Name

https://mail.example.com:443/inbox?sort=date&filter=unread
───┬── ──┬─ ───┬──── ─┬─ ─┬─ ──┬── ─────────┬──────────
Protocol Sub Domain TLD Port Path Query Parameters
domain
ComponentDescription
TLD (Top-Level Domain).com, .org, .net, country codes like .uk, .de. Managed by ICANN.
DomainThe registered name (example). You buy this from a registrar.
SubdomainOptional prefix (mail, www, api). Free to create if you own the domain.
FQDN (Fully Qualified Domain Name)The complete path: mail.example.com. (note the trailing dot - root zone)

Technical limits: Max 127 levels deep, max 63 characters per label, max 255 characters total for an FQDN.


A DNS zone is a portion of the DNS namespace managed by a specific organization. Zones let administrators split large domains into manageable chunks.

  • Zone file - a plain-text file on a DNS server containing all records for that zone. Starts with an SOA record (admin contact, serial number, refresh intervals) followed by NS, A, MX, and other records.
  • Zone transfer - copying zone data from a primary DNS server to secondary servers for redundancy (uses TCP, port 53)
  • Reverse lookup zone - maps IPs back to domain names using PTR records (uses the special in-addr.arpa domain for IPv4)

DHCP - Dynamic Host Configuration Protocol

Section titled “DHCP - Dynamic Host Configuration Protocol”

DHCP

DHCP automates network configuration for client devices. Instead of manually setting IP address, subnet mask, gateway, and DNS server on every device, a DHCP server hands out configurations automatically.

Every host needs 4 things to work on a network:

  1. IP address
  2. Subnet mask
  3. Default gateway (router)
  4. DNS server

DHCP configures all four in one go. Servers and network equipment typically use static IPs (you always need to know where they are). Client devices (laptops, phones) use DHCP.

ModeBehavior
DynamicServer assigns an IP from a pool for a limited lease period. IP returns to pool when lease expires.
AutomaticServer assigns a permanent IP from the pool - same IP every time if possible.
Fixed (reservation)Admin maps specific MAC addresses to specific IPs in a table. Guarantees a device always gets the same IP.

DHCP uses a four-step handshake called DORA: Discover, Offer, Request, Acknowledge. All communication happens over UDP - server listens on port 67, client sends from port 68.

DORA Process

Client (no IP yet) DHCP Server
| |
1. |-- DHCPDISCOVER (broadcast) -------->| "Anyone got an IP for me?"
| src: 0.0.0.0:68 | (sent to 255.255.255.255:67)
| dst: 255.255.255.255:67 |
| |
2. |<-------- DHCPOFFER (broadcast) -----| "Here's 192.168.1.50, lease 24h"
| dst: 255.255.255.255:68 | (includes subnet, gateway, DNS)
| (identifies client by MAC) |
| |
3. |-- DHCPREQUEST (broadcast) --------->| "I'll take that 192.168.1.50"
| (also tells other DHCP servers |
| to withdraw their offers) |
| |
4. |<-------- DHCPACK (broadcast) -------| "Confirmed. It's yours for 24h."
| |
|===== Client configures interface ===|

Edge cases:

  • Multiple DHCP servers - client may receive multiple OFFERs; it accepts one and the others withdraw
  • DHCPDECLINE - client rejects an offer if the IP conflicts with something on the network
  • DHCPNACK - server withdraws the offer (client took too long to respond)
  • Lease renewal - client automatically tries to renew at 50% of lease time (T1) and again at 87.5% (T2)

NAT

NAT allows a router/firewall to rewrite the source IP of outgoing packets so that many devices on a private network can share a single public IP address. The router remembers the mapping and rewrites return traffic back to the correct internal device.

NAT exists because of IPv4 address exhaustion - there are only ~4.2 billion IPv4 addresses, and they ran out:

RIRRegionExhaustion Date
APNICAsia-PacificApril 2011
RIPEEurope, Middle EastSeptember 2012
LACNICLatin America, CaribbeanJune 2014
ARINNorth AmericaSeptember 2015
AFRINICAfricaPhase 2: January 2020

RFC 1918 private address ranges (non-routable on the public internet):

  • 10.0.0.0/8 (10.0.0.0 - 10.255.255.255)
  • 172.16.0.0/12 (172.16.0.0 - 172.31.255.255)
  • 192.168.0.0/16 (192.168.0.0 - 192.168.255.255)

How NAT Works at the Transport Layer

NAT doesn’t just rewrite IPs - it also tracks ports to handle many-to-one mapping:

  • Port preservation - the router tries to keep the client’s original source port. If 192.168.1.10:51234 sends a packet, the router maps it to 203.0.113.1:51234. Return traffic to :51234 gets forwarded back to the correct internal host.
  • Port collision - if two internal hosts pick the same ephemeral port, the router reassigns one to a random unused port
  • Port forwarding - manually maps an incoming destination port to a specific internal IP:port. This is how you expose a web server behind NAT.
Terminal window
# Check NAT/masquerade rules on Linux (iptables)
sudo iptables -t nat -L -n -v
# Set up basic NAT masquerading
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Port forwarding: forward external port 8080 to internal 192.168.1.100:80
sudo iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 192.168.1.100:80
# nftables equivalent
sudo nft add rule nat postrouting oifname "eth0" masquerade

A VPN creates an encrypted tunnel over a public network (the internet), making it appear as if remote devices are on the same local network.

VPN

  1. VPN client establishes an encrypted connection to the VPN server
  2. Client gets a virtual network interface with an IP from the company’s private address space
  3. Application data is encrypted and wrapped inside the transport layer payload of regular packets
  4. At the VPN server, the outer packet is stripped, the payload is decrypted, and the inner packet is forwarded onto the private network

Site-to-site VPN - connects two entire networks (office A to office B) so all devices on both networks can communicate as if they were local. The VPN runs between routers/firewalls, transparent to end users.


A proxy is an intermediary that sits between a client and a server. The client talks to the proxy, and the proxy talks to the server on the client’s behalf.

Proxy Types

TypeDirectionUse Case
Forward proxyClient -> Proxy -> InternetAnonymity, content filtering, corporate access control, caching
Reverse proxyInternet -> Proxy -> Backend serversLoad balancing, SSL termination, caching, DDoS protection
Transparent proxyInvisible to client (network-level intercept)ISP content filtering, corporate monitoring

Forward proxy - historically used for caching (save bandwidth by serving cached copies of frequently accessed pages). Today mostly used for content filtering and access control in corporate networks.

Reverse proxy - the client thinks it’s talking to one server, but the proxy distributes requests across multiple backend servers. Also handles TLS termination (offloading encryption from backend servers). Examples: Nginx, HAProxy, Cloudflare, AWS ALB.