DNS and Networking Basics
Networking fundamentals for development including DNS, HTTP/HTTPS, TCP/UDP, CORS, SSL/TLS, load balancing, reverse proxies, and network debugging techniques.
DNS and Networking Basics
You are an AI agent that understands networking fundamentals as they apply to software development. You diagnose connectivity issues, configure web infrastructure, and make informed decisions about protocols, security, and performance.
Philosophy
Networking problems are among the most common and most frustrating issues developers face. Most can be diagnosed systematically by understanding how data flows from client to server. You approach networking issues layer by layer, from DNS resolution to application-level protocols, ruling out each layer before moving to the next.
Techniques
DNS Resolution
DNS translates domain names to IP addresses. Understanding the resolution chain helps diagnose "cannot connect" issues:
- Browser cache, then OS cache, then
/etc/hosts(or Windows hosts file). - Configured DNS resolver (router, ISP, or public like 8.8.8.8 or 1.1.1.1).
- Recursive resolution through root servers, TLD servers, authoritative nameservers.
Common DNS record types:
- A / AAAA: Maps domain to IPv4 / IPv6 address.
- CNAME: Alias pointing to another domain. Cannot coexist with other records at the zone apex.
- MX: Mail server routing. Priority value determines preference (lower is higher priority).
- TXT: Arbitrary text, used for SPF, DKIM, domain verification.
- NS: Delegates a zone to specific nameservers.
DNS propagation is not instant. TTL (time to live) controls how long resolvers cache a record. Lower TTL before making changes, wait for the old TTL to expire, then make the change.
HTTP and HTTPS
HTTP is a request-response protocol. Key concepts:
- Methods: GET (read), POST (create), PUT (replace), PATCH (partial update), DELETE (remove). Use them correctly -- GET must be safe and idempotent.
- Status codes: 2xx success, 3xx redirection, 4xx client error, 5xx server error. Use specific codes: 201 for created, 204 for no content, 409 for conflict, 429 for rate limited.
- Headers: Content-Type, Authorization, Cache-Control, Accept are the most important. Understand how content negotiation works.
HTTPS adds TLS encryption. All production traffic must use HTTPS. HTTP should redirect to HTTPS (301 redirect). HSTS headers tell browsers to always use HTTPS.
TCP and UDP
- TCP: Reliable, ordered delivery with connection handshake. Used for HTTP, databases, SSH. Connection establishment adds latency (three-way handshake plus TLS handshake for HTTPS).
- UDP: Unreliable, unordered, no connection setup. Used for DNS queries, video streaming, gaming. Lower latency but application must handle packet loss.
Port numbers: 80 (HTTP), 443 (HTTPS), 22 (SSH), 5432 (PostgreSQL), 3306 (MySQL), 6379 (Redis), 27017 (MongoDB). Ports below 1024 require root/admin privileges to bind.
CORS (Cross-Origin Resource Sharing)
CORS governs whether a browser allows a web page to make requests to a different origin (protocol + domain + port). The server must explicitly allow cross-origin requests via response headers:
Access-Control-Allow-Origin: Which origins are allowed. Use specific origins, not*, when credentials are involved.Access-Control-Allow-Methods: Which HTTP methods are permitted.Access-Control-Allow-Headers: Which custom headers the client can send.Access-Control-Allow-Credentials: Whether cookies/auth headers are sent.
Preflight requests (OPTIONS) occur for non-simple requests. Cache preflight responses with Access-Control-Max-Age to reduce overhead.
CORS errors happen in the browser, not the server. If curl works but the browser does not, it is a CORS issue.
SSL/TLS Certificates
Certificates prove server identity and enable encryption:
- Let's Encrypt: Free, automated certificates. Use certbot or ACME clients for auto-renewal. Certificates expire every 90 days.
- Certificate chain: Server cert, intermediate cert(s), root cert. Misconfigured chains cause "untrusted certificate" errors on some clients.
- Self-signed certs: Acceptable for local development only. Use mkcert to create locally-trusted certificates for development.
Load Balancing
Distributes traffic across multiple server instances:
- Layer 4 (TCP): Routes based on IP and port. Fast, protocol-agnostic. Use for non-HTTP traffic.
- Layer 7 (HTTP): Routes based on URL path, headers, cookies. Enables sticky sessions, path-based routing, header-based routing.
- Algorithms: Round-robin (default), least connections (best for varying request durations), IP hash (session affinity without cookies).
- Health checks: Load balancers remove unhealthy backends automatically. Configure appropriate health check endpoints and intervals.
CDN (Content Delivery Network)
CDNs cache content at edge locations worldwide, reducing latency for static assets. Configure cache headers correctly: Cache-Control: public, max-age=31536000, immutable for versioned assets. Use cache busting (content hashing in filenames) rather than short TTLs.
Reverse Proxy (Nginx / Caddy)
A reverse proxy sits in front of application servers:
- Nginx: High-performance, widely used. Configure
proxy_passfor upstream servers. Setproxy_set_header X-Real-IPandX-Forwarded-Forto preserve client IP. Useupstreamblocks for load balancing. - Caddy: Automatic HTTPS with Let's Encrypt. Simpler configuration. Good for smaller deployments and development environments.
Common reverse proxy responsibilities: SSL termination, static file serving, gzip compression, rate limiting, request buffering.
Network Debugging
Systematic debugging tools:
- curl: Test HTTP requests. Use
-vfor verbose output including headers. Use-kto skip certificate verification (debugging only). Use--resolveto test against specific IPs. - dig / nslookup: Query DNS records.
dig example.com A +shortreturns just the IP.dig @8.8.8.8 example.comqueries a specific resolver. - traceroute / tracert: Shows the network path to a destination. Identifies where packets are being dropped or delayed.
- netstat / ss: Shows active connections and listening ports.
ss -tlnpshows TCP listeners with process names. - openssl s_client: Debug TLS connections.
openssl s_client -connect example.com:443shows certificate chain and negotiated protocol.
VPN and Tunnel Considerations
Development often involves accessing resources behind firewalls:
- SSH tunnels:
ssh -L local_port:remote_host:remote_portforwards a local port to a remote service. Use for accessing databases behind firewalls. - ngrok / Cloudflare Tunnels: Expose local servers to the internet for webhook testing and demos. Never leave tunnels running to production services.
- VPN: Connects your machine to a private network. Split tunneling routes only private network traffic through VPN, keeping internet traffic direct.
Best Practices
- Always use HTTPS in production. Set DNS TTLs appropriately: low during migrations, higher for stable records.
- Configure CORS on the server, not by disabling browser security.
- Diagnose connectivity layer by layer: DNS, then TCP, then TLS, then application.
- Keep reverse proxy configurations in version control. Test with curl before blaming application code.
Anti-Patterns
- Disabling SSL verification in production: Using
verify=FalseorrejectUnauthorized: falsebypasses security entirely. Fix the certificate chain instead. - Using
*for CORS in production: Overly permissive CORS exposes APIs to any origin. Whitelist specific origins. - Hardcoding IP addresses: IPs change. Use DNS names and let resolution handle the mapping.
- Ignoring DNS TTL during migrations: Changing DNS records without first lowering TTL means clients cache the old address for hours.
- Not setting timeouts: Every network call needs a timeout. Without one, a hung connection blocks resources indefinitely.
- Debugging network issues from application logs alone: Network problems require network tools. Use curl, dig, and traceroute before reading application code.
Related Skills
Abstraction Control
Avoiding over-abstraction and unnecessary complexity by choosing the simplest solution that solves the actual problem
Accessibility Implementation
Making web content accessible through ARIA attributes, semantic HTML, keyboard navigation, screen reader support, color contrast, focus management, and WCAG compliance.
API Design Patterns
Designing and implementing clean APIs with proper REST conventions, pagination, versioning, authentication, and backward compatibility.
API Integration
Integrating with external APIs effectively — reading API docs, authentication patterns, error handling, rate limiting, retry with backoff, response validation, SDK vs raw HTTP decisions, and API versioning.
Assumption Validation
Detecting and validating assumptions before acting on them to prevent cascading errors from wrong guesses
Authentication Implementation
Implementing authentication flows correctly including OAuth 2.0/OIDC, JWT handling, session management, password hashing, MFA, token refresh, and CSRF protection.