How to Configure Dns on Ubuntu 20.04

Configuring DNS (Domain Name System) on Ubuntu 20.04 is an essential task for anyone setting up a server or managing network settings. DNS allows users to access websites and internet services using recognizable domain names, rather than IP addresses. In this blog post, we will explore how to configure DNS on Ubuntu 20.04, providing you with the knowledge and steps required to set up and manage DNS settings effectively.

Video Tutorial:

Why You Need to Configure DNS on Ubuntu 20.04

There are several compelling reasons why configuring DNS on Ubuntu 20.04 is crucial. Firstly, DNS resolution is necessary for the functioning of the internet as we know it. Without DNS, users would have to remember and manually input IP addresses to access websites or services, which is both inconvenient and prone to errors.

Secondly, configuring DNS on Ubuntu 20.04 allows you to control the routing and availability of various network resources. By assigning custom domain names to IP addresses, you can create a more user-friendly experience for your clients or users. It also enables you to set up internal domain names for your local network, making it easier to access local network resources.

Additionally, DNS configuration on Ubuntu 20.04 enables you to set up and manage certain security features. For example, you can utilize DNS filtering to block access to malicious websites or prevent users from accessing inappropriate content. By configuring DNS correctly, you can enhance both the security and productivity of your network.

Method 1. Configuring DNS via Network Manager GUI

Configuring DNS settings via the Network Manager GUI in Ubuntu 20.04 provides a user-friendly and intuitive way to manage DNS settings. Here are the steps to do it:

1. Click on the network icon in the top-right corner of the Ubuntu desktop.
2. Select "Wi-Fi Settings" or "Wired Settings" depending on your network connection type.
3. Click on the gear icon next to your network name to open the settings.
4. In the "IPv4" or "IPv6" tab, select the "Automatic (DHCP) addresses only" option.
5. Enter the desired DNS server addresses in the DNS servers field, separated by commas.
6. Click "Apply" to save the changes.

Pros Cons
1. Easy and straightforward process to configure DNS settings. 1. Limited advanced configuration options compared to command-line methods.
2. Suitable for users who prefer a graphical interface and ease of use. 2. Not suitable for bulk or automated DNS configuration.
3. Allows easy management of multiple network connections and their respective DNS settings. 3. May not be available on server editions of Ubuntu or headless setups without a graphical interface.

Method 2. Configuring DNS via Netplan

Netplan is the default network configuration tool in Ubuntu 20.04 and provides a powerful command-line method to configure DNS settings. Here’s how to do it:

1. Open a terminal on your Ubuntu 20.04 system.
2. Navigate to the "/etc/netplan" directory using the command:
"`bash
cd /etc/netplan
"`
3. Edit the Netplan configuration file using a text editor like nano or vim:
"`bash
sudo nano 01-netcfg.yaml
"`
4. In the configuration file, locate the networking interface and add the DNS server addresses under the "nameservers" section. For example:
"`yaml
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
"`
5. Save the changes and exit the text editor.
6. Apply the new Netplan configuration using the following command:
"`bash
sudo netplan apply
"`

Pros Cons
1. Provides more flexibility and advanced configuration options compared to the Network Manager GUI. 1. Requires basic knowledge of YAML syntax and Netplan configuration.
2. Suitable for bulk DNS configuration or automated setups using configuration management tools. 2. Not as user-friendly as the GUI method for those who prefer a graphical interface.
3. Allows fine-grained control over DNS settings for specific network interfaces. 3. May not be available or recommended on systems with complex network setups or multiple routing tables.

Method 3. Configuring DNS via /etc/resolv.conf

The "/etc/resolv.conf" file is another method to configure DNS settings directly on Ubuntu 20.04. Follow these steps to modify the file:

1. Open a terminal on your Ubuntu 20.04 system.
2. Edit the "/etc/resolv.conf" file using a text editor like nano or vim:
"`bash
sudo nano /etc/resolv.conf
"`
3. Add the DNS server addresses in the following format:
"`
nameserver 8.8.8.8
nameserver 8.8.4.4
"`
4. Save the changes and exit the text editor.

Pros Cons
1. Quick and straightforward method to configure DNS settings. 1. The "/etc/resolv.conf" file may be automatically overwritten by certain network management tools.
2. Suitable for temporary or one-time DNS configuration changes. 2. Not recommended for long-term or automated DNS management.
3. Allows manual overrides of DNS settings on a per-system basis. 3. May not be available or recommended on systems using Network Manager or Netplan for DNS configuration.

Method 4. Configuring DNS via systemd-resolved

Ubuntu 20.04 utilizes the systemd-resolved service to manage DNS resolution. Here’s how to configure DNS settings using this method:

1. Open a terminal on your Ubuntu 20.04 system.
2. Edit the "/etc/systemd/resolved.conf" file using a text editor like nano or vim:
"`bash
sudo nano /etc/systemd/resolved.conf
"`
3. Uncomment the line containing "DNS=" and add the desired DNS server addresses. For example:
"`
DNS=8.8.8.8 8.8.4.4
"`
4. Save the changes and exit the text editor.
5. Restart the systemd-resolved service to apply the new configuration:
"`bash
sudo systemctl restart systemd-resolved.service
"`

Pros Cons
1. Integrates well with the systemd service management system in Ubuntu 20.04. 1. Requires manual editing of a configuration file, which may be daunting for some users.
2. Provides more advanced configuration options like DNSSEC and DNS over TLS. 2. Not suitable for users who prefer a graphical interface or simplified configuration methods.
3. Allows fine-grained control over DNS settings with support for multiple DNS servers. 3. May not be available or recommended on systems using Network Manager or Netplan for DNS configuration.

What to Do If You Can’t Configure DNS on Ubuntu 20.04

If you encounter difficulties configuring DNS on Ubuntu 20.04, here are a few possible fixes:

1. Double-check the syntax and formatting of your DNS configuration. A small mistake can lead to DNS resolution issues.
2. Make sure you have administrative privileges when modifying configuration files or applying DNS changes.
3. Check for any conflicting DNS settings or firewall rules that may interfere with your DNS configuration.
4. Restart the networking service or restart your Ubuntu 20.04 system to ensure proper application of DNS settings.
5. If using a virtual machine, review the network settings to ensure correct DNS configuration within the virtual environment.

Bonus Tips

1. Use DNS caching services like Nscd or Dnsmasq to improve DNS resolution performance and reduce latency.
2. Consider implementing DNSSEC (DNS Security Extensions) to enhance the security and integrity of DNS responses.
3. Regularly monitor your DNS infrastructure for potential misconfigurations or performance issues using tools like dig or nslookup.

5 FAQs

Q1: How can I check my current DNS settings on Ubuntu 20.04?

A: You can check your current DNS settings by running the following command in a terminal: "systemd-resolve –status".

Q2: Can I configure DNS settings per-user in Ubuntu 20.04?

A: No, DNS settings are system-wide and apply to all users on the Ubuntu 20.04 system.

Q3: How can I prioritize or specify a preferred DNS server in Ubuntu 20.04?

A: You can specify a preferred DNS server by listing it first in the DNS configuration. The system will attempt to use the first DNS server before trying the others.

Q4: Are there any alternatives to the default DNS servers like 8.8.8.8?

A: Yes, there are several alternative DNS servers available, such as Cloudflare DNS (1.1.1.1), OpenDNS (208.67.222.222), or Quad9 DNS (9.9.9.9).

Q5: Can I configure DNS settings for specific network interfaces in Ubuntu 20.04?

A: Yes, using methods like Netplan or systemd-resolved, you can configure DNS settings for specific network interfaces on Ubuntu 20.04.

Final Thoughts

Configuring DNS on Ubuntu 20.04 is a fundamental task for network administrators and system administrators alike. Whether you prefer a graphical interface or command-line tools, Ubuntu 20.04 offers multiple options to manage and configure DNS settings. By following the methods and tips outlined in this blog post, you can ensure efficient and reliable DNS resolution and enhance the overall performance and security of your Ubuntu 20.04 system.