How to modify DNS in Ubuntu

Ubuntu often has a lot of bugs, such as graphics card drivers, software package dependencies, DNS and other issues. Today I will focus on how to solve DNS problems.

1. What is Ubuntu DNS problem?

When using Ubuntu, the following errors often occur:

ping: XXX.com: 域名解析失败

This is because Ubuntu's default DNS occasionally has bugs.

If you go to "Settings" to change the DNS, you will find that Ubuntu still uses the original DNS, and restarting is useless.

Therefore, we have to use more advanced means to modify DNS.

Many tutorials on the Internet are useless. After a series of explorations, I figured out how to modify DNS in Ubuntu.

2. Temporarily modify DNS

This method can temporarily modify the DNS, but it will take effect after restarting.

1. Edit the /etc/resolv.conf file

sudo gedit /etc/resolv.conf

2. Add the following code

nameserver 114.114.114.114
nameserver 8.8.8.8

That's it. 114.114.114.114 and 8.8.8.8 can be replaced with your favorite DNS.

Once the modification is completed, save it and it will take effect immediately.

3. Permanently modify DNS

Notice that there is this line at the top of /etc/resolv.conf:

DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

Note that this file will be automatically overwritten after restarting.

So how to prevent it from being overwritten? Just turn off the service covering it.

1. Disable systemd-resolved service

sudo systemctl disable --now systemd-resolved

2. Modify the NetworkManager file:

sudo gedit /etc/NetworkManager/NetworkManager.conf

3. [main] Add the following configuration under the node:

dns=none

4. In fact, resolv.conf is not a file, but a soft link. After disabling systemd-resolved, the soft link will take effect, so we need to create a resolv.conf file ourselves.

cd /etc
sudo mv resolv.conf resolv.conf.bak
sudo touch resolv.conf

5. Modify according to the temporary modification method

6. Restart

reboot

In this case, the file will not be overwritten even if it is restarted.

Then, Ubuntu’s DNS BUG was fixed!

Reference: Ubuntu 20.04 Modify DNS

Guess you like

Origin blog.csdn.net/nnKevi/article/details/131555234