I run a mail server, and it runs 99% fine. One issue I have is that I cannot utilise DNS blocklists for checking incoming emails for spam because the OVH default DNS is an open resolver and most DNS blocklists will therefore block the OVH default DNS. I would like to avoid this if possible. I can, and have, set up unbound to run as a local DNS server for my email machine, but something, I assume cloud-init, is overriding my changes to /etc/resolv.conf.
Is there a proper way of changing the DNS that my VPS will use? And does OVH run any internal, closed DNS resolvers for my VPS to access, or should I just run my own DNS?
Hello @Swedish
The problem is not your Unbound server, but cloud-init is overwriting your changes in /etc/resolv.conf when rebooting.
I'll suggest something to see if it works for you:
- Create a configuration file to disable DNS management by NetworkManager:
sudo nano /etc/NetworkManager/conf.d/99-cloud-init-no-dns.conf
Inside the file add the following:
[main]
dns=none
- Restart the network service:
sudo systemctl restart NetworkManager
- Restore your Unbound configuration in /etc/resolv.conf. It should now point to 127.0.0.1
Let me know if it works, cheers 
Sergio Turpín
Hello @sturpin
Indeed, I was fairly sure it was cloud-init causing problems. I don't have NetworkManager installed, but I could install it to get it to re-write my resolv.conf on bootup. However, my /etc/resolv.conf file is being re-written even without the system restarting. The latest modification date on it is Oct 5 13:27, even though my system has been up for weeks currently, and it seems to be re-written about every six hours, so I don't think NetworkManager alone would solve my problem. I believe I could also just chattr +i /etc/resolv.conf to stop cloud-init making changes to /etc/resolv.conf but my preference would be to actually disabled the part of cloud-init that tries to make the changes. However, I've not been able to decipher enough of the documentation for cloud-init to determine how to stop it changing the DNS settings specifically. My guess was that it has something to do with /etc/networking/interfaces.d/50-cloud-init.cfg as this seems to actually mention the OVH DNS server IP address. However, the documentation for disabling it seems to only suggest the option to completely disable networking configuration via cloud-init and I'd rather not do that as that would mean that a setting change from OVH could render my VPS unreachable over the network.
Yes, that’s the right way and you don’t need to install anything else. Create the file /etc/cloud/cloud.cfg.d/99-custom-dns.cfg with:
manage_resolv_conf: false
After this change, restart the VPS. With that, cloud-init will stop touching /etc/resolv.conf on each boot. Sometimes, even if you set that option, a residual nameserver remains in the file. If that happens to you, simply edit /etc/resolv.conf manually one last time to point to your Unbound (127.0.0.1) and save.
If you prefer, you can wait for a response from someone on Staff to see if they can verify my version.
Kind regards,
Sergio Turpín
Thanks for helping with the investigation. Disabling the manage_resolv_conf seems like a good tip at first, but according to the documentation at https://docs.cloud-init.io/en/latest/reference/modules.html#mod-cc-resolv-conf that module shouldn't be used on Debian. The /etc/resolv.conf file also doesn't have the usual boilerplate that cloud-init would usually add to the file, and I also don't think that module would be re-writing the resolv.conf file every few hours. I've dug around within cloud-init and have found the following:
$ cloud-init query ds.network_json.services
[
{
"address": "213.186.33.99",
"type": "dns"
}
]
This seems to be where cloud-init gets the DNS information (there's no other mention of the DNS server anywhere in the data source for cloud-init), but I cannot find any documentation on the network_jsonobject, so I cannot know for sure. My guess is that this is used to create files under /etc/network/interfaces.d/ and then there's some other script that occasionally updates /etc/resolv.conf with data from those interfaces files. However, I cannot find any evidence of this other script. I'm also happy to wait to see if Staff have any light to shine on the situation.