Server Networking: Opening the Pipes
A server with no network is just an expensive space heater. In this module, you will learn how a
server gets its address, why DHCP is great for laptops but risky for servers,
how DNS turns names into IPs, what 0.0.0.0 vs
127.0.0.1 really means, and how host firewalls protect every open
port.
01 Server IP Addressing: IP, Subnet Mask & Default Gateway
Define: Every server on a network needs three core numbers to communicate: an IP Address (its unique identifier), a Subnet Mask (which defines who is local), and a Default Gateway (the router that leads to the outside world).
๐๏ธ Universal Analogy: Street, Neighborhood & Highway Exit
Imagine mailing a letter in a city. Your IP Address
(e.g., 192.168.10.50) is your house number and street. Your
Subnet Mask (255.255.255.0 or /24) is your
neighborhood boundaryโit tells you which houses you can walk to directly
without getting on a highway. Your Default Gateway (192.168.10.1)
is the highway on-ramp: if a packet needs to visit Google or another subnet,
your server hands it to the gateway to leave the neighborhood.
Understand How the Three Numbers Work Together
- Static IP Address: A permanent, manually assigned IP (or DHCP reservation) so users, load balancers, and DNS records can always find the server at the exact same address.
- Subnet Mask / CIDR (
/24): Splits the IP into a Network portion (192.168.10) and a Host portion (.50). Any IP from192.168.10.1to192.168.10.254is in the same local neighborhood. - Default Gateway: Almost always the
.1(or.254) address on that subnet. Without a valid gateway, your server can talk to machines in the same room, but cannot reach the internet.
Know When to Check & Execute on Linux and Windows
When: Run these commands right after provisioning a new server or whenever a server
can ping its neighbor (192.168.10.60) but cannot reach the internet
(8.8.8.8).
# Linux (Modern iproute2) โ Check IP, Subnet (/24), and Default Gateway
ip addr show
ip route show # Look for: default via 192.168.10.1 dev eth0
# Linux (Netplan static config example: /etc/netplan/01-netcfg.yaml)
# addresses: [192.168.10.50/24]
# routes: [{ to: default, via: 192.168.10.1 }]
# Windows Server (PowerShell) โ View IP & Default Gateway
Get-NetIPConfiguration
๐งช Practice Problem 1: The Isolated Server
Your new Linux server has IP 10.0.5.25/24. You can successfully
ping 10.0.5.10 (a neighbor server), but ping 1.1.1.1 fails with
Network is unreachable. What is most likely missing?
Show Solution
The server is missing a Default Gateway (default route) in
ip route show. Because 10.0.5.10 is in the same
/24 neighborhood, the server reaches it directly without a gateway. Reaching
1.1.1.1 requires a highway exit (e.g., default via 10.0.5.1).
02 DHCP & the DORA Process
Define: DHCP (Dynamic Host Configuration Protocol) automatically assigns an IP address, subnet mask, default gateway, and DNS servers to a device when it joins a networkโusing a 4-step conversation called DORA.
๐ง Memory Trick: D-O-R-A
Think of a newcomer shouting in a crowded room to rent an apartment: Discover ("Any empty rooms?"), Offer ("Room 104 is free!"), Request ("I'll take Room 104!"), Acknowledge ("Deal! Here are your keys for 24 hours.").
โ ๏ธ Why Production Servers Avoid Plain DHCP
DHCP leases expire. If a database server reboots after a power outage
and gets a new random IP from DHCP (say .124 instead of
.120), every web app pointing to .120 immediately crashes.
Rule of thumb: Laptops and phones use DHCP; servers use either a
Static IP configured on the OS or a DHCP Reservation (pinned to
the server's MAC address).
03 DNS Records Every Server Admin Must Know
Define: DNS (Domain Name System) is the internet's phonebookโit
translates human-friendly names like api.shekharit.com into machine-friendly IP
addresses like 203.0.113.10.
IPv4 Address
Maps a hostname to a 32-bit IPv4 address (e.g., web.site.com โ 203.0.113.10).
IPv6 Address
Maps a hostname to a 128-bit IPv6 address (e.g., 2001:db8::1). "Quad-A" = 4ร
bigger than A.
Canonical Name
Creates an alias pointing one domain name to another name (e.g.,
www โ site.com).
Mail Exchange
Tells the world which mail servers accept email for your domain, ordered by priority.
Text Record
Stores arbitrary text for domain ownership verification and email security (SPF, DKIM, DMARC).
Pointer (Reverse)
Reverse DNS: maps an IP address back to a hostname. Critical for outbound mail servers.
The Local Override: /etc/hosts
Before your server ever asks a DNS server on the network, it checks its own local notepad first:
/etc/hosts on Linux (or C:\Windows\System32\drivers\etc\hosts on Windows).
Admins use this to test a new server before updating public DNS.
# Test DNS records from the terminal
dig +short shekharit.com A
dig +short shekharit.com MX
nslookup -type=TXT shekharit.com
# Check local /etc/hosts override
cat /etc/hosts
# 127.0.0.1 localhost
# 10.0.1.50 staging-api.internal
โ DNS & DHCP Checkpoint
- DORA = Discover, Offer, Request, Acknowledge.
- Servers use Static IPs or DHCP Reservations so their IP never drifts.
- A = IPv4, AAAA = IPv6, CNAME = Alias, MX = Mail, TXT = Verification/SPF, PTR = Reverse IPโName.
04 Listening Sockets: 0.0.0.0 vs 127.0.0.1
Define: When a server program starts (like Nginx, Node.js, or PostgreSQL), it must bind to an IP address and a port numberโcreating a listening socket. The IP you choose decides who can knock on that door.
๐ช Analogy: Front Door vs. Internal Hallway
Binding to 0.0.0.0:443 is like opening your
Front Door to every network cable plugged into the server (public internet,
LAN, and localhost). Binding to 127.0.0.1:5432 (the loopback
address) is like putting a door inside an Internal Hallwayโonly programs
already running inside the same server can walk through it. Anyone outside on the
network is physically unable to reach it.
Execute: Inspect Open Sockets with ss
# Linux: Show all TCP & UDP listening sockets with process names
sudo ss -tulpn
# Example output:
# LISTEN 0 511 0.0.0.0:443 0.0.0.0:* users:(("nginx",pid=1024,fd=6))
# LISTEN 0 128 127.0.0.1:5432 0.0.0.0:* users:(("postgres",pid=890,fd=5))
๐งช Practice Problem 2: The "It Works on the Server, Not My Laptop" Mystery
You started a Python web app on your Linux server, and curl http://localhost:8000
works when you SSH into the server. But when you open http://<server-ip>:8000
from your laptop, it refuses to connect. Running ss -tulpn shows
127.0.0.1:8000. Why?
Show Solution
The app is bound to 127.0.0.1:8000 (the internal loopback), so it only
accepts connections from inside the server itself. To accept external traffic (or
traffic via a reverse proxy), bind it to 0.0.0.0:8000โor keep it on
127.0.0.1:8000 and put Nginx on 0.0.0.0:443 in front of it!
05 Host Firewalls: Default Deny, Allow Specific Ports
Define: A Host Firewall is software running directly inside your server's OS kernel that inspects every incoming and outgoing packet. Golden Rule: Default Deny incoming, Allow only the specific ports you need.
Comparison: Linux & Windows Host Firewalls
| OS Family | Firewall Tool | Allow Port 443 Command |
|---|---|---|
| Ubuntu / Debian | ufw (Uncomplicated Firewall) |
sudo ufw allow 443/tcp |
| RHEL / Rocky / Alma | firewalld |
sudo firewall-cmd --permanent --add-service=https && sudo firewall-cmd --reload |
| Windows Server | Windows Defender Firewall | New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -LocalPort 443 -Protocol TCP -Action Allow |
๐จ Never Lock Yourself Out of SSH!
When enabling ufw on a remote cloud server,
ALWAYS run sudo ufw allow OpenSSH (or 22/tcp)
before running sudo ufw enable. Otherwise, the default-deny policy will
immediately drop your active SSH session.
# Safe UFW setup sequence on Ubuntu/Debian
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose