Skip to content
Network debugging for platform engineers · Chapter 9 of 21 Day 7: HTTP with curl

Day 7: HTTP with curl

Goal: You read curl -v line by line, break a slow request down with -w into DNS, connection, TLS and server response, test a virtual host with -H Host and --resolve before DNS has been switched, follow redirects with care and find a proxy nobody knew about · Duration: approx. 90 min · Prerequisite: Day 6 including checkpoint (DNS server dns-router is running)

Briefing

  • Until yesterday you asked: Does a packet arrive, is someone listening, is the name right? Today you move one layer up, to HTTP – the protocol of almost every service platform engineers deal with: APIs, health checks, webhooks, registries, Kubernetes itself.
  • curl is the measuring instrument for this. It shows the request it sends, the response that comes back, and with -w the time of each phase. “The page is slow” turns into “the connection takes 100 ms, the server 2 seconds”.
  • For the exercises, web gets a second web server: nginx with two virtual hosts, like an ingress controller in miniature. On Day 8 it gets TLS.

Drill 1: Reading curl -v

# on netz
# Fetch with all details
#   -s   silent: no progress meter (it would otherwise mix with -v)
#   -v   verbose: connection, request and response header on stderr
sudo ip netns exec client curl -sv http://web.firma.lab/

Expected (date and times differ):

* Host web.firma.lab:80 was resolved.
* IPv6: (none)
* IPv4: 10.2.0.10
*   Trying 10.2.0.10:80...
* Connected to web.firma.lab (10.2.0.10) port 80
> GET / HTTP/1.1
> Host: web.firma.lab
> User-Agent: curl/8.5.0
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: SimpleHTTP/0.6 Python/3.12.3
< Date: Thu, 26 Nov 2026 14:08:38 GMT
< Content-type: text/html
< Content-Length: 14
< Last-Modified: Thu, 26 Nov 2026 07:43:16 GMT
< 
* Closing connection
hallo von web

The first character of each line tells you where it comes from:

Character Meaning What you check here
* curl reports what it is doing Name resolved? Which address? Connection established?
> request curl sends method, path, Host header, custom headers
< response header from the server status code, server, length, redirect (Location)
no character response body what the application returns

The * lines are Days 2 to 6 in miniature: DNS (was resolved), route and neighbor (Trying), port (Connected). If curl -v stops before Connected, the problem lies below HTTP – then the table from Day 4 helps you.

For scripts and health checks you often need only two things: the header or the status code.

# on netz
# Only the response header
#   -I   HEAD request: server sends only the header, no body
sudo ip netns exec client curl -sI http://web.firma.lab/
# Only the status code
#   -o /dev/null        discard the body
#   -w '%{http_code}\n'  after the fetch, print only the status code
sudo ip netns exec client curl -s -o /dev/null -w '%{http_code}\n' http://web.firma.lab/

Expected:

HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.12.3
Date: Thu, 26 Nov 2026 14:12:02 GMT
Content-type: text/html
Content-Length: 14
Last-Modified: Thu, 26 Nov 2026 07:43:16 GMT

200

An important difference for scripts: curl exits with exit code 0 even if the server answers 404 or 500 – for curl, the transfer succeeded. If a script should fail on HTTP errors, add -f (--fail); then curl exits with exit code 22 on status 400 and above.

Save your progress? Sign up for free

Drill 2: Where does the time go?

-w has variables for every phase. All of them count in seconds from the start, not as the duration of the phase:

# on netz
# Measurement format in a variable to keep the commands short
#   time_namelookup     name resolved
#   time_connect        TCP connection established
#   time_appconnect     TLS handshake done (0 for http)
#   time_starttransfer  first byte of the response arrived (TTFB)
#   time_total          everything transferred
W='dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total}\n'
# in your own network
sudo ip netns exec client curl -s -o /dev/null -w "$W" http://web.firma.lab/
# on the internet, with TLS
sudo ip netns exec client curl -s -o /dev/null -w "$W" https://example.com/

Expected (the internet times vary a lot):

dns=0.001976 connect=0.002477 tls=0.000000 ttfb=0.004827 total=0.005011
dns=0.009044 connect=0.014202 tls=0.149457 ttfb=0.160439 total=0.160580

For example.com the TLS handshake takes 135 ms (0.149 − 0.014), everything else together 25 ms. Now you add two faults one after the other and see where the numbers jump. First a slow link to site B, as on Day 4:

# on netz
# 100 ms delay for every packet the router sends to site B
#   netem delay 100ms   network emulator: hold every packet for 100 ms
sudo ip netns exec router tc qdisc add dev eth-b root netem delay 100ms
sudo ip netns exec client curl -s -o /dev/null -w "$W" http://web.firma.lab/
sudo ip netns exec router tc qdisc del dev eth-b root

Expected:

dns=0.002999 connect=0.103809 tls=0.000000 ttfb=0.207054 total=0.207194

connect jumps by 100 ms: establishing the connection takes one round trip, and the outbound path is delayed. ttfb grows by another 100 ms, because the request also has to cross the link. The pattern “connect high” always means: network or path.

Then a server that accepts the connection immediately but computes for two seconds before it answers:

# on netz
# Slow service on port 8081: waits 2 s, then a minimal HTTP response
#   socat TCP-LISTEN:8081,bind=10.2.0.10,reuseaddr,fork   listen; a new process for each connection
#   SYSTEM:'…'                                             command whose output is the response
sudo systemd-run --unit=web-langsam ip netns exec web socat TCP-LISTEN:8081,bind=10.2.0.10,reuseaddr,fork SYSTEM:'sleep 2; echo HTTP/1.0 200 OK; echo; echo langsam'
sudo ip netns exec client curl -s -o /dev/null -w "$W" http://web.firma.lab:8081/

Expected:

Running as unit: web-langsam.service; invocation ID: 48ba75a1effd4ec794b80eeab62bfa70
dns=0.003150 connect=0.003699 tls=0.000000 ttfb=2.010949 total=2.012529
jumps cause lies in continue with
dns name resolution Day 6 (resolv.conf, dead name server)
connect − dns network, path, full accept queue mtr, ss -ltn (Days 4, 5)
tls − connect TLS handshake, certificate validation (OCSP, long chain) Day 8
ttfb − tls or connect application computes, waits for database or backend logs and metrics of the app
total − ttfb large response or thin link size (%{size_download}), bandwidth

This table is the answer to the most common question on call: “Is it the network or the app?” Here the answer is clear: the app takes two seconds, the network three milliseconds.

Save your progress? Sign up for free

Drill 3: One server, many names

A web server, ingress controller or load balancer usually serves many names under one address. It decides by the Host header of the request which site it delivers. For this, web now gets nginx with two virtual hosts:

# on netz
# install nginx, but don't use the system service (it would listen on the VM itself)
sudo apt-get install -y nginx
#   disable --now   stop the service and no longer start it at boot
sudo systemctl disable --now nginx
mkdir -p ~/ndbg

The configuration: a default server for unknown names and one server each for shop.firma.lab and api.firma.lab, all on 10.2.0.10:8080. Create the file ~/ndbg/nginx.conf with an editor:

worker_processes 1;
pid /run/nginx-web.pid;
error_log /var/log/nginx/web-error.log;
events {}
http {
    default_type text/plain;
    access_log /var/log/nginx/web-access.log;
    server {
        listen 10.2.0.10:8080 default_server;
        return 404 "unbekannter Host\n";
    }
    server {
        listen 10.2.0.10:8080;
        server_name shop.firma.lab;
        location = /alt   { return 301 /neu; }
        location = /neu   { return 200 "neue Seite\n"; }
        location = /kreis { return 302 /kreis; }
        location / { return 200 "shop\n"; }
    }
    server {
        listen 10.2.0.10:8080;
        server_name api.firma.lab;
        location / { return 200 "api\n"; }
    }
}
Line Meaning
pid, error_log, access_log separate files, so this nginx doesn’t get in the way of the system service
listen 10.2.0.10:8080 default_server this server answers when no server_name matches
server_name shop.firma.lab responsible when the Host header is shop.firma.lab
return 301 /neu permanent redirect (Drill 4); 302 is a temporary one
# on netz
# start nginx in the web namespace
#   -c <datei>             this configuration instead of /etc/nginx/nginx.conf
#   -g 'daemon off;'       stay in the foreground (systemd supervises the process)
sudo systemd-run --unit=web-nginx ip netns exec web nginx -c /home/ubuntu/ndbg/nginx.conf -g 'daemon off;'
# Fetch via the address: Host header is 10.2.0.10:8080, no server_name matches
sudo ip netns exec client curl -s http://10.2.0.10:8080/
# Set the Host header yourself
#   -H 'Host: shop.firma.lab'   send your own header, replaces the automatic one
sudo ip netns exec client curl -s -H 'Host: shop.firma.lab' http://10.2.0.10:8080/
sudo ip netns exec client curl -s -H 'Host: api.firma.lab' http://10.2.0.10:8080/

Expected:

Running as unit: web-nginx.service; invocation ID: 9161ef3e42bf478c9cc32e898bdda64e
unbekannter Host
shop
api

Same address, same port, three responses – only the Host header tells them apart. That is why a test with the IP address instead of the name is often misleading: you end up at the default server and see 404, even though the site is fine.

shop.firma.lab does not exist in DNS yet. This is exactly the situation you have before every migration: the new server is running, DNS still points to the old one. With --resolve you can still test with the right name:

# on netz
# Without a DNS entry
sudo ip netns exec client curl -sS http://shop.firma.lab:8080/
# With a fixed mapping name → address for this call only
#   --resolve shop.firma.lab:8080:10.2.0.10   NAME:PORT:ADDRESS, applies only to curl, only to this call
sudo ip netns exec client curl -s --resolve shop.firma.lab:8080:10.2.0.10 http://shop.firma.lab:8080/

Expected:

curl: (6) Could not resolve host: shop.firma.lab
shop

-H Host and --resolve look the same, but they are not. -H only changes the header; curl connects to the address from the URL. --resolve changes the name resolution; URL, Host header and – with HTTPS – the name in the TLS handshake (SNI) stay correct. For HTTPS, --resolve is therefore almost always the right choice (Day 8). Unlike an entry in /etc/hosts (Day 6), it affects only this one call and cannot be forgotten.

Save your progress? Sign up for free

Drill 4: Redirects

# on netz
# What does the server answer for /alt?
sudo ip netns exec client curl -sI --resolve shop.firma.lab:8080:10.2.0.10 http://shop.firma.lab:8080/alt
# Follow the redirect
#   -L   follow the Location header until a response without a redirect comes
sudo ip netns exec client curl -sL --resolve shop.firma.lab:8080:10.2.0.10 http://shop.firma.lab:8080/alt
# How many redirects, and where did it end?
#   %{num_redirects}   number of redirects followed
#   %{url_effective}   last URL
sudo ip netns exec client curl -sL -o /dev/null -w '%{num_redirects} %{url_effective}\n' --resolve shop.firma.lab:8080:10.2.0.10 http://shop.firma.lab:8080/alt

Expected (date differs):

HTTP/1.1 301 Moved Permanently
Server: nginx/1.24.0 (Ubuntu)
Date: Thu, 26 Nov 2026 14:08:31 GMT
Content-Type: text/html
Content-Length: 178
Location: http://shop.firma.lab:8080/neu
Connection: keep-alive

neue Seite
1 http://shop.firma.lab:8080/neu

Without -L you get to see the redirect itself – often exactly what you want when debugging. Typical failure patterns: an application behind a proxy redirects to http:// instead of https:// because it ignores the X-Forwarded-Proto header, or to its internal name (http://app:8080/…), which nobody outside can resolve. You see both in the Location header before the browser turns them into a puzzling error message.

Save your progress? Sign up for free

Exercise

A colleague reports: “For shop.firma.lab:8080/kreis the browser only says: This page redirects too often.” Prove with curl what the server does, and show that curl notices the error the same way.

Solution

# on netz
# First without -L: Where does the server redirect to?
sudo ip netns exec client curl -sI --resolve shop.firma.lab:8080:10.2.0.10 http://shop.firma.lab:8080/kreis
# With -L, but at most 5 redirects
#   -S                 show error messages despite -s
#   --max-redirs 5     abort after 5 redirects (default: 50)
sudo ip netns exec client curl -sSL --max-redirs 5 --resolve shop.firma.lab:8080:10.2.0.10 http://shop.firma.lab:8080/kreis
echo "exit=$?"

Expected (header shortened):

HTTP/1.1 302 Moved Temporarily
Server: nginx/1.24.0 (Ubuntu)
Location: http://shop.firma.lab:8080/kreis

curl: (47) Maximum (5) redirects followed
exit=47

The page redirects to itself. In practice the loop is usually longer: the app redirects http to https, but the proxy in front talks to the app over http and redirects back. curl -sI on every URL in the loop shows each Location header individually – that is how you find the spot where the loop closes.

Save your progress? Sign up for free

Challenge

Introduce the fault:

# on netz
# a configuration file for curl in root's home directory
echo "proxy = http://10.1.0.1:3128" | sudo tee /root/.curlrc >/dev/null

The monitoring script, which runs as root, has been reporting “Failed to connect” for http://web.firma.lab/ since this morning. A colleague has checked: web is running, port 80 is open, DNS is correct. Find the cause without knowing about the file yet, and prove the fix.

Solution

# on netz
# Symptom
sudo ip netns exec client curl -sS http://web.firma.lab/
# Which address does curl really connect to?
sudo ip netns exec client curl -sv http://web.firma.lab/ 2>&1 | head -3

Expected:

curl: (7) Failed to connect to 10.1.0.1 port 3128 after 0 ms: Couldn't connect to server
*   Trying 10.1.0.1:3128...
* connect to 10.1.0.1 port 3128 from 10.1.0.10 port 41838 failed: Connection refused
* Failed to connect to 10.1.0.1 port 3128 after 0 ms: Couldn't connect to server

The error message does not name web, but 10.1.0.1:3128 – the router, port 3128, the classic port of an HTTP proxy. curl sends everything to a proxy that doesn’t exist. Where does it come from? First the environment variables, then the configuration files:

# on netz
# Proxy variables in the command's environment (ip netns exec inherits those of sudo)
#   env                   print the environment
#   grep -i proxy         case-insensitive: http_proxy, HTTPS_PROXY, no_proxy …
sudo ip netns exec client env | grep -i proxy || echo "keine Proxy-Variablen"
# curl without a configuration file
#   -q   don't read ~/.curlrc (must be the first option)
sudo ip netns exec client curl -q -sS http://web.firma.lab/
# Find the file
sudo cat /root/.curlrc

Expected:

keine Proxy-Variablen
hallo von web
proxy = http://10.1.0.1:3128

No variable, but with -q it works: the proxy is in ~/.curlrc of the user the script runs as – here root. Fix and proof:

# on netz
sudo rm /root/.curlrc
sudo ip netns exec client curl -sS http://web.firma.lab/

Expected:

hallo von web

Proxies get into a curl call in three ways, and curl -v reveals each one: variables (http_proxy, https_proxy, HTTPS_PROXY, no_proxy – then the first line says Uses proxy env variable …), ~/.curlrc (then only the Trying to the proxy address) or the -x option. Countermeasure for a single call: --noproxy '*' (all destinations direct) or --noproxy firma.lab (only internal destinations direct).

Save your progress? Sign up for free

Checkpoint

# on netz
# nginx with virtual hosts is running in web
systemctl is-active web-nginx
sudo ip netns exec client curl -s --resolve api.firma.lab:8080:10.2.0.10 http://api.firma.lab:8080/
# no curl configuration for root, no delay at the router
sudo test -e /root/.curlrc && echo "/root/.curlrc vorhanden" || echo "keine .curlrc"
sudo ip netns exec router tc qdisc show dev eth-b | grep -c netem
# Status code and time of the web server from Day 0
sudo ip netns exec client curl -s -o /dev/null -w '%{http_code} %{time_total}\n' http://web.firma.lab/

Expected (the time differs, it should be below 0.05 s):

active
api
keine .curlrc
0
200 0.004908

Clean up

You no longer need the slow service; nginx (web-nginx) stays for Day 8.

# on netz
sudo systemctl stop web-langsam
# socat exits with an error code when stopped; reset-failed forgets the unit so the name is free
sudo systemctl reset-failed web-langsam
sudo ip netns exec web ss -Hltn 'sport = :8081' | wc -l

Expected:

0

Interview note

“An endpoint is slow. How do you find out whether it’s the network or the application?” curl -w with time_namelookup, time_connect, time_appconnect and time_starttransfer: if connect jumps, it’s the path; if the time between connection and first byte jumps, the application is computing. Bonus points: the values are cumulative from the start, without -f curl exits with exit code 0 even on HTTP 500, and for HTTPS tests before a DNS switch you use --resolve instead of -H Host, because otherwise SNI and certificate don’t match.

Enterprise note

In companies, the proxy is the most common invisible source of errors: in /etc/environment, in a profile script, in ~/.curlrc, in the Docker daemon configuration or inherited in the container image. Then access to the internet works, but internal destinations fail because no_proxy doesn’t contain them – in Kubernetes especially often .svc, .cluster.local and the pod network. With every “Failed to connect”, check which address curl wanted to connect to. If it isn’t the destination, it’s a proxy.

Command Drills

Practise commands from Day 7

3 drills · approx. 7 minutes · in your browser, no VM

Task

Only the response headers

With an account your progress is saved and drills that are due come back in your daily round. Without an account it stays in this browser only. Sign up for free

Contents

More