In this quick tutorial we will cove the right way to change the Raspberry Pi DNS settings so you can change your DNS server to Google DNS, OpenDNS, or even the DNS server from your ISP.

DNS or Domain Name Service is the service which your Raspberry Pi (and all internet connected devices) convert the name of a host (or website) into an IP address that your network can contact.  We’ll go over the very simple process of changing these settings to something that better suits your needs.  Many people wish to switch away from their ISPs DNS for privacy reasons or performance gains.  Many Internet Service Provider DNS servers are not only very slow, but these ISPs also capture and sell this data to other companies for marketing purposes! Sneaky bastards!

Parts list for this project:

You’ll of course need a Raspberry Pi and accessories for this project, here’s a simple list to get started.

Changing the DNS Servers on a Raspberry Pi

Before starting this project it is highly recommended that you update Raspbian to the latest version of the operating system.  Almost every problem reported to us is fixed by doing this first.  To update your Raspberry Pi do the following:

sudo apt update
sudo apt upgrade

Be careful of instructions floating around the web telling you to modify the /etc/resolv.conf file! This will not work on Raspbian will not change raspberry pi DNS settings!  Raspbian uses a newer method of controlling DNS settings, as part of the /etc/dhcpcd.conf file. If you make changes directly to resolv.conf they will be overwritten at various times and on reboot.

Run the following command to edit dhcpcd.conf:

sudo nano /etc/dhcpcd.conf

Once opened, add one of the following lines to the very end of the file:

For Google DNS Servers:

static domain_name_servers=8.8.4.4 8.8.8.8

For Open DNS Servers:

static domain_name_servers=208.67.222.222 208.67.220.220

For Cloudflare’s DNS Servers:

static domain_name_servers=1.1.1.1 1.0.0.1

For your ISP, change the IP addresses to your own ISPs servers.  For your router, your address will be something like 192.168.0.1, or 192.168.1.1 in most cases.

After making these changes its time to save the /etc/dhcpcd.conf file.  In Nano, we save files by pressing CTRL + O. Then press CTRL + X to exit Nano.  Now restart the the Raspbian dhcpd service to cause Raspbian to start using these new DNS server settings.

sudo service dhcpcd restart

That’s all it takes to change raspberry pi DNS settings!  But before you go, let’s test them to make sure they work!

Testing the Raspberry Pi DNS Server Changes

If you’re a true geek, you’ll want to do what a geek does and open the hood to see your changes.  Use Nano again to open the /etc/resolv.conf and you’ll see your new DNS servers are now present (assuming you did everything above correctly).

sudo nano /etc/resolv.conf

Of course, the simplest way to see if they worked is to run nslookup.  Type the following command:

nslookup www.thegeekpub.com

You should be greeted with the following message if everything worked as planned (in this example, we used Google DNS):

Server: 8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
www.thegeekpub.com canonical name = thegeekpub.com.
Name: thegeekpub.com
Address: 107.20.215.52

I hope this quick tutorial helped you along the way in setting up and using your Raspberry Pi!  Check out some of our many other 50+ Raspberry Pi projects before you go!