DNS Lookup Time: Measure Network Latency with curl

Quick Linux Tip #90:

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. This makes it easier to measure DNS lookup time separately from other connection stages.

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.




LinuxTeck.com
linuxteck:~$ 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

  time_namelookup:  0.001234s
  time_connect:     0.023456s
  time_appconnect:  0.089012s
  time_pretransfer: 0.089234s
  time_starttransfer: 0.145678s
  time_total:       0.234567s
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #89: Kernel Modules: Check RAM Usage with lsmod NEXT ARTICLE Quick Linux Tip #91: Open Ports: Find Which Program Uses Them in Linux
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.