Part 1 ยท Chapter 3

The Internet's Invisible Roads

How TCP/IP, DNS, and HTTP actually work โ€” the plumbing behind every web request.

What you'll learn in this chapter

  • How data travels across the internet using IP addresses and routing
  • What DNS is and how your browser translates google.com into a connection
  • The difference between TCP and UDP โ€” and when each is used
  • How HTTP and HTTPS work, including the anatomy of a request and response
  • Ports: what they are and which ones every DevOps engineer must know by heart
  • Firewalls and security groups โ€” the gatekeepers of your servers

The City Postal Service Analogy

Before we talk about packets and protocols, let us build an analogy that will make everything else click.

Imagine a massive city โ€” bigger than Lagos, bigger than Cairo, bigger than any city that exists. This city has millions of buildings. Every single building has a unique address. Inside each building, there are dozens of departments, each handling a specific type of business.

Now imagine you want to send a letter from your office to the accounts department of a building across the city. Here is what happens:

  • You write the letter (the data).
  • You put it in an envelope with the recipient's building address (the IP address) and the department number (the port).
  • The postal service takes your envelope and routes it through various sorting offices (routers).
  • The letter arrives at the right building. The security guard at the front door checks the department number and only lets it through if that department is open and accepting mail (a firewall).
  • The correct department receives it and sends a reply.

That entire process โ€” end to end โ€” is how data travels across the internet. The letter is a packet. The envelope address is the IP address. The department number is the port. The sorting offices are routers. The security guard is a firewall.

IP Addresses โ€” The Unique Addresses of the Internet

Every device connected to the internet has an IP address โ€” a unique numerical identifier, like a postal address for the digital world. There are two versions of IP in use today.

IPv4 addresses look like four numbers separated by dots, each between 0 and 255: 192.168.1.1 or 203.0.113.45. IPv4 can represent about 4.3 billion unique addresses โ€” which seemed like plenty when it was designed in 1981. It was not. The internet grew far beyond what anyone imagined, and we ran out.

IPv6 was created to solve this problem. IPv6 addresses look like this: 2001:0db8:85a3:0000:0000:8a2e:0370:7334. IPv6 supports a number so large it is practically infinite โ€” roughly 340 undecillion addresses. Your city postal service analogy now works for every atom in the observable universe.

Public vs. Private IP Addresses

Not all IP addresses are visible on the public internet. There are ranges reserved for private use โ€” only accessible within a local network:

  • 10.0.0.0 โ€“ 10.255.255.255 โ€” Large private networks (common in AWS VPCs)
  • 172.16.0.0 โ€“ 172.31.255.255 โ€” Medium private networks
  • 192.168.0.0 โ€“ 192.168.255.255 โ€” Small private networks (your home router uses this)

Your home router gets one public IP address from your ISP. It then assigns private IP addresses to your phone, laptop, and smart TV. When any of those devices sends a request to the internet, the router translates the private address to its public one โ€” this process is called NAT (Network Address Translation).

One address you will see constantly in DevOps work: 127.0.0.1 โ€” called localhost. This always refers to the machine itself. When you run a server locally and visit http://localhost:3000, you are connecting to your own machine using the loopback address.

๐Ÿ“š Key Terms

IP Address: A unique numerical identifier for a device on a network.

Public IP: An address reachable from anywhere on the internet.

Private IP: An address only reachable within a local network.

Localhost (127.0.0.1): Always refers to the current machine. Used to access services running on the same computer.

DNS โ€” The Phone Book of the Internet

Humans are bad at remembering numbers. We are good at remembering names. google.com is easy to remember. 142.250.80.46 is not. The Domain Name System (DNS) is the service that bridges the gap โ€” it translates human-readable domain names into machine-readable IP addresses.

Think of DNS as a phone book. You know someone's name (the domain). The phone book gives you their number (the IP address). Your device then dials that number to make the connection.

When you type google.com in your browser, a surprisingly sophisticated chain of lookups happens in fractions of a second:

You type: google.com in your browser
         โ”‚
         โ–ผ
Browser cache? โ†’ Not found
         โ”‚
         โ–ผ
Operating System cache? โ†’ Not found
         โ”‚
         โ–ผ
Local DNS Resolver (your ISP, or 8.8.8.8 for Google DNS)
         โ”‚
         โ–ผ
Root Nameserver (.) โ†’ "Ask the .com TLD server"
         โ”‚
         โ–ผ
.com TLD Nameserver โ†’ "Ask Google's nameserver"
         โ”‚
         โ–ผ
Google's Authoritative DNS Server
         โ”‚
         โ–ผ
Answer: 142.250.80.46
         โ”‚
         โ–ผ
Browser connects to 142.250.80.46 on port 443 (HTTPS)

The whole process usually takes under 100 milliseconds โ€” and most of it is cached, so repeat visits skip straight to the answer.

DNS Record Types

DNS is not just one thing. There are different types of DNS records, each serving a different purpose. As a DevOps engineer, you will configure these when you set up domains for your applications:

Record Type What It Does Example
A Maps a domain name to an IPv4 address myapp.com โ†’ 203.0.113.10
AAAA Maps a domain name to an IPv6 address myapp.com โ†’ 2001:db8::1
CNAME Creates an alias pointing to another domain www.myapp.com โ†’ myapp.com
MX Specifies the mail server for a domain myapp.com โ†’ mail.myapp.com
TXT Stores text โ€” used for domain verification, SPF, DKIM v=spf1 include:sendgrid.net ~all
NS Delegates DNS authority to specific nameservers ns1.cloudflare.com

DNS Commands

# Look up the IP address for a domain
dig google.com

# Look up a specific record type
dig MX gmail.com

# Simple lookup (older tool, still works)
nslookup google.com

# Verbose HTTP request showing DNS, connection, and response details
curl -v https://google.com

# Trace the full DNS resolution chain
dig +trace google.com

TCP vs. UDP โ€” Reliable vs. Fast

Data travels across the internet in small chunks called packets. A single web page request might be broken into dozens of packets, each finding its own route to the destination and reassembled in order when they arrive. There are two main protocols that govern how these packets are sent.

TCP โ€” The Reliable Protocol

TCP (Transmission Control Protocol) is like certified mail. Before any data is sent, TCP performs a handshake to establish a connection. During transmission, it verifies that every packet arrived and in the right order. If a packet is lost, it is retransmitted. Nothing arrives out of order. Nothing gets lost.

TCP Three-Way Handshake:

Client                              Server
  โ”‚                                    โ”‚
  โ”‚โ”€โ”€โ”€โ”€ SYN ("I want to talk") โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚
  โ”‚                                    โ”‚
  โ”‚โ—„โ”€โ”€โ”€ SYN-ACK ("OK, I'm listening") โ”€โ”‚
  โ”‚                                    โ”‚
  โ”‚โ”€โ”€โ”€โ”€ ACK ("Great, let's go") โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚
  โ”‚                                    โ”‚
  โ”‚   [Connection established]         โ”‚
  โ”‚   [Data exchange begins]           โ”‚

This reliability comes at a cost: all that confirmation overhead takes time. TCP is used for HTTP, HTTPS, SSH, email (SMTP, IMAP), and databases โ€” anywhere you need guaranteed, ordered delivery and cannot afford to lose data.

UDP โ€” The Fast Protocol

UDP (User Datagram Protocol) is like sending a postcard. You write it, drop it in the mailbox, and move on. You have no idea if it arrived. You have no idea if it arrived in order. You do not care โ€” you have already sent the next postcard.

UDP is used when speed matters more than reliability: video streaming (if one frame is lost, the next one comes immediately anyway), online games (a slightly stale position is better than waiting), DNS (the overhead of TCP for a tiny lookup would be wasteful), and VoIP calls. The applications using UDP handle loss tolerance in their own logic.

๐Ÿ“ฌ TCP vs UDP in Plain Language

TCP: "Here is packet 1. Did you get it? Great. Here is packet 2. Did you get it? Great. Here is packet 3. Wait โ€” you didn't get packet 3? Let me resend it. OK, got it? Continuing with packet 4..." Slow but guaranteed.

UDP: "Packet 1! Packet 2! Packet 3! Packet 4! Packet 5! Done." Fast but some may be lost.

HTTP and HTTPS โ€” The Language of the Web

HTTP (HyperText Transfer Protocol) is the language that browsers and web servers speak to each other. Every time you load a webpage, fetch data from an API, or submit a form, an HTTP transaction is happening underneath.

The Anatomy of an HTTP Request

An HTTP request has three parts: a method, a URL, and optionally a body.

The method says what you want to do:

  • GET โ€” fetch a resource (read)
  • POST โ€” create a new resource (send data to the server)
  • PUT โ€” replace a resource completely (update)
  • PATCH โ€” partially update a resource
  • DELETE โ€” remove a resource
HTTP Request:
GET /api/users HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Accept: application/json
Content-Type: application/json

HTTP Response:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 234
X-Request-ID: abc-123

{
  "users": [
    { "id": 1, "name": "Ushahemba", "role": "admin" },
    { "id": 2, "name": "Amaka", "role": "user" }
  ]
}

HTTP Status Codes

Every HTTP response includes a status code โ€” a three-digit number that tells you whether the request succeeded or failed, and why. You will see these constantly in logs, API responses, and monitoring dashboards.

Code Meaning When You See It
200 OKSuccessEverything worked
201 CreatedResource createdPOST created a new record
204 No ContentSuccess, nothing to returnDELETE succeeded
301 Moved PermanentlyURL has changed foreverhttp:// redirected to https://
304 Not ModifiedCached version is still freshBrowser uses its cache
400 Bad RequestClient sent invalid dataMissing required field in JSON
401 UnauthorizedNot authenticatedNo token or expired token
403 ForbiddenAuthenticated but not allowedCorrect token, wrong permissions
404 Not FoundResource doesn't existWrong URL or deleted resource
429 Too Many RequestsRate limitedSending requests too fast
500 Internal Server ErrorServer crashedUnhandled exception in your code
502 Bad GatewayUpstream server failedYour app behind Nginx is down
503 Service UnavailableServer overloaded or downDeployment in progress, or server crashed

HTTPS โ€” Adding Encryption to HTTP

HTTPS is HTTP with a security layer called TLS (Transport Layer Security). The padlock you see in your browser's address bar means TLS is active. Without it, anyone on the same network as you can read every HTTP request and response โ€” your credentials, your data, everything.

TLS works through a clever two-phase process:

  1. Asymmetric encryption (handshake): The server has a public key (shared freely) and a private key (secret). The browser uses the server's public key to encrypt a message. Only the server's private key can decrypt it. This lets them exchange a shared secret key securely.
  2. Symmetric encryption (data transfer): Once both sides have the shared secret, all subsequent data is encrypted using that symmetric key. Symmetric encryption is much faster than asymmetric, so the heavy lifting is done efficiently.

TLS certificates are issued by Certificate Authorities (CAs) who vouch that the server is who it claims to be. In production, you will typically use Let's Encrypt (free, automated) or a commercial CA.

# Test an HTTPS connection and see the certificate chain
curl -v https://example.com 2>&1 | grep -A5 "SSL"

# Check when an SSL certificate expires
echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -dates

# Make a simple API GET request
curl https://api.example.com/health

# POST JSON data to an API
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"name": "Ushahemba", "email": "u@example.com"}'

Ports โ€” The Doors on the Building

An IP address gets you to the right building (the server). A port number gets you to the right department inside that building. Ports are numbers from 0 to 65535, and certain port numbers have been standardized for specific services.

As a DevOps engineer, you will need to know these by heart โ€” because they come up in firewall rules, security group configurations, Docker port mappings, and debugging sessions constantly.

Port Protocol / Service When You Encounter It
22SSHConnecting to Linux servers
80HTTPUnencrypted web traffic
443HTTPSEncrypted web traffic โ€” most web apps
3000Node.js (dev)Your local Next.js, Express app
5432PostgreSQLDatabase connections
3306MySQL / MariaDBDatabase connections
6379RedisCache and message queue
27017MongoDBDocument database
5672RabbitMQMessage broker
8080HTTP (alternate)Common for dev servers, Jenkins
9090PrometheusMetrics collection
3100Grafana LokiLog aggregation
# Check which ports are open and listening on your machine
ss -tlnp

# Check if a specific port is reachable on a remote server
telnet 192.168.1.100 5432

# Use nc (netcat) to test port connectivity
nc -zv 192.168.1.100 5432

# See what process is using a specific port
lsof -i :3000

Firewalls and Security Groups โ€” The Gatekeepers

A firewall is a security guard at the door of your server. It examines every incoming and outgoing network connection and decides whether to allow or block it, based on rules you define.

Without a firewall, every port on your server is potentially accessible from anywhere on the internet. That means anyone who knows your IP address could attempt to connect to your database, your Redis cache, your admin panel, or any other service that happens to be listening. This is how servers get compromised.

The principle of least privilege applies here: only open ports that need to be open. A web application typically needs port 80 and 443 open. Port 22 (SSH) should only be open to your IP address or VPN. Your database port (5432) should only be accessible from the application servers that need it โ€” not from the public internet.

UFW โ€” The Linux Firewall Tool

# Check firewall status
sudo ufw status

# Allow SSH (important: do this BEFORE enabling the firewall)
sudo ufw allow 22

# Allow HTTP and HTTPS
sudo ufw allow 80
sudo ufw allow 443

# Allow a specific IP to access a port
sudo ufw allow from 203.0.113.5 to any port 5432

# Enable the firewall
sudo ufw enable

# Deny everything not explicitly allowed
sudo ufw default deny incoming

AWS Security Groups

In cloud environments like AWS, firewalls are called Security Groups. They work the same way โ€” you define inbound and outbound rules โ€” but they are configured through the AWS console or Terraform rather than command-line tools. A typical production security group looks like this:

Web Server Security Group:

Inbound Rules:
  Port 443  (HTTPS)  โ† from 0.0.0.0/0  (the entire internet)
  Port 80   (HTTP)   โ† from 0.0.0.0/0  (redirects to HTTPS)
  Port 22   (SSH)    โ† from 10.0.0.0/8 (only from our VPN)

Outbound Rules:
  All traffic โ†’ 0.0.0.0/0  (servers can talk to the internet)

Database Security Group:
  Port 5432 (PostgreSQL) โ† from Web Server Security Group only
  (The database is NEVER directly reachable from the internet)
โš ๏ธ Never Expose Databases to the Public Internet

One of the most common security mistakes in DevOps is accidentally leaving a database port (5432, 3306, 27017) open to 0.0.0.0/0 (the entire internet). Automated scanners constantly probe the internet for open database ports and attempt default credentials. Always restrict database access to your application servers only, using private IP ranges or security group references.

๐Ÿ“ก Fun Fact: How Fast is the Internet?

Light travels through a fiber optic cable at about 200,000 km per second. The distance between Lagos and London is about 5,000 km. That means the theoretical minimum round-trip time (latency) for a request from Lagos to a London server is about 50ms โ€” just from the physics of light. In practice, with routing overhead, typical latency is 80-120ms. This is why "edge computing" (putting servers closer to users) matters so much for performance.

Chapter Summary

  • The internet works like a postal service: data is addressed with IP addresses and port numbers, routed through networks, and checked by firewalls at the destination.
  • IP addresses identify devices on a network. IPv4 uses four-number notation; IPv6 is longer. 127.0.0.1 always means the local machine.
  • DNS translates domain names (google.com) to IP addresses through a chain of lookups. A records point to IPv4 addresses; CNAMEs are aliases; MX records are for email.
  • TCP provides reliable, ordered delivery with a handshake. UDP provides fast, best-effort delivery. Most web services use TCP; streaming and games often use UDP.
  • HTTP is the language of the web. Requests have methods (GET, POST, PUT, DELETE) and responses have status codes (200, 404, 500). HTTPS adds TLS encryption.
  • Ports are the numbered "departments" on a server. Know the common ones: 22 (SSH), 80 (HTTP), 443 (HTTPS), 5432 (PostgreSQL), 6379 (Redis).
  • Firewalls (and AWS Security Groups) enforce the principle of least privilege โ€” only open the ports that need to be open, to the sources that need access.