Netplan Nameservers

7 min read Oct 12, 2024
Netplan Nameservers

How to Configure DNS Servers in Ubuntu 20.04 Using Netplan

In the realm of Linux system administration, configuring network settings is a fundamental task. Ubuntu 20.04, powered by the robust netplan system, offers a streamlined and intuitive way to manage network interfaces, including the crucial aspect of DNS servers. This article will guide you through the process of configuring DNS servers in Ubuntu 20.04 using netplan.

What is Netplan?

Netplan is a network configuration system designed for simplicity and clarity. It replaces the traditional /etc/network/interfaces file with a YAML-based configuration system. This YAML format makes it easy to read, understand, and modify network configurations, particularly for beginners.

Why Configure DNS Servers?

DNS servers act as the backbone of the internet's name resolution system. When you type a domain name like "google.com" into your browser, your computer queries a DNS server to translate that human-readable name into an IP address, allowing your browser to connect to the correct website.

Configuring DNS Servers with Netplan

Here's how to configure DNS servers using netplan in Ubuntu 20.04:

  1. Locate the Netplan Configuration File: The configuration file for netplan is typically located at /etc/netplan/01-netcfg.yaml.

  2. Edit the Configuration File: Use your preferred text editor, like nano or vim, to open the netplan configuration file.

  3. Modify the DNS Server Section: Look for the nameservers section within the network configuration block. If this section doesn't exist, you'll need to add it.

    Here's a simple example of a netplan configuration with two DNS servers set:

    network:
      version: 2
      ethernets:
        enp0s3:
          addresses: [192.168.1.100/24]
          gateway4: 192.168.1.1
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]
    

    In this example, we've configured the enp0s3 interface with the following:

    • addresses: The IP address and subnet mask of the interface.
    • gateway4: The IP address of the default gateway.
    • nameservers: An array containing the IP addresses of the DNS servers you want to use.
      • 8.8.8.8 and 8.8.4.4 are the public DNS servers provided by Google.
  4. Apply the Changes: After modifying the configuration file, save it. Then, apply the changes using the following command:

    sudo netplan apply
    

    This command will reload the netplan configuration and apply the new DNS server settings.

  5. Verify the Changes: To verify that the DNS server configuration has been applied successfully, you can use the nmcli command:

    nmcli connection show
    

    This command will display information about your active network connections, including the configured DNS servers.

Using Multiple DNS Servers

It's often a good practice to use multiple DNS servers for redundancy and improved performance. You can add multiple DNS server addresses to the nameservers array in your netplan configuration. For example:

nameservers:
  addresses: [8.8.8.8, 8.8.4.4, 1.1.1.1, 1.0.0.1]

Using Custom DNS Servers

If you want to use DNS servers provided by your ISP or your own custom DNS servers, you can replace the example DNS server addresses with the appropriate IP addresses.

Troubleshooting

If you encounter any issues configuring DNS servers with netplan, check the following:

  • Configuration Syntax: Double-check that the YAML syntax in your configuration file is correct.
  • File Permissions: Ensure that the netplan configuration file has the correct permissions. It should be owned by root and have read/write permissions for the root user.
  • Network Interface Name: Make sure you are using the correct name for your network interface. You can find this by running ip a in the terminal.
  • Apply Command: Ensure you have run the sudo netplan apply command after modifying the configuration file.

Conclusion

Netplan provides a user-friendly approach to managing network configurations, including DNS server settings. By following these steps, you can easily configure DNS servers in Ubuntu 20.04 to ensure proper internet name resolution and optimize your browsing experience. Remember to verify your configuration and troubleshoot any issues that may arise to ensure a smooth and efficient network setup.