{"id":1209,"date":"2026-09-23T23:06:27","date_gmt":"2026-09-23T23:06:27","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1209"},"modified":"2026-09-23T23:06:27","modified_gmt":"2026-09-23T23:06:27","slug":"diagnosing-dns-resolver-latency-vps-dig-tcpdump","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/","title":{"rendered":"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">DNS resolution latency is invisible until it is not. A resolver that answers in 5 ms and one that answers in 2 seconds produce identical application code and wildly different page load times. Because the delay appears in name lookups rather than in your database or PHP, it hides from application profiling. This guide shows how to measure resolver latency directly, find the slow path, and tune the settings that cause it.<\/p>\n\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Measure resolver latency directly<\/h2>\n<!-- \/wp:post-content -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\"><code>dig<\/code> reports query time in its footer. Run several lookups against your configured resolver and against a public one to isolate local configuration from upstream latency.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code>dig +stats example.com @127.0.0.53 | grep -i \"Query time\"\ndig +stats example.com @1.1.1.1 | grep -i \"Query time\"<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">A large gap means the problem is local \u2014 the stub resolver, the resolving library, or <code>ndots<\/code> behaviour. A uniformly slow result on both means upstream latency.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Understand the ndots search-path trap<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">The default <code>ndots:1<\/code> means any name with fewer than one dot in it is tried against every search domain before being tried as absolute. With two search domains, <code>api<\/code> becomes two failed lookups followed by the real one \u2014 up to three round trips where one should do. For applications resolving many short internal names, this multiplies latency.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code># \/etc\/resolv.conf\noptions ndots:2 timeout:1 attempts:2 rotate\nnameserver 127.0.0.53<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Raising <code>ndots<\/code> to 2 means names with fewer than two dots skip the search list. Use a fully-qualified name with a trailing dot (<code>api.internal.example.com<\/code>) when you want no search expansion at all.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Trace where the time actually goes<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">When <code>dig<\/code> is fast but the app is slow, capture the resolver traffic and read the timings. <code>tcpdump<\/code> on port 53 shows whether a query is retried, duplicated, or sent to a second nameserver after a timeout.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code>tcpdump -ni any -ttt port 53 -c 20<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">The <code>-ttt<\/code> flag prints the delta between packets. A repeated query to a second nameserver followed by a long gap is the classic signature of the primary resolver timing out and the client failing over. Reducing <code>timeout<\/code> and <code>attempts<\/code> in resolv.conf shortens that worst case.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Run a local caching resolver<\/h2>\n<!-- wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">A local resolver caches answers in memory and answers repeat lookups without network round trips. On a VPS, a small caching resolver bound to the loopback interface turns a 30 ms upstream lookup into sub-millisecond cache hits. Point <code>\/etc\/resolv.conf<\/code> at it and let it forward.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code># after installing a local resolver\n# \/etc\/resolv.conf\nnameserver 127.0.0.1\noptions ndots:2 timeout:1 attempts:2<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:table -->\n<figure class=\"wp-block-table\"><table><thead><tr><th>Signal<\/th><th>Meaning<\/th><th>Action<\/th><\/tr><\/thead><tbody><tr><td>dig slow, public DNS fast<\/td><td>Local stub\/library issue<\/td><td>Check ndots and stub config<\/td><\/tr><tr><td>Both slow<\/td><td>Upstream latency<\/td><td>Use a closer\/caching resolver<\/td><\/tr><tr><td>tcpdump shows retries<\/td><td>Timeouts and failover<\/td><td>Lower timeout\/attempts<\/td><\/tr><tr><td>First query slow, rest fast<\/td><td>Cold cache<\/td><td>Expected; keep resolver warm<\/td><\/tr><\/tbody><\/table><\/figure>\n<!-- \/wp:table -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Test the resolver the way the application does<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\"><code>dig<\/code> is a clean-room test; your application uses the system resolver through <code>getaddrinfo<\/code>, which obeys <code>\/etc\/nsswitch.conf<\/code> and the search list. Reproduce the application&#8217;s path so you measure what it actually experiences, including any hosts-file lookup and any search-domain expansion.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code>getent ahosts example.com\ngetent ahosts api\nstrace -f -e trace=sendto,recvfrom -T getent ahosts api 2&gt;&amp;1 | head -30<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">The <code>-T<\/code> flag prints the time spent in each syscall. If the same name produces several <code>sendto<\/code> calls with multi-second gaps between them, you have found the retry-and-failover path that application-level profiling never shows.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Pick the right resolver for the workload<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:table -->\n<figure class=\"wp-block-table\"><table><thead><tr><th>Workload<\/th><th>Resolver choice<\/th><th>Reason<\/th><\/tr><\/thead><tbody><tr><td>Single web server<\/td><td>Local caching resolver on 127.0.0.1<\/td><td>Sub-ms cache hits, no extra hosts<\/td><\/tr><tr><td>Many containers<\/td><td>Host resolver + container DNS forwarding<\/td><td>One cache shared across namespaces<\/td><\/tr><tr><td>Inside a private network<\/td><td>Local resolver forwarding to internal DNS<\/td><td>Split-horizon names resolve correctly<\/td><\/tr><\/tbody><\/table><\/figure>\n<!-- \/wp:table -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Avoid pointing every host at the same public resolver with no cache: upstream rate limits and added latency both bite under sustained load. A local cache absorbs the repeat lookups that dominate real traffic.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Does anything else depend on the resolver?<\/h2>\n<!-- wp:heading -->\n\n<!-- wp:list -->\n<ul class=\"wp-block-list\"><li>Cron jobs and backup scripts that resolve S3 or database hostnames fail silently when resolution is slow but not broken.<\/li><li>Health checks that use hostnames inherit the same latency; prefer IPs or keep the cache warm.<\/li><li>Container stacks run their own stub resolver \u2014 check the container&#8217;s resolv.conf separately, not just the host&#8217;s.<\/li><\/ul>\n<!-- \/wp:list -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">A quick before-and-after check<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Record a baseline before you touch anything, then compare. Ten lookups to the same name reveal both cold and warm latency.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code>for i in $(seq 1 10); do\n  dig +short +stats example.com | tail -1\ndone | grep -i \"Query time\"<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">After adding a local cache, the first query stays slow and the next nine should drop to under a millisecond. That pattern is the confirmation that the resolver \u2014 not the application \u2014 was the source of the delay.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Measure first with <code>dig<\/code>, then trace with <code>tcpdump<\/code>, then cache locally. Most &#8220;random slowness&#8221; incidents that resist application profiling are a resolver issue sitting one layer underneath. Pair this with the environment review on the <a href=\"https:\/\/virtualserversvps.com\/cloud-vps-benefits\/\">cloud VPS benefits<\/a> page, and see <a href=\"https:\/\/virtualserversvps.com\/\">VPS tutorials<\/a> for other diagnostic walkthroughs.<\/p>\n<!-- \/wp:paragraph -->","protected":false},"excerpt":{"rendered":"<p>DNS resolution latency is invisible until it is not. A resolver that answers in 5 ms and one that answers in 2 seconds produce identical application code and wildly different&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1209","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump\" \/>\n<meta property=\"og:description\" content=\"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-23T23:06:27+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/\",\"name\":\"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-09-23T23:06:27+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/","og_locale":"en_US","og_type":"article","og_title":"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump","og_description":"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump","og_url":"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-09-23T23:06:27+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/","url":"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/","name":"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-09-23T23:06:27+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/diagnosing-dns-resolver-latency-vps-dig-tcpdump\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Diagnosing DNS Resolver Latency on a VPS with dig and tcpdump"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1209"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1209\/revisions"}],"predecessor-version":[{"id":1212,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1209\/revisions\/1212"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}