intermediate
IP addressing and ports
Know IPv4/IPv6 basics, private ranges, NAT, sockets, well-known ports, ephemeral ports, and how services bind and listen.
IPv4 uses 32-bit addresses; private ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) sit behind NAT for outbound internet access. IPv6 uses 128-bit addresses and often avoids NAT at the edge. A socket is (protocol, local IP, local port, remote IP, remote port).
Well-known ports: 80 HTTP, 443 HTTPS, 5432 PostgreSQL. Ephemeral ports (roughly 32768–60999 on Linux) are consumed per outbound TCP connection — high churn services can exhaust them.
import { createServer } from 'node:http';
createServer((req, res) => res.end('ok')).listen(3000, '0.0.0.0');
Binding `0.0.0.0` listens on all interfaces; container and cloud networking add overlay IPs and security groups that filter ports independently of the app.
On interviews: explain NAT, why localhost differs from container DNS names, port conflicts on deploy, and health-check port alignment.
Common pitfalls: binding only to localhost inside Kubernetes; confusing host port with container port; firewall rules blocking internal service mesh traffic.
The trade-off is balancing simplicity, performance, safety, and operability — name which axis you optimized and what cost you accepted.
Checklist:
- Know private vs public address ranges.
- Explain ephemeral port exhaustion symptoms.
- Match listen address to deployment environment.
- Align health checks with actual listen ports.