How to Configure DNS on Ubuntu Using Netplan
Easily customize your DNS settings via the command line.
1What is Netplan?
Netplan is a command-line tool for managing network configurations on Ubuntu-based Linux distributions. It uses YAML-formatted configuration files to provide flexible network settings for both desktop and server systems. It simplifies DNS changes for systems using either DHCP or static IP addresses.
2Preparation Steps
Before changing DNS settings, you may need to disable NetworkManager's DNS control. Add 'dns=none' and 'rc-manager=unmanaged' to /etc/NetworkManager/NetworkManager.conf and restart the service. This step is crucial to allow Netplan to manage your DNS settings effectively.
3Editing the DNS File
Modify the YAML configuration file (usually 00-netplan.yaml) in /etc/netplan to change your DNS servers. When adding preferred DNS addresses like Cloudflare (1.1.1.1, 1.0.0.1) under the 'nameservers' section, pay attention to YAML indentation rules. Always back up the file before saving changes.
4Applying Changes
After saving your edits, activate the new settings with 'sudo netplan apply'. If you encounter indentation errors, check the YAML file syntax. Test your internet connection with 'ping google.com' after successful application.
5Verification Process
Verify your new DNS settings with 'resolvectl status | grep "DNS"'. If you see old DNS addresses, a system reboot might be necessary. These steps ensure you have both secure and performant DNS configuration.
6Why Command Line?
Command-line DNS configuration can be lifesaving in server environments without GUI or during remote access. Tools like Netplan allow Linux system administrators to manage network settings centrally and consistently. Mastering this skill represents an important step in technical competency development for Linux users.
Original article: Latest news — Ubuntu'da Netplan ile DNS Yapılandırma Rehberi