/etc/hosts file on system A to map the IP address to the name “db”:
Keep in mind that system A relies entirely on the
/etc/hosts entry for name resolution. It does not verify whether system B’s actual hostname (as reported by the hostname command) matches “db”./etc/hosts file as follows:
/etc/hosts file:
/etc/hosts files works well, maintaining consistency becomes difficult as the number of hosts increases.
If a server’s IP address changes, updating the
/etc/hosts file on every host can be a major headache. A centralized DNS server eliminates this problem.Centralizing DNS with a DNS Server
To simplify name resolution in larger networks, you store these mappings on a single DNS server. For example, consider these entries on your centralized DNS server:/etc/resolv.conf file. For example, if your DNS server’s IP address is 192.168.1.100, add:

/etc/hosts, the system queries the DNS server. Updating the DNS server’s mappings automatically refreshes host resolution across the network.
Local /etc/hosts entries remain useful for specific purposes. For instance, if you provision a test server that only you need to access, add an entry like this:
/etc/nsswitch.conf. By default, it is set to:
/etc/hosts file first (“files”) and then query the DNS server (“dns”).
If a hostname isn’t found in either the local file or on the DNS server (for example, www.facebook.com when your DNS does not forward unresolved queries), the ping will fail. To resolve external domains, you can add a public DNS server (such as Google’s 8.8.8.8) to /etc/resolv.conf or set your internal DNS server to forward queries.
Consider this scenario: Initially, pinging www.facebook.com fails.
/etc/resolv.conf:
DNS Hierarchy and Search Domains
Consider the hierarchical structure of Google’s domain. The primary domain is “google.com”, while “www” is one of its subdomains. Other subdomains like maps.google.com, drive.google.com, apps.google.com, and mail.google.com represent different Google services. When queried, your DNS server may need to forward the request up the hierarchy—which involves root DNS servers, TLD servers, and authoritative DNS servers—to resolve the domain to the correct IP address.
/etc/resolv.conf. This allows you to use short names instead of fully qualified domain names. For example:
Common DNS Record Types
DNS servers store mappings between hostnames and IP addresses, and these mappings are defined by various record types. Below is a table summarizing common DNS record types:
An A record maps a hostname to an IPv4 address, while an AAAA record maps a hostname to an IPv6 address. A CNAME (canonical name) record creates an alias for another domain name—useful for routing multiple names to the same application.

DNS Diagnostic Tools
While ping is a standard tool for checking DNS resolution, utilities like NSLookup and DIG provide more detailed insights. For example, NSLookup directly queries a DNS server, bypassing local/etc/hosts entries: