When you run the ping command in Linux, the system resolves the target hostname to an IP address. The resolution process follows the order defined in the Name Service Switch (NSS) configuration file (/etc/nsswitch.conf), which specifies whether the system should check /etc/hosts or DNS (via /etc/resolv.conf) first.
Typically, the configuration in nsswitch.conf looks like this for hostname resolution:
hosts: files dns
filesmeans/etc/hostsis checked first.- If no match is found, it proceeds to DNS as specified in
/etc/resolv.conf.
