Create the /etc/resolv.conf file. Show
A simple example resolv.conf file for a client (non-server) machine in the doc.com domain is shown below. Example 4–2 Sample resolv.conf File
The first line of the /etc/resolv.conf file lists the domain name in the following form. Where domainname is the name registered with the Internet governing bodies (as of this writing, the InterNIC). Note –No spaces or tabs are permitted at the end of the domain name. Make sure that you enter a hard carriage return immediately after the last character of the domain name. The second line identifies the loopback name server in the form. Succeeding lines list the IP addresses of up to three DNS master, slave, or cache-only name servers that the resolver should consult to resolve queries. Do not list more than three master or slave servers. Name server entries have the following form. IP_address is the IP address of a master or slave DNS name server. The resolver queries these name servers in the order they are listed until it obtains the information it needs. The fifth line of the /etc/resolv.conf file lists the address sortlist in the form: addresslist specifies the sort order of the addresses returned by gethostbyname(3c). In our example, gethostbyname returns the netmask pair 130.155.160.0/255.255.240.0 ahead of the IP address 130.155.0.0. Modify the /etc/nsswitch.conf file. NIS. If your master enterprise-level naming service is NIS, with proper configuration, NIS is already DNS-enabled. Files-based. If your master enterprise-level naming service is based on /etc files, or if your master enterprise-level naming service is NIS+, do the following.
The Domain Name System (DNS) is used to resolve (translate) hostnames to internet protocol (IP) addresses and vice versa. A DNS server, also known as a nameserver, maps IP addresses to hostnames or domain names. In this article, you will learn the basics of DNS, from how DNS gets the IP address and hostname, to the concepts of forward and reverse lookup zones. It will also show you how to install and configure DNS, define and edit zone files, and verify whether the DNS can resolve to the correct address with the help of commands. If you are new to DNS, this article will help you play with it on your system using basic configurations. How DNS worksWhen a client requests information from a nameserver, it usually connects to port 53, and then the nameserver resolves the name requested. (Ashish Bharadwaj, CC BY-SA 4.0) Where does DNS get IP addresses?You might wonder how DNS gets the IP of the corresponding hostname or domain name. How does DNS search among different IP addresses and associate your domain name correctly? Who stores those mappings between domain names and IP addresses? The DNS workflow illustrates how communication happens within DNS and how it resolves the addresses. (Ashish Bharadwaj, CC BY-SA 4.0)
[ Download now: A system administrator's guide to IT automation. ] Forward and reverse lookupsThe forward lookup zone uses the domain name to search for IP addresses, whereas the reverse lookup zone uses IP addresses to search for the domain name. (Ashish Bharadwaj, CC BY-SA 4.0) Install and configure DNSBIND is a nameserver service responsible for performing domain-name-to-IP conversion on Linux-based DNS servers. [root@servera ~] # yum install bindThe BIND package provides the named service. It reads the configuration from the /etc/named and /etc/named.conf files. Once this package is installed, you can start configuring DNS. Configure the /etc/named.conf fileFirst, add or edit the two values in the options field. One is the DNS server address, and the other is the allow-query to any. [root@servera ~] # vim /etc/named.conf listen-on port 53 { 127.0.0.1; 192.168.25.132; }; allow-query { localhost; any; };Here are the values from the above file:
Define the forward and reverse zonesDefine the forward and reverse zones in the /etc/named.conf or /etc/named.rfc1912.zones (you can define zones in either of those files). In this example, I am appending zone definition details to the /etc/named.rfc1912.zones file. [root@servera ~] # vim /etc/named.rfc1912.zones zone "example.com" IN { type master; file "example.forward.zone"; allow-update { none; }; }; zone "25.168.192.in-addr.arpa" IN { type master; file "example.reverse.zone"; allow-update { none; }; };Create forward and reverse zone filesYou also need to create forward and reverse zone files in the /var/named directory. Note: By default, the named.conf file includes the /var/named directory for checking zone files. Sample zone files named.localhost and named.loopback are created during the installation of the BIND package. [root@servera ~] # vim /var/named/example.forward.zone
(Ashish Bharadwaj, CC BY-SA 4.0) Add the nameserver IP to /etc/resolv.confFirst, you must disable DNS processing by NetworkManager because it dynamically updates the /etc/resolv.conf file with DNS settings from its active connection profiles. To disable this and allow manual editing of /etc/resolv.conf, you must create a file (For example, 90-dns-none.conf), as root in the /etc/NetworkManager/conf.d/ directory that contains the following: [main] dns=noneSave the file and reload (restart) NetworkManager. # systemctl reload NetworkManagerAfter you reload NetworkManager, it won't update /etc/resolv.conf. Now, you can manually add the nameserver's IP address to the /etc/resolv.conf file. [root@servera ~] # vim /etc/resolv.conf # Generated by NetworkManager search localdomain example.com nameserver 192.168.25.132[ Be prepared in case something goes wrong. Read An introduction to DNS troubleshooting. ] Start/restart and enable the named serviceIf the named service is not running or is disabled, then start and enable it. If it is already active (running) and you made all these configurations, you need to restart the service to make changes. [root@servera ~] # systemctl status named.service [root@servera ~] # systemctl start named.service [root@servera ~] # systemctl enable named.service [root@servera ~] # systemctl restart named.serviceVerify the DNS name resolutionYou have installed the BIND package, configured named files, created lookup zones, and restarted the service to make configurations take effect. Now use the nslookup and dig commands to check whether DNS is working properly and verify whether you are getting the intended results.
Query with nslookup[root@servera ~] # nslookup servera.example.com Server: 192.168.25.132 Address: 192.168.25.132#53 Name: servera.example.com Address: 192.168.25.132 [root@servera ~] # nslookup 192.168.25.132 132.25.168.192.in-addr.arpa name = servera.example.com.Query with digHere is a forward lookup, where DNS responds with 192.168.11.132 as an IP for servera.example.com: [root@servera ~] # dig servera.example.com ...output truncated... ;; ANSWER SECTION: servera.example.com. 86400 IN A 192.168.25.132 ;; AUTHORITY SECTION: example.com. 86400 IN NS servera.example.com. ...output truncated...This example displays a reverse lookup, where the DNS server responds with servera.example.com as the domain name for 192.168.25.132: [root@servera ~] # dig -x 192.168.25.132 ...output truncated... ;; ANSWER SECTION: 132.25.168.192.in-addr.arpa. 86400 IN PTR servera.example.com. ;; AUTHORITY SECTION: 25.168.192.in-addr.arpa. 86400 IN NS servera.example.com. ;; ADDITIONAL SECTION: servera.example.com. 86400 IN A 192.168.25.132 ...output truncated...[ Network getting out of control? Check out Network automation for everyone, a free book from Red Hat. ] Wrap upIn this article, you learned what DNS is and how it works. Also, you now know what forward and reverse lookup zones are and how they work. You also learned how to install the BIND package, which is responsible for setting up DNS on the system and configuring the named files and lookup zones. Finally, you learned two commands, nslookup and dig, to interrogate DNS resolutions. |