Skip to content

Linux Change DNS

作者:Lee 等
最后更新:

Confirm DNS management program

Run cat /etc/resolv.conf and check the file output for comments like # Generated by resolvconf or # Generated by systemd-resolved .

Directly modify resolv.conf

Suitable for cases where DNS is not taken over or when you want to temporarily modify it even if it is.

Open etc/resolv.conf and modify the nameserver parameter, for example:

text
nameserver 1.1.1.1
nameserver 1.0.0.1
nameserver 2606:4700:4700::1111
nameserver 2606:4700:4700::1001

Modify via systemd-resolved

Open etc/systemd/resolved.conf and edit the DNS= parameter, for example:

text
DNS= 1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001

Run sudo systemctl restart systemd-resolved.service to restart the DNS service.

Modify via resolvconf

Open the resolvconf configuration file.

bash
nano /etc/resolvconf/resolv.conf.d/head

Edit the configuration.

text
nameserver 8.8.8.8
nameserver 8.8.4.4

Regenerate resolv.conf

bash
sudo resolvconf -u

Run the following command to verify the DNS configuration

bash
cat /etc/resolv.conf

页面历史