It seems to me, I need 127.0.0.1 added to the /etc/resolv.conf file (my server is using BIND and is a name server).
However, whenever I try to add it via the form on the “Hostname and DNS Client” page in Virtualmin, they are not saved.
In the file itself (/etc/resolv.conf) it says:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
So, how do I solve this?
I believe its saved in the network config when using the Hostname and DNS settings page.
Look at /etc/network/interfaces file. ‘dns-nameservers’ will be listed in the interface settings.
If you are using a VPS or a server configured with DHCP, it is common for the “resolv.conf” file to be overwritten by the DHCP server. This can drive you nuts without question as it did so many times before I learned how to address the matter.
You can effectively write content to the “resolv.conf” file, then make the file “read-only” making any further changes impossible until you remove the read-only status on the file.
The trick to making a file “read-only” or “immutable” comes with the program “chattr” which can change this attribute.
Once you’ve made the change, and before you restart the network (or Apply in Webmin) you need to go to the command line and enter:
chattr +i /etc/resolv.conf
If at a later date you want make changes to the file, simply enter the following command:
chattr -i /etc/resolv.conf
This will remove the write protection from the file.
Hope this helps!
There is one “dirty” trick what will always work:
- Go to
/root and run
cp /etc/resolv.conf /root/resolv.conf.
- Use WinSCP, nano or any other software and open
- At the bottom insert this line
/bin/cp /root/resolv.conf /etc/resolv.conf.
- Leave one empty line at the end and save.
- Again use WinSCP (nano…) and open
- This is what you should have in this file:
xxx.xxx.xxx.xxx is IP of your server.
- Dont mess up this order, e.g. must be exactly as i posted.
- Last but not least check if
/etc/rc.local is executable, if isnt make it.
For now on every time when you restart your server the file
/etc/resolv.conf will be replaced with
/root/resolv.conf and no more problems with missing
127.0.0.1. This is why i call this “dirty” trick but compared to anything else it will work 100%… at least i never encountered any problem. This usually happens with VPS on OpenVZ virtualization.
P.S. This was for Centos 6/7 but it should work with any other OS.
Unfortunately Debian 9 is missing the rc.local.
Any idea how to solve this?
Rather than “hack” the system, when you are using DHCP, just edit the dhclient.conf file and supersede:
# vim /etc/dhcp/dhclient.conf
supersede domain-name-servers 188.8.131.52, 184.108.40.206;
supersede domain-name-servers 127.0.0.1;
Remember that you need to “reboot” rather than just “restart networking” on Ubuntu 18.