Network Integration  «Prev  Next»
Lesson 6Using DNS to resolve hostnames into IP addresses
ObjectiveConfigure your network interface to use DNS.

DNS hostname resolution in Red Hat Linux:

Here's how
  1. Client-side Resolution: When you try to access a website by its hostname (e.g., "[https://www.google.com.mx/](https://www.google.com.mx/)"), your system doesn't directly contact the website. It first attempts to resolve the hostname into an IP address using the following steps:
    • /etc/hosts file: This local file located at `/etc/hosts` takes precedence. It can contain mappings of hostnames to IP addresses. Your system checks if the hostname exists in this file. If a match is found, the corresponding IP address is used.
    • Name Servers: If the hostname is not found in `/etc/hosts`, your system queries the configured name servers for the IP address. The name servers are typically set in the `/etc/resolv.conf` file. This file specifies:
      • nameserver lines: Each line defines an IP address of a name server your system should contact to resolve hostnames. Typically, these are provided by your internet service provider (ISP).
      • Search domain: Optionally, a search domain can be specified. If the hostname you entered doesn't include a domain extension (like ".com" or ".org"), the system will append the search domain and try resolving it.

    Recursive vs. Iterative Resolution:
    • The name server contacted might not have the answer for the specific hostname. In this case:

      • Recursive resolution: (Default behavior on most systems) The contacted name server will act on your behalf and query other name servers until it finds the answer (IP address) and returns it to your system.
      • Iterative resolution: (Less common) The contacted name server provides your system with the address of another name server that might have the answer. Your system then contacts the new server and repeats the process until the IP address is found.
  2. Server-side Resolution:
    • Once your system obtains the IP address, it can connect to the web server using the IP address and establish communication.
  3. Caching:
    • To improve efficiency, your system caches recently resolved hostnames and their corresponding IP addresses for a certain period. This way, subsequent requests for the same hostname can be fulfilled quickly without querying the name servers again.
Managing DNS Resolution in Red Hat Linux:
  • Viewing name server configuration:
    • Use the `cat /etc/resolv.conf` command to see the configured nameservers.
  • Modifying name servers:
    • Editing `/etc/resolv.conf` requires root privileges. You can use a text editor like `nano` to edit the file, but be cautious as incorrect configurations can disrupt internet access.
  • Adding entries to /etc/hosts:
    • Editing `/etc/hosts` with a text editor (as root) allows you to define custom hostname-to-IP mappings for specific hosts. This can be useful for internal network resources or testing purposes.

Additional Tools:
  • `dig`: This command-line tool allows querying name servers manually and viewing detailed DNS information.
  • `host`: Another command-line tool for basic hostname resolution checks.

By understanding these steps and tools, you can effectively manage hostname resolution on your Red Hat Linux system. Remember, modifying system configuration files like `/etc/resolv.conf` should be done with caution to avoid unintended consequences.
In large networks, the disadvantages of Host Tables become apparent: there are simply too many hosts constantly connecting and disconnecting from the network. You would have to edit the Host Table constantly, leaving no time for useful computing.

High level Overview of DNS

DNS (Domain Name System) is a hierarchical system used to translate domain names into IP addresses. Domain names, such as www.example.com, are easy for humans to remember and use, but computers communicate with each other using IP addresses, such as 192.168.0.1. The DNS system consists of a global network of DNS servers that work together to provide the translation between domain names and IP addresses. When a user enters a domain name into their web browser, the browser sends a request to a local DNS resolver, which then queries the DNS system to find the corresponding IP address. The DNS system uses a hierarchical structure, with top-level domains (TLDs) at the highest level, followed by second-level domains (SLDs), and then subdomains. Each domain is managed by a DNS server, which is responsible for storing information about the domain and its corresponding IP address.
DNS servers use a caching system to improve performance and reduce the load on the network. When a DNS server receives a request for a domain name, it first checks its cache to see if it has a record of the domain and its corresponding IP address. If it does, it can immediately provide the answer without having to query other DNS servers. Overall, DNS plays a critical role in enabling users to access websites and other online resources using easy-to-remember domain names, while allowing computers to communicate with each other using IP addresses. The hierarchical structure of the DNS system and the use of caching help to ensure efficient and reliable performance for users around the world.
The solution is a large database that is spread among many computers. The most common system is the Domain Name System (DNS). Each DNS machine keeps a database of names and addresses. The database is updated constantly to reflect the current state of the network. When requests are made, the server searches for the hostname and, if found, returns the IP address. If the server does not find the IP address, it asks other DNS servers to try and find the hostname. Likewise, if the DNS server receives an IP address, it will return the hostname, if found, or ask other servers to look up the IP address.

Configuring client-side DNS
In order to use DNS, you must specify at least the primary DNS server's IP address. If the primary DNS fails to resolve the hostname, Linux consults any backup DNS servers you specified. The DNS configuration information is stored in two files, /etc/host.conf and /etc/resolv.conf. The /etc/host.conf file describes how your Linux machine connects to DNS. The default configuration is adequate. However, you must manually configure the /etc/resolv.conf file, as described in the following series of images below.


/etc/resolv.conf file
1) A typical /etc/resolv.conf looks like this.
1) A typical /etc/resolv.conf looks like this

2) Three keywords used in the /etc/resolv.conf file: domain, search, and nameserver. Each line begins with a keyword and is followed by that keyword's values, separated by white space.
2) Three keywords used in the /etc/resolv.conf file:
  1. domain,
  2. search, and
  3. nameserver.
Each line begins with a keyword and is followed by that keyword's values, separated by white space.

3) Domain keyword specifies your domain name. In this case, it is 'mydomain
3) Domain keyword specifies your domain name. In this case, it is 'mydomain'

4) The search keyword tells the DNS application what other domains to look for in hosts that do not exist in your domain.
4) The search keyword tells the DNS application what other domains to look for in hosts that do not exist in your domain.

5) Finally, each instance of the nameserver keyword lists the IP address of a DNS server to contact to resolve hostnames to IP addresses.
5) Finally, each instance of the nameserver keyword lists the IP address of a DNS server to contact to resolve hostnames to IP addresses.

Using DNS to resolve hostnames into IP addresses

resolv.conf, a computer file utilized in various operating systems, is responsible for configuring the Domain Name System (DNS) resolver of the system. Typically, this plain-text file is created by the network administrator or applications managing the configuration of the system. One such program that manages the resolv.conf file is the resolvconf program found in FreeBSD or other Unix machines. The primary function of the resolv.conf configuration file is to provide information regarding the operational parameters of the DNS resolver in most Unix-like operating systems and those implementing the BIND DNS resolver library. By translating human-friendly domain names into numeric IP addresses, the DNS resolver enables applications to access resources on the local area network or the Internet. This process of translating domain names to IP addresses is known as resolving.
The resolv.conf file usually contains directives that specify default search domains, which are used to complete a query name to a fully qualified domain name when a domain suffix is not supplied. Additionally, it also contains a list of IP addresses of available nameservers used for resolution. In conclusion, resolv.conf plays a crucial role in configuring the DNS resolver in various operating systems. Its contents are essential in determining the operational parameters of the DNS resolver, making it possible for applications to translate human-friendly domain names into the numeric IP addresses necessary for accessing resources on the local area network or the Internet.
Linux contacts the nameservers in the /etc/resolv.conf file in the order you list them. Put your primary DNS as the first entry, and all backup DNS servers afterward.

SEMrush Software6