Adding to /etc/resolv.conf ?

It seems to me, I need 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:

  1. Go to /root and run cp /etc/resolv.conf /root/resolv.conf.
  2. Use WinSCP, nano or any other software and open /etc/rc.local.
  3. At the bottom insert this line /bin/cp /root/resolv.conf /etc/resolv.conf.
  4. Leave one empty line at the end and save.
  5. Again use WinSCP (nano…) and open /root/resolv.conf.
  6. This is what you should have in this file:


    where is IP of your server.

  7. Dont mess up this order, e.g. must be exactly as i posted.
  8. Save /root/resolv.conf.
  9. 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 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,;
supersede domain-name-servers;

Remember that you need to “reboot” rather than just “restart networking” on Ubuntu 18.