How to change DNS on Linux
1 min read
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 DNSnameserver 8.8.8.8
# Cloudflare Primary DNSnameserver 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 1uuid=aaaaaaaa-bbbb-cccc-1111-222222222222type=ethernetautoconnect-priority=-999interface-name=enp34s0timestamp=1714051582
[ethernet]
[ipv4]dns=8.8.8.8;1.1.1.2;ignore-auto-dns=truemethod=auto
[ipv6]addr-gen-mode=defaultmethod=auto
[proxy]
-
Save and exit
-
Exit root:
exit
- Restart the network manager:
systemctl restart NetworkManager
References: