
Quick Linux Tip #90 - DNS Lookup Time: Measure Network Latency with curl
Question: How do I measure DNS lookup, connect, and download time separately?
Try:
`curl -w '@-' -o /dev/null -s https://google.com <<'EOF'`
` time_namelookup: %{time_namelookup}s`
` time_connect: %{time_connect}s`
` time_appconnect: %{time_appconnect}s`
` time_pretransfer: %{time_pretransfer}s`
` time_starttransfer: %{time_starttransfer}s`
` time_total: %{time_total}s`
`EOF`
Info: `curl -w` customizes output formatting using predefined variables. Breaking down latency identifies bottlenecks across DNS resolution, TCP handshakes, TLS negotiation, and server response times.
Examples:
$ `curl -w 'HTTP: %{http_code}, Time: %{time_total}s\n' -o /dev/null -s https://example.com` # Check status code and total duration
$ `curl -w '%{time_total}\n' -o /dev/null -s -X POST -d 'data' https://api.example.com` # Benchmark API response speed
$ `curl --resolve example.com:443:1.2.3.4 https://example.com` # Test direct IP routing, bypassing DNS
Note: High `appconnect` indicates TLS handshake delays, high `starttransfer` indicates server processing lag (TTFB), and high `connect` signals network routing latency.
Want to master Linux one command at a time?
Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/