Virtualmin has the ability to manage your domain’s DNS when properly configured. But it’s optional, you can use your domain registrar or third party services like CloudFlare to host your DNS. In any case, there a bug on some Ubuntu systems that prevent Virtualmin from mapping domains inside your VPS. This post intend help you fix it for good.
So I was setting up a new server for a client with Ubuntu 16.04, Virtualmin and Nginx. Server’s DNS was managed by DigitalOcean itself. But where DNS is hosted does not play a part in this case. I tried to enable Nginx modules in the Features and Plugins after running Virtualmin post-installation wizard. But it failed with following error.
Failed to save enabled features : Virtualmin is configured to setup DNS zones, but this system is not setup to use itself as a DNS server. Either add 127.0.0.1 to the list of DNS servers, or turn off the BIND feature on the module config page.
As you can see, Virtualmin gives possible solutions along with the error. This can be easily fixed by adding 127.0.0.1 to the list of DNS Servers. But unfortunately that doesn’t work. Changes you make to the list of DNS servers does not get saved. It won’t even give you an error message.
The other solution Virtualmin suggest is to disable DNS server. That won’t work for me since Virtualmin will then fail to serve domains from it’s home directory and serve pages from Ubuntu’s default html directory. This will result in an Apache default page on your domain although you have NGINX installed.
This error is caused by DHCP. DigitalOcean uses DHCP to assign IP addresses to droplets. And while obtaining the IP address for your server, DNS servers provided by DigitalOcean are used by DHCP server instead of what’s currently setup on your server. This is the reason why you couldn’t add 127.0.0.1 to the list of DNS Servers. It gets overwritten.
I could fix this by adding 127.0.0.1 to the /etc/resolv.conf (list of DNS Servers) file from command line. But it gets overwritten on each server boot-up. What if I can add 127.0.0.1 to the /etc/resolv.conf file on each boot-up? that’s exactly how I’m going to fix this. You can use /etc/rc.local to add peace of code that adds 127.0.0.1 to the /etc/resolv.conf file on each boot-up. So open your /etc/rc.local file from command line. You need to be root user to do this.
Now paste following file before the line that reads exit 0
echo nameserver 127.0.0.1 >> /etc/resolv.conf
Save rc.local file with the change and reboot the server,
Error should be fixed now.