How to change DNS on Linux

1 min read

Temporarily change DNS on Linux

  1. Edit the file /etc/resolv.conf with your favourite text editor:
vim /etc/resolv.conf
  1. Add the following lines to the file:
resolv.conf
# Generated by NetworkManager
# Google Primary DNS
nameserver 8.8.8.8
# Cloudflare Primary DNS
nameserver 1.1.1.1

Permanently change DNS on linux

  1. Become root:
sudo -i
  1. Edit /etc/NetworkManager/system-connections/<connection_name> with your favourite text editor:
vim /etc/NetworkManager/system-connections/<connection_name>
  1. Add (change) the following line under the [ipv4] section:
Wired Connection 1
[connection]
id=Wired connection 1
uuid=aaaaaaaa-bbbb-cccc-1111-222222222222
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]
  1. Save and exit

  2. Exit root:

exit
  1. Restart the network manager:
systemctl restart NetworkManager

References: