How to Change DNS Server Settings in Ubuntu Server 22

This blog post will guide you through the process of changing the DNS server settings on your Ubuntu Server 22. By changing your DNS servers, you can improve the security, privacy, and speed of your internet connection. We’ll cover how to modify the Netplan configuration file and verify the changes.

Changing DNS Server Settings using Netplan

  1. Open the terminal or log in to the server using SSH.
  2. List the available Netplan configuration files:
ls /etc/netplan
  1. Identify the configuration file for your network interface. It usually has a .yaml extension, for example, 00-installer-config.yaml.
  2. Open the configuration file with a text editor (such as nano) using sudo:
sudo nano /etc/netplan/00-installer-config.yaml
  1. Edit the file to include the DNS servers you want to use. If you’re using DHCP for IP address assignment, add the following lines under the correct network interface (ethernet or wifi), replacing 1.1.1.1 and 1.0.0.1 with the desired DNS server addresses:
dhcp4: true
dhcp6: true
nameservers:
  addresses: [1.1.1.1, 1.0.0.1]

If you’re using static IP address configuration, add the DNS server addresses to the existing configuration like this:

addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
nameservers:
  addresses: [1.1.1.1, 1.0.0.1]
  1. Save and exit the file (for nano, press Ctrl + X, then Y, and finally, Enter).
  2. Apply the new Netplan configuration:
sudo netplan apply
  1. Verify the new DNS settings by checking the contents of the resolv.conf file:
cat /etc/resolv.conf

Your new DNS servers should be listed in the output.

Checking the Current DNS Servers

To check which DNS servers your system is currently using, you can run the resolvectl status command. This command provides detailed information about the DNS settings for each network interface.

Follow these steps to check the current DNS servers:

  1. Open a terminal or log in to the server using SSH.
  2. Run the following command:
resolvectl status
  1. The output will show the current DNS servers being used by your system for each network interface. Look for the “Current DNS Server” and “DNS Servers” fields under the desired network interface (e.g., enp3s0).

Conclusion

In this blog post, we’ve shown you how to change the DNS server settings in Ubuntu Server 22 by modifying the Netplan configuration file. By following these steps, you can customize your DNS servers to improve the security, privacy, and speed of your internet connection. Don’t forget to verify the changes to ensure your system is using the desired DNS servers.

Leave a comment

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