resolv
In the context of DNS, the term resolv refers to the process of domain name resolution (DNS resolution)—the conversion of a human-readable domain name (e.g., example.com) into an IP address (e.g., 93.184.216.34) required to establish a network connection.
Key Aspects of Resolv in DNS
File `/etc/resolv.conf` This is a configuration file used in UNIX-like systems to specify DNS resolution parameters.
What Does the File Contain?
The file stores a list of DNS servers that the operating system uses to convert domain names into IP addresses. Example file content:
nameserver 8.8.8.8 nameserver 8.8.4.4 search localdomain
Where:
- nameserver specifies the IP address of the DNS server.
- search defines domains to automatically append to queries.
How DNS Resolving Works
The process works as follows:
When a user types a domain name (e.g., example.com) into a browser, the operating system first looks for a corresponding entry in the local cache (e.g., /etc/hosts). If the desired record isn’t found there, the system forwards the query to the DNS servers specified in the resolv.conf file. These DNS servers respond with the IP address associated with the requested domain.
Managing and Setting Up /etc/resolv.conf
How to Change the DNS Server? You can edit the file manually:
sudo nano /etc/resolv.conf
Add, for example:
nameserver 1.1.1.1 nameserver 8.8.8.8
These are Cloudflare and Google DNS servers.
Automatic File Management
In some systems, the file is managed automatically through:
- DHCP clients (e.g., dhclient).
- Network managers (e.g., NetworkManager).
To prevent changes, you can make the file read-only:
sudo chattr +i /etc/resolv.conf
Commands for checking resolution:
Basic DNS query:
nslookup example.com
Detailed query:
dig example.com
Problems and Solutions
DNS Is Not Working. What to Do?
Verify the resolv.conf file to confirm it lists active and functioning DNS servers. Opt for dependable options, such as:
- Google DNS: 8.8.8.8, 8.8.4.4
- Cloudflare DNS: 1.1.1.1, 1.0.0.1
- OpenDNS: 208.67.222.222, 208.67.220.220
The resolv.conf File Keeps Resetting
This may be caused by:
- DHCP.
- NetworkManager or another network manager.
Solution:
- Disable automatic updates.
- Configure DNS through DHCP or NetworkManager settings.
Delays in Domain Resolution
- Ensure fast DNS servers are specified.
- Set up a local caching DNS server, such as dnsmasq or unbound.
FAQ
How to Check Current DNS Settings?
Use the command:
cat /etc/resolv.conf
Can I Use Multiple Nameservers?
Yes, the system queries the servers in the order listed.
What Is the Search Parameter in resolv.conf?
It adds a specified domain to the query. For example:
If search example.com is specified, a query for host1 becomes host1.example.com.
What to Do if I Am Behind NAT and DNS Is Not Responding?
Check your router settings or use public DNS servers.
What Are Alternatives to DNS Servers?
You can use local caching resolvers or built-in DNS services such as systemd-resolved.