Researching a solution

A little reading on the Virtualmin forum led me to this page which seems to hint that my server may be receiving its address by DHCP or that my DNS servers are being overwritten each time that the server is rebooted. 

The Problem

For about as long as I've been using Virtualmin on OpenVZ VPS servers, I have encountered this problem. It pertains to the following error message reported by Virtualmin

Virtualmin is configured to setup DNS zones, but this system is not setup to use itself as a DNS server. Either add to the list of DNS servers, or turn off the BIND feature on the module config page.

I wrote about this a while ago on this site, but the solution I wrote then does not permanently solve the problem.

There seems to be a problem on OpenVZ VPS servers that run Virtualmin such that the error is produced. The problem is mainly that in OpenVZ, the /etc/resolv.conf file gets overwritten by the OpenVZ host node on every boot/reboot. 

What I've tried in the past is adding a line with "nameserver" to the end of /etc/resolv.conf and it works. But it only works until I reboot the system. Once the server is rebooted, the problem comes back again, I guess because something overwrites the file on every reboot.

So before proceeding any further, I wanted to be sure that my /etc/resolv.conf was being overwritten. 

I opened up my favorite editor and added a commented line at the end of the /etc/resolv.conf file. It was just a little line that said "# If this line is gone after reboot, then this file is being overwritten!"

I saved the file and rebooted.


After the server rebooted, I was surprised at what I saw. The whole file wasn't completely overwritten. My comment was there, but instead of being at the bottom of the file, the commented line was at the top of the file. 

What appeared to be happening was that on every boot, all of the files contents except for comments were being deleted and then the nameservers, and, were being appended to the end of the file.

I tried another experiment. I kept my comment at the top of /etc/resolv.conf, but I added an uncommented line containing "nameserver" at the end of the file. Then I rebooted again.

And after reboot, the uncommented line containing "nameserver" was gone. It was removed. All that was in the file was my commented line and the two nameserver lines that the OpenVZ VPS host node seemed to be adding to the file during every boot.

With this new knowledge, the knowledge that the VPS host node was indeed overwriting my /etc/resolv.conf file, I proceeded to read the recommendations listed in the Virtualmin documentation regarding DNS issues.

"If you're certain -- absolutely certain -- that your server isn't obtaining it's IP address via DHCP -- the issue you're seeing can occur when using a VPS, where your VPS provider automatically overwrites your /etc/resolv.conf file each reboot." -

This is something that I previously didn't think I had any control of since this is an OpenVZ VPS and not a regular server, but the Virtualmin documentation provided more than one solution.


A non-ideal solution

The first solution is described as non-ideal. It involves just going into Virtualmin's advanced settings and checking the box for 'Check resolv.conf for this system' to 'No". This was described as non-ideal because it would cause DNS lookups to be slower on the server.

So I didn't want that solution because it would slow down DNS lookups.

The recommended solution

Instead, I took the next recommendation that the article provided. The recommendation was to make the /etc/resolv.conf file immutable. What that means (immutable) is that the /etc/resolv.conf file would be unchangeable by anyone - even root.

First, I added the line "nameserver" at the end of my /etc/resolv.conf file.

I also added a note, which was commented out, to explain to a possibly confused "future me" that the file was made immutable so that it wouldn't get overwritten by the VPS host node on every reboot.

Once I added "nameserver" to the end of the file, and after I added my comment, I saved the file.

Then I did the command to make the /etc/resolv.conf file immutable:

chattr +i /etc/resolv.conf

If you get an error which says "-bash: chattr: command not found" that just means that chattr isn't installed on your system. Here are instructions on how to install chattr on Debian.

I gave the server a reboot and then I could see if the chattr command was able to make /etc/resolv.conf immutable so that it wouldn't get overwritten by the host node.

And it worked! I was able to add to the list of nameservers in /etc/resolv.conf on my Debian VPS server and not have it become overwritten every time that I rebooted the server.

And now Virtualmin will no longer show me that error message which said that I must add to the list of nameservers or to turn off Bind.