The /etc/resolv.conf
configuration file contains information that allows a computer to convert alpha-numeric domain names into the numeric IP addresses.
The process of converting domain names to IP addresses is called resolving.
When using DHCP, dhclient usually rewrites resolv.conf with information received from the DHCP server.
How do I edit the “/etc/resolv.conf” file?
Use text editor such as vi or gedit from Linux desktop:
# vi /etc/resolv.conf
There are three main configuration directives in /etc/resolv.conf
:
nameserver # DNS server IP domain # Domain Name of local host search # Which Domain to search
The “nameserver” directive
The nameserver
directive points out to the IP address of a Name Server.
nameserver <IP address>
It can be your own Name Server, some public Name Server or the Name Server of your’s ISP.
Note: Up to 3 name servers may be listed.
Example:
nameserver 192.168.0.100 nameserver 8.8.8.8 nameserver 8.8.4.4
The “domain” directive
Local domain name.
domain <local domain name>
Example:
domain domain.com nameserver 192.168.0.100 nameserver 8.8.4.4
How the “domain” directive in the “resolv.conf” file works?
You can use domain
directive for resolving short host-names – e.g. test
.
So if you have the following in your /etc/resolv.conf
:
domain example.com
Then your computer will try to resolve test.example.com
.
The “search” directive
Search list for hostname lookup. The search list is normally determined from the local domain name but it can be set to a list of domains.
search <search list>
Example:
search example.com company.net nameserver 192.168.0.100 nameserver 8.8.8.8
How the “search” directive in the “resolv.conf” file works?
You need to use search
directive for resolving short host-names – e.g. test
.
So if you have the following in your /etc/resolv.conf
:
search example.com company.net
Then your computer will try to resolve test.example.com
followed by test.company.net
. It will return the first query that was successful.
perfect!
Can you add an example for option: ndot:n
does it matter in which order those name-value pairs are mentioned in the file?
search / domain / nameserver key-value pairs…
I”m stuck here, please help
https://stackoverflow.com/questions/52224586/from-centos-6-9-failed-to-resolve-two-windows-domain-controllers-at-a-time-when
Hi, this is very helpful 🙂
One question: As you stated domain is overwriten if DHCP Client is used. I’m having two ethernet interfaces, one with fixed IP and one running on dhcp. Is it possible to force a domain in this configuration?
How can we use resolv.conf to redirect all dns requests to local ip address?
If DHCP is being used, the default behavior in Red Hat and its derivatives (CentOS, etc) is to inherit the DNS information from the DHCP server. However, this can be disabled by defining PEERDNS=no in your network configuration file located at
/etc/sysconfig/network-scripts/ifcfg-ens192 .
Keep in mind that ‘ifcfg-ens192’ may vary depending on the network card type on your system.
Here is an example:
cat /etc/sysconfig/network-scripts/ifcfg-ens192
TYPE=Ethernet
NAME=ens192
DEVICE=ens192
ONBOOT=yes
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=no
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPV6_AUTOCONF=no
NM_CONTROLLED=no
USERCTL=no
MTU=”1500″
Other options like DOMAIN= and SEARCH= can be applied globally by defining them on this file.
source:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s1-networkscripts-interfaces