DevOpsDocs Help

Change DNS Nameserver via Config File

If you do not use a GUI, change DNS settings with the command line Netplan tool.

  1. Go to the Netplan directory:

cd /etc/netplan
  1. List the directory contents with ls to see the name of the yaml file containing network configuration.

Checking the /etc/netplan folder contents Open the file in a text editor. Your file may have a different name.

sudo vi 01-network-manager.yaml

Ethernet connections are listed in the ethernets section of the file. If there are any wireless connections, you can find them in the wifis section. Netplan stores the current DNS configuration parameters in nameservers subsections of each section.

Editing the yaml file in /etc/netplan using nano Replace the addresses located in the file with the DNS addresses you want to use. You can enter more than two addresses. Save the changes and exit.

Note: The file on your system may lack the entire ethernets or wifis section. In that case, add the lines that are missing, making sure you respect the indentation provided in the example.

  1. Apply the changes you made in the config file:

sudo netplan apply

If the operation is successful, there is no output. To check if the system successfully applied the changes, type:

resolvectl status | grep "DNS Server" -A2
Last modified: 07 March 2024