Tuesday, July 21, 2026

How I configure DNS on Ubuntu Linux distros through the command line – it is simpler than you assume

Share


netplanhero

Jack Wallen/ZDNET

Comply with ZDNET: Add us as a preferred source on Google.


ZDNET’s key takeaways

  • I exploit Netplan to customise DNS on Ubuntu-based distros.
  • This CLI technique could also be daunting, however you will see its energy.
  • This technique can be utilized on desktops and servers alike.

Each now and again, you may end up in a state of affairs the place it is advisable change DNS suppliers, and you do not have entry to a desktop GUI. You is likely to be coping with a PC remotely, an at-home server, or possibly you simply need to up your Linux abilities.

Both approach, you may need to know methods to configure DNS with the Netplan device, which is the command-line system for configuring networking on Ubuntu-based desktops.

Earlier than we get into it, know that configuring DNS the GUI approach may be very simple, so when you have entry to a desktop atmosphere, you can do that with out ever touching the command line. If, then again, you’ve got used SSH to distant right into a machine (or the machine merely has no GUI), be glad the command line technique is nearly as simple (so long as you’ve no less than a modicum of expertise with the command line).

Additionally: 7 Linux commands I can’t live without after 20 years in the terminal

Fortuitously, it is not as arduous as you assume. All it is advisable do is edit a single file. Do be aware that this does work, whether or not you’ve your system arrange for a DHCP IP tackle or a static IP tackle.

What’s Netplan?

Netplan is used for community configurations on Linux techniques. With this device, you create an outline of a community interface, outline what it ought to do, after which apply it. Netplan information are specified by YAML configurations and can be utilized on server, desktop, cloud, and even IoT installations. It’s also able to controlling numerous backends, reminiscent of NetworkManager and systemd-networkd.

Netplan is configured through information inside the /and so forth/netplan listing, the place chances are you’ll or could not discover a number of YAML information. Most desktops utilizing DHCP will solely have one YAML file, however it’s not out of the strange to have a number of information.

Additionally: 5 reasons you should ditch Windows for Linux today

The structure of the config file is typical YAML, the place you will have an outline of an possibility on the left facet of a colon after which the choice on the appropriate, reminiscent of:

dhcp4: true

Remember that YAML may be very choosy about indentation, so be sure to observe the indentation structure of the file you’re enhancing. In case you get an error when making use of a configuration file, almost definitely it is brought on by improper indentation.

Additionally: Linux desktop frozen? My 5 go-to tricks to try – before forcing a hard reboot

One other subject to consider is that on the desktop, your DNS might be managed by NetworkManager. You may override that performance (to offer you extra flexibility) by including the next to /and so forth/NetworkManager/NetworkManager.conf

dns=none
rc-manager=unmanaged

Save and shut the file. Restart NetworkManager with:

sudo systemctl restart NetworkManager

With that stated, let’s configure.

Configuring the Netplan file

Let’s assume you will be utilizing Cloudflare’s safe DNS addresses of 1.1.1.1 and 1.0.0.1. 

Open your terminal app and alter into the netplan listing with:


Present extra

cd /and so forth/netplan

View what’s within the listing with the ls command. In case you see a number of information, greater than probably, the one you need begins with 00. In my case, it is 00-netplan.yaml. Earlier than you edit the file, make a backup with the command:


Present extra

sudo cp 00-netplan.yaml 00-netplan.yaml.bak

Be sure that to edit the above command to evolve to the file it is advisable edit.

Open the unique file for enhancing with:


Present extra

Be sure that to edit the above command to evolve to the file it is advisable edit.

With the file open, search for the road:

nameservers:

That is the part the place DNS is configured. In case you do not see that line, you will add it. If it is advisable add it, place it above the dhcp4: true line. Here is how the DNS part seems, utilizing the Cloudflare addresses:

nameservers:
    addresses:
    – 1.1.1.1
    – 1.0.0.1

Be sure that the n in nameservers is in the identical column because the d in dhcp4. That ought to guarantee correct indentation. If not, you will have to regulate the indentation in keeping with your file structure.

After you’ve got added the road, save and shut the file with the Crtl+X keyboard shortcut. 


Present extra

Making use of the edits

To use the brand new edits, subject the command:

sudo netplan apply

In case you obtain any errors, return and alter the indentation of the namserver part to ensure it’s indented correctly; in any other case, your new DNS servers ought to now be in impact. To verify DNS is functioning, subject the command:

ping google.com

In case you see outcomes, congratulations, DNS is working correctly. To confirm if the brand new addresses are getting used, subject the command:

resolvectl standing | grep “DNS”

In case you see the outdated DNS addresses, restart your machine, and all needs to be good.

Additionally: 5 of my favorite Linux distros ready to use out of the box – no setup required





Source link

Read more

Read More