How to change DNS on Linux
Temporarily change DNS on Linux
- Edit the file
/etc/resolv.conf
with your favourite text editor:
vim /etc/resolv.conf
- Add the following lines to the file:
# Generated by NetworkManager
# Google Primary DNS
+ nameserver 8.8.8.8
# Cloudflare Primary DNS
+ nameserver 1.1.1.1
Permanently change DNS on linux
- Become root:
sudo -i
- Edit
/etc/NetworkManager/system-connections/<connection_name>
with your favourite text editor:
vim /etc/NetworkManager/system-connections/<connection_name>
- Add (change) the following line under the
[ipv4]
section:
[connection]
id=Wired connection 1
uuid=a9d84673-638a-3f89-b487-3fd64d0c7673
type=ethernet
autoconnect-priority=-999
interface-name=enp34s0
timestamp=1714051582
[ethernet]
[ipv4]
+ dns=8.8.8.8;1.1.1.2;
ignore-auto-dns=true
method=auto
[ipv6]
addr-gen-mode=default
method=auto
[proxy]
-
Save and exit
-
Exit root:
exit
- Restart the network manager:
systemctl restart NetworkManager