How I configure DNS on Ubuntu Linux distros via the command line - it's easier than you think
Tech Why you can trust ZDNET : ZDNET independently tests and researches products to bring you our best recommendations and advice. When you buy through our links, we may earn a commission. Our process 'ZDNET Recommends': What exactly does it mean? ZDNET's recommendations are based on many hours of…
Tech Why you can trust ZDNET : ZDNET independently tests and researches products to bring you our best recommendations and advice. When you buy through our links, we may earn a commission. Our process 'ZDNET Recommends': What exactly does it mean? ZDNET's recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.ZDNET's editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form. Close Home Tech Services & Software Operating Systems Linux How I configure DNS on Ubuntu Linux distros via the command line - it's easier than you think DNS is a critical component for PC networking, searching, and security. If you want to learn how to set it up on Ubuntu-based distros from the command line, here's how. Written by Jack Wallen, Contributing WriterContributing Writer July 20, 2026 at 7:19 a.m. PT Jack Wallen/ZDNETFollow ZDNET: Add us as a preferred source on Google.ZDNET's key takeawaysI use Netplan to customize DNS on Ubuntu-based distros.This CLI method may be daunting, but you'll see its power.This method can be used on desktops and servers alike.Every once in a while, you might find yourself in a situation where you need to change DNS providers, and you don't have access to a desktop GUI. You might be dealing with a PC remotely, an at-home server, or maybe you just want to up your Linux skills. Either way, you might want to know how to configure DNS with the Netplan tool, which is the command-line system for configuring networking on Ubuntu-based desktops. Before we get into it, know that configuring DNS the GUI way is very easy, so if you have access to a desktop environment, you could do this without ever touching the command line. If, on the other hand, you've used SSH to remote into a machine (or the machine simply has no GUI), be glad the command line method is almost as easy (as long as you have at least a modicum of experience with the command line). Also: 7 Linux commands I can't live without after 20 years in the terminalFortunately, it's not as hard as you think. All you need to do is edit a single file. Do note that this does work, whether you have your system set up for a DHCP IP address or a static IP address. What is Netplan? Netplan is used for network configurations on Linux systems. With this tool, you create a description of a network interface, define what it should do, and then apply it. Netplan files are laid out in YAML configurations and can be used on server, desktop, cloud, or even IoT installations. It is also capable of controlling various backends, such as NetworkManager and systemd-networkd. Netplan is configured via files within the /etc/netplan directory, where you may or may not find multiple YAML files. Most desktops using DHCP will only have one YAML file, but it's not out of the ordinary to have multiple files. Also: 5 reasons you should ditch Windows for Linux todayThe layout of the config file is typical YAML, where you'll have a description of an option on the left side of a colon and then the option on the right, such as: dhcp4: true Keep in mind that YAML is very picky about indentation, so make sure you follow the indentation layout of the file you are editing. If you get an error when applying a configuration file, most likely it's caused by improper indentation. Also: Linux desktop frozen? My 5 go-to tricks to try - before forcing a hard rebootAnother issue to think about is that on the desktop, your DNS is probably controlled by NetworkManager. You can override that functionality (to give you more flexibility) by adding the following to /etc/NetworkManager/NetworkManager.conf dns=none rc-manager=unmanaged Save and close the file. Restart NetworkManager with: sudo systemctl restart NetworkManager With that said, let's configure. Configuring the Netplan file Let's assume you'll be using Cloudflare's secure DNS addresses of 1.1.1.1 and 1.0.0.1. 1. Open the terminal Open your terminal app and change into the netplan directory with: Show more cd /etc/netplan 2. Locate the file name and back it up View what's in the directory with the ls command. If you see multiple files, more than likely, the one you want begins with 00. In my case, it's 00-netplan.yaml. Before you edit the file, make a backup with the command: Show more sudo cp 00-netplan.yaml 00-netplan.yaml.bak Make sure to edit the above command to conform to the file you need to edit. 3. Edit the file Open the original file for editing with: Show more Make sure to edit the above command to conform to the file you need to edit. With the file open, look for the line: nameservers: That's the section where DNS is configured. If you don't see that line, you'll add it. If you need to add it, place it above the dhcp4: true line. Here's how the DNS section looks, using the Cloudflare addresses:nameservers: addresses: - 1.1.1.1 - 1.0.0.1 Make sure the n in nameservers is in the same column as the d in dhcp4. That should ensure proper indentation. If not, you'll have to adjust the indentation according to your file layout. 4. Save and close the file After you've added the line, save and close the file with the Crtl+X keyboard shortcut. Show more Applying the editsTo apply the new edits, issue the command:sudo netplan applyIf you receive any errors, go back and alter the indentation of the namserver section to make sure it is indented properly; otherwise, your new DNS servers should now be in effect. To make sure DNS is functioning, issue the command:ping google.comIf you see results, congratulations, DNS is working properly. To verify if the new addresses are being used, issue the command:resolvectl status | grep "DNS"If you see the old DNS addresses, restart your machine, and all should be good.Also: 5 of my favorite Linux distros ready to use out of the box - no setup requiredOpen Source How AI has suddenly become much more useful to open-source developers Google's Gemma 4 model goes fully open-source and unlocks powerful local AI - even on phones Why AI is both a curse and a blessing to open-source software - according to developers I tried a Claude Code rival that's local, open source, and completely free - how it went How AI has suddenly become much more useful to open-source developers Google's Gemma 4 model goes fully open-source and unlocks powerful local AI - even on phones Why AI is both a curse and a blessing to open-source software - according to developers I tried a Claude Code rival that's local, open source, and completely free - how it went Editorial standards Show Comments Log In to Comment Community Guidelines Related Best Amazon Prime Day Walmart deals: I'm tracking 40+ of my favorite discounts still live Prime Day is over, but these 60+ top deals are still live (for now): Apple, Garmin, LG, more Last chance to grab Prime savings on TVs, laptops, Apple and more