Software & AppsOperating SystemLinux

What is the Effect of the Nameservers Field in Netplan YAML Configuration File?

Ubuntu 10

In the world of Linux, Netplan is a utility for easily configuring networking on a Linux system. It uses YAML description files to configure network interfaces and, from these descriptions, will generate the necessary configuration options for any chosen renderer tool. One key aspect of this configuration is the nameservers field, which plays a crucial role in the system’s DNS resolution process. This article will delve into the details of the nameservers field in the Netplan YAML configuration file and its effects on a Linux system.

Quick Answer

The nameservers field in the Netplan YAML configuration file is used to specify the DNS servers that the system should use for name resolution. It plays a crucial role in the system’s DNS resolution process by consulting these servers when the local cache doesn’t contain the requested information.

Understanding Netplan

Netplan reads network configuration from /etc/netplan/*.yaml which are written by administrators, installers, cloud image instantiations, or other OS deployments. During early boot, it generates backend specific configuration files in /run to hand off control of devices to a particular networking daemon.

The Role of Nameservers in Netplan

The nameservers field in the Netplan YAML configuration file is used to specify the DNS servers that the system should use for name resolution. Essentially, these DNS servers are consulted when the local cache doesn’t contain the requested information.

For instance, a basic configuration might look like this:

network:
 version: 2
 renderer: networkd
 ethernets:
 enp3s0:
 dhcp4: no
 addresses: [192.0.2.3/24]
 gateway4: 192.0.2.1
 nameservers:
 addresses: [8.8.8.8, 8.8.4.4]

In this example, the addresses under nameservers are the IP addresses of the DNS servers. The system will use these servers for DNS resolution.

Checking the Configured DNS Servers

You can check the currently configured DNS servers by running the command systemd-resolve --status. This command displays the list of DNS servers being used by systemd-resolved, the default DNS system in Ubuntu 18.04 and later.

$ systemd-resolve --status

The output will list the DNS servers that systemd-resolved is currently using.

Troubleshooting DNS Issues

If you’re experiencing issues where applications are not using the DNS servers configured in Netplan, it could be due to other factors such as the presence of resolvconf. In such cases, you may need to purge resolvconf and ensure that /etc/resolv.conf is a static file with the correct configuration.

$ sudo apt purge resolvconf

After running this command, you should check /etc/resolv.conf to ensure it points to the correct DNS servers.

The Importance of the Search Field

In addition to the nameservers field, the search field in the Netplan configuration is used to specify the search domains for DNS queries. This means that if you enter a hostname without a domain, the system will append the domains listed in the search field to the hostname and try to resolve it.

In conclusion, the nameservers field in the Netplan YAML configuration file is a critical component in specifying the DNS servers to be used by the system for name resolution. Understanding and correctly configuring this field can help ensure that your system’s network connections function as expected.

How do I configure the `nameservers` field in a Netplan YAML configuration file?

To configure the nameservers field in a Netplan YAML configuration file, you need to specify the IP addresses of the DNS servers you want to use for name resolution. Here’s an example:

network:
 version: 2
 renderer: networkd
 ethernets:
 enp3s0:
 dhcp4: no
 addresses: [192.0.2.3/24]
 gateway4: 192.0.2.1
 nameservers:
 addresses: [8.8.8.8, 8.8.4.4]

In this example, the addresses field under nameservers contains the IP addresses of the DNS servers. You can specify multiple DNS servers by separating the addresses with commas.

How can I check the currently configured DNS servers in Netplan?

To check the currently configured DNS servers in Netplan, you can run the command systemd-resolve --status. This command will display the list of DNS servers being used by systemd-resolved, the default DNS system in Ubuntu 18.04 and later. Simply open a terminal and enter the following command:

$ systemd-resolve --status

The output will show the DNS servers that systemd-resolved is currently using.

Leave a Comment

Your email address will not be published. Required fields are marked *