Are you facing any problem with /etc/resolv.conf file when it automatically reset on boot, and all custom configuration get varnish from the file?
In early days, when I was rebooting my Linux machine after some time realize I am not getting any email, alert from the server and in the log getting host not found then only go to the resolv.conf file and edit it to mention my DNS server.
Every day I thought why it not saved permanently when I edit the /etc/resolv.conf file.
And one day when I saw on top of the page, Oh.. I was too stupid. There are already written in the file.
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
Now I just started to find why it is happening and how to make /etc/resolv.conf file permanent.
The file /etc/resolv.conf gets changed on every boot; this file is configured by the network service of the Linux system dynamically, and the DHCP service updates DNS parameter.
So, the DHCP service is only responsible for removing my DNS configuration from /etc/resolv.conf file.
Now, It’s time to work on the solution for this issue.
Whenever I am working to found solution for any problem, first I speak with myself to understand if I solve the issue how much time it will save for me in future and my answer is going to help others?
When I got the answer to my above question, I am getting the motivation to solve the problem?
In this case, I found if I solve this issue, my server will work smoothly and no need to remind to configure “/etc/resolv.conf” file on every boot. So, yes It will save my time on every boot of Linux machine.
Now I started to work around solution for making /etc/resolv.conf file permanent with custom configuration.
To achieve this solution, we found the various method which can make resolv.conf file static or permanent.
Some of the methods are here:
Method 1 – Using DHCP configuration file
You can change the DHCP configuration file (dhclient.conf) for configuring static DNS for the system. The DHCP configuration file location is /etc/dhcp/dhclient.conf; you can find the below line in the file:
# supersede domain-name "fugue.com home.vix.com"; # prepend domain-name-servers 127.0.0.1;
You need to remove the comment symbol ‘#’ from the beginning of the line and enable it with your domain-name and domain-name-server parameter which you want and save the file.
Now your system DNS configuration will always be static even on the boot of the system.
Method 2 – Using resolvconf package
There is one another alternate option to make static DNS for your Linux system is using the “resolvconf” tool.
To use the “resolvconf” tool, you need first to install this tool in your system, as shown below.
$ sudo apt-get install resolvconf
The above command you can use in Ubuntu Linux to install “resolvconf” tool.
Once “resolvconf” installed in your system need to edit the configuration file in below location:
After configuring your DNS in the file, save it and close.
Now your permanent and static DNS is configured for the system.
I hope, now your issue related with /etc/resolv.conf will solve, and you will get sweet dreams every night.