{"id":9760,"date":"2026-02-13T18:24:03","date_gmt":"2026-02-13T12:54:03","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=9760"},"modified":"2026-08-25T15:06:11","modified_gmt":"2026-08-25T09:36:11","slug":"name-resolution-flow-in-linux","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/name-resolution-flow-in-linux\/","title":{"rendered":"Name Resolution Flow in Linux"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Hostname resolution in Linux is the process of translating a domain name (e.g., <code>example.com<\/code>) into its corresponding IP address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This process is controlled by:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/etc\/nsswitch.conf<\/code> \u2192 Defines lookup order<\/li>\n\n\n\n<li><code>\/etc\/hosts<\/code> \u2192 Local static hostname mappings<\/li>\n\n\n\n<li><code>\/etc\/resolv.conf<\/code> \u2192 DNS resolver configuration<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This document explains how hostname resolution works on the current server configuration.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">2. Current Configuration<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 <code>\/etc\/nsswitch.conf<\/code><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">hosts: files dns\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This line defines the order in which hostname resolution occurs.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>files<\/code> \u2192 Check <code>\/etc\/hosts<\/code><\/li>\n\n\n\n<li><code>dns<\/code> \u2192 Query DNS server<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 <code>\/etc\/hosts<\/code><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">127.0.0.1       localhost\n::1             localhost ip6-localhost ip6-loopback\n12.34.56.78     example.com \n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This file contains static hostname-to-IP mappings.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 <code>\/etc\/resolv.conf<\/code><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nameserver 127.0.0.53\noptions edns0 trust-ad\nsearch .\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Key points:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>127.0.0.53<\/code> \u2192 systemd-resolved stub resolver<\/li>\n\n\n\n<li>DNS queries are handled by systemd-resolved<\/li>\n\n\n\n<li>Upstream DNS servers can be checked using:<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">resolvectl status\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">3. Hostname Resolution Flow<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When an application tries to resolve:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">example.com\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The system follows the order defined in:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">hosts: files dns\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Check <code>\/etc\/hosts<\/code><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>System checks local file first.<\/li>\n\n\n\n<li>If hostname is found \u2192 return IP immediately.<\/li>\n\n\n\n<li>No DNS query is performed.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In this case:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">12.34.56.78 example.com\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So resolution stops here.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Query DNS (If Not Found in Hosts)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the hostname does not exist in <code>\/etc\/hosts<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Query is sent to <code>127.0.0.53<\/code><\/li>\n\n\n\n<li>systemd-resolved forwards request to configured upstream DNS servers<\/li>\n\n\n\n<li>DNS server responds with IP<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. Priority Order<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Order<\/th><th>Source<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td><code>\/etc\/hosts<\/code><\/td><td>Local static mapping<\/td><\/tr><tr><td>2<\/td><td>DNS<\/td><td>Remote DNS server<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Important:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/etc\/hosts<\/code> always overrides DNS.<\/li>\n\n\n\n<li>If an entry exists locally, DNS will not be queried.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">5. Practical Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Running:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ping example.com\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Resolution process:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Check <code>\/etc\/hosts<\/code><\/li>\n\n\n\n<li>Entry found<\/li>\n\n\n\n<li>IP <code>12.34.56.78<\/code> returned<\/li>\n\n\n\n<li>DNS is NOT used<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">6. Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Based on the current configuration:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hostname resolution follows:<br><strong>\/etc\/hosts \u2192 DNS<\/strong><\/li>\n\n\n\n<li>Local entries have higher priority than DNS.<\/li>\n\n\n\n<li>systemd-resolved handles DNS forwarding.<\/li>\n\n\n\n<li>This setup ensures predictable and controlled hostname resolution.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This configuration is standard and recommended for environments requiring local overrides and centralized DNS management.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Hostname resolution in Linux is the process of translating a domain name (e.g., example.com) into its corresponding IP [&hellip;]<\/p>\n","protected":false},"author":508,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019,1039,1040],"tags":[],"class_list":["post-9760","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","category-dns","category-linux","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2xq","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/508"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=9760"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9760\/revisions"}],"predecessor-version":[{"id":9763,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9760\/revisions\/9763"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=9760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=9760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=9760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}