Networking, DNS, ports and TLS
Move from a laptop shell to a safe, observable delivery pipeline: version control, Linux processes and permissions, container images, networking, configuration and secrets, deployment, health checks, observability, rollback, reproducibility and security hardening.
What you will be able to do
#- Trace a request through DNS, TCP and TLS to a service.
- Diagnose connection refused versus timeout versus certificate errors.
- Explain how proxies and load balancers change what the app sees.
Overview
#Most production incidents are networking incidents in disguise. A request flows through name resolution, a TCP connection, a TLS handshake, and finally the application protocol. Knowing where it can fail tells you where to look.
DNS
DNS resolves a name to an address. dig or nslookup shows the answer and its TTL.
dig +short app.example.com
A cached record with a long TTL keeps pointing at an old address after a change, which looks like a routing bug but is a caching effect.
Ports and connections
A connection is identified by source address and port plus destination address and port. connection refused means the host is reachable but nothing is listening on that port. A timeout usually means a firewall dropped the packet or the address is wrong.
curl -v https://app.example.com/health
nc -vz app.example.com 443
TLS
TLS encrypts the connection and proves the server identity with a certificate. A certificate error means the name does not match, the certificate expired, or the client does not trust the issuing authority. TLS terminates either at the load balancer or at the app; know which.
Proxies and load balancers
A reverse proxy forwards requests to backends and often sets headers such as X-Forwarded-For and X-Forwarded-Proto. The app sees the proxy address unless it reads those headers, so logs and rate limits can be wrong if the headers are ignored.
Common pitfalls
- Debugging TLS when the real problem is DNS returning a stale address.
- Trusting
X-Forwarded-Forfrom the public internet, which a client can forge. - Forgetting that a health check from the load balancer uses the same DNS and TLS path as real traffic.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Predict
curl https://app.example.com fails immediately with 'Connection refused', while curl https://api.example.com hangs and times out. What does each tell you?
Read the code, then choose the best answer. The reference explanation stays hidden until you respond. stimulus.bashcurl -v https://app.example.com # refused curl -v https://api.example.com # timeoutExercise 2Implement
Write a command that shows the HTTP status code and the TLS certificate details for https://app.example.com/health without downloading the body.
starter.bash# curl with verbose TLS and status onlyReveal the reference answer
reference.bashcurl -sS -o /dev/null -w '%{http_code}\n' https://app.example.com/health # and for certificate details: openssl s_client -connect app.example.com:443 -servername app.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -datesAuthored expected output: A status code such as 200, followed by the certificate subject and validity dates.
curl -w prints the status without the body. openssl s_client retrieves the presented certificate, and openssl x509 formats the subject and dates for inspection.
Exercise 3Debug
After moving a service behind a load balancer, rate limiting blocks every user at once and logs show only the load balancer address. What is wrong?
starter.text# logs show client_ip = 10.0.0.5 for all requestsReveal the reference answer
reference.textThe app is using the direct socket address, which is now the load balancer. Configure it to trust the load balancer and read X-Forwarded-For (or the proxy protocol) to recover the real client IP, and only trust that header from the known proxy address.Authored expected output: Per-client rate limiting and accurate client IPs in logs.
Behind a proxy the socket peer is the proxy. The real client is carried in a forwarded header that must be read only when the immediate peer is a trusted proxy, otherwise clients can spoof it.
Common misconceptions
#- A timeout and a connection refused are the same: refused means nothing is listening, timeout means packets are dropped or the host is unreachable.
- X-Forwarded-For is trustworthy: it can be set by any client unless a trusted proxy overwrites it.
Follow-up practice
#- devops-configuration
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.