WindowsMacSoftwareSettingsSecurityProductivityLinuxAndroidPerformanceConfigurationApple All

How to Change DNS Settings on Ubuntu

Edited 3 weeks ago by ExtremeHow Editorial Team

DNSNetworkingUbuntuLinuxConfigurationOperating SystemsInternetSystemDesktopAdministration

How to Change DNS Settings on Ubuntu

This content is available in 7 different language

Changing DNS settings on Ubuntu is an essential skill for those who want to manage their own network settings. DNS stands for Domain Name System, and it's like the phone book of the Internet. It translates human-friendly domain names into machine-readable IP addresses.

By changing DNS settings, you gain more control over how your system interacts with hosts on the Internet. This can improve your browsing speed, security, and reliability because it allows your machine to ask different DNS servers for information instead of the default DNS servers provided by your Internet service provider (ISP).

Understanding DNS and its importance

DNS plays a vital role by converting domain names like www.example.com into IP addresses like 192.168.1.1. This process, known as DNS resolution, is crucial for accessing websites, sending emails, and more.

Imagine if every website was accessed via IP addresses instead of names; this would be cumbersome and impractical for users. DNS simplifies this process by maintaining a distributed database and providing resolving services.

Why change DNS settings?

Why would you need to change DNS settings, you might ask? There are several reasons for this:

Steps to change DNS settings

Let’s explore the methods available to change DNS settings on Ubuntu in simple and understandable terms. We will learn about the various configurations possible in Ubuntu.

1. Using Network Manager (GUI Method)

This method is straightforward and doesn't require much technical knowledge. Ubuntu's Network Manager provides a graphical user interface to easily change network connection settings.

With these steps, you have updated your DNS settings using the graphical interface. If you have more than one network, each network connection may require different configuration.

2. Using the Terminal (Command Line Method)

If you’re comfortable using the terminal, you can change DNS settings through the command line, which is sometimes quicker and offers more control.

Modify /etc/resolv.conf

The file /etc/resolv.conf usually contains DNS configurations. However, in many modern systems, it is managed by a system service and may come back after a reboot. To edit it temporarily, you can use:

$ sudo nano /etc/resolv.conf
$ sudo nano /etc/resolv.conf

Once the file is open, add or modify the lines to change the DNS entries:

nameserver 8.8.8.8 nameserver 8.8.4.4
nameserver 8.8.8.8 nameserver 8.8.4.4

Save the file and exit the editor. Remember, changes made directly to /etc/resolv.conf are often temporary.

Use resolvectl (for systems with systemd-resolv)

Many Ubuntu systems use systemd-resolved; therefore, the command to manage DNS settings is resolvectl.

$ sudo resolvectl dns <YOUR_INTERFACE_NAME> 8.8.8.8 8.8.4.4 $ sudo resolvectl domain <YOUR_INTERFACE_NAME> example.com
$ sudo resolvectl dns <YOUR_INTERFACE_NAME> 8.8.8.8 8.8.4.4 $ sudo resolvectl domain <YOUR_INTERFACE_NAME> example.com

Replace <YOUR_INTERFACE_NAME> with your network interface, such as wlan0 for wireless or eth0 for a wired connection.

3. Persistent changes in DNS across reboots

For permanent DNS settings, you should configure your network manager or netplan (for systems using it) configuration.

Netplan method

On Ubuntu with Netplan, you can define permanent DNS settings by editing YAML configuration files located in /etc/netplan/.

Edit the appropriate YAML file:

$ sudo nano /etc/netplan/01-netcfg.yaml
$ sudo nano /etc/netplan/01-netcfg.yaml

Within the file, add or modify the following structure:

network: version: 2 ethernets: eth0: dhcp4: yes nameservers: addresses: [8.8.8.8, 8.8.4.4]
network: version: 2 ethernets: eth0: dhcp4: yes nameservers: addresses: [8.8.8.8, 8.8.4.4]

Save and exit. Apply the changes with the following:

$ sudo netplan apply
$ sudo netplan apply

Troubleshooting DNS issues

Sometimes, despite changing the DNS settings, you may face issues like DNS cache not getting cleared or settings not getting applied. Here are some general tips you can try for troubleshooting:

Conclusion

By following these methods, you can effectively manage DNS settings on Ubuntu, either through the graphical interface or direct command-line methods. Knowing this not only gives you better control over your networking setup but also provides a better browsing experience by having reliable, fast, and secure DNS servers.

Always remember to properly test DNS changes by accessing a website or running various network checks. This ensures that your DNS configurations are applied correctly and are improving your system's networking capabilities as expected.

If you find anything wrong with the article content, you can


Comments