Report this

What is the reason for this report?

How to override default DNS servers?

Posted on April 29, 2021

Our system uses an internally managed DNS powerdns-recursor with a bunch of forwarded zones for our split-horizon DNS. We’re using Ubuntu 18.04 images, which by default configure /etc/netplan/50-cloud-init.yaml with DO’s name servers, which then systemd-resolv picks up on.

Is there a ‘proper’ way to remove the name servers, or simply replace them with our custom servers? The only way I can think of doing this would involve a pre-network oneshot systemd service to re-write the file after cloud-init does it’s thing.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

To replace or remove the default DigitalOcean name servers with your custom name servers, you can modify the /etc/netplan/50-cloud-init.yaml file. Here’s how:

  1. network:
  2. ethernets:
  3. eth0:
  4. dhcp4: true
  5. dhcp6: true
  6. match:
  7. macaddress: XX:XX:XX:XX:XX:XX
  8. set-name: eth0
  9. version: 2
  10. nameservers:
  11. addresses: [your.nameserver.ip.1, your.nameserver.ip.2]

Replace your.nameserver.ip.1 and your.nameserver.ip.2 with your custom name servers’ IP addresses. After updating the file, apply the new configuration:

  1. sudo netplan apply

This method will work without needing a pre-network oneshot systemd service.

Regards

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.