Raspberry Pi: DNS Server Settings

The DNS servers in Raspberry Pi are listed in /etc/resolv.conf file.

If you want to change the Raspberry Pi’s DNS server settings you shouldn’t update this file manually, because all changes will be overwritten after reboot by data that your local DHCP server provides.

In this note i will show how to change DNS servers in Raspberry Pi and make the settings permanent.

Cool Tip: Free fast public DNS servers! Read more →

Raspberry Pi DNS Server Settings

Open the /etc/dhcpcd.conf file:

$ sudo nano /etc/dhcpcd.conf

At the bottom of the file, uncomment the following line and set the IP addresses of the required DNS servers, for example:

static domain_name_servers=8.8.8.8 8.8.4.4

Save the changes and restart the dhcpcd service:

$ sudo systemctl restart dhcpcd

Check the DNS server settings:

$ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 8.8.8.8
nameserver 8.8.4.4

To ensure additionally that the new DNS server settings are in place, you can install dnsutils and execute the nslookup command:

$ sudo apt update
$ sudo apt install dnsutils
$ nslookup www.shellhacks.com
Server:		8.8.8.8
Address:	8.8.8.8#53

Non-authoritative answer:
Name:	www.shellhacks.com
Address: 195.201.82.106
Name:	www.shellhacks.com
Address: 2a01:4f8:13b:3f55::2

Cool Tip: Mount USB drives in Raspberry Pi automatically! Read more →

Was it useful? Share this post with the world!

One Reply to “Raspberry Pi: DNS Server Settings”

  1. The above doesn’t work if your WIFI is set to static as everyone’s should be it gets reset on reboot.

    Had to change
    etc/NetworkManager/system-connections/
    And edit my wifi settings to change the DNS.
    This static WIFI dns setting overrides your above settings. Ive been fooling with this for days all the online blogs like yours were wrong.

Leave a Reply