43

I want my Raspberry Pi to use OpenDNS to resolve domain names. How can I modify this setting?

Josiah Sprague
  • 844
  • 2
  • 9
  • 17
  • what OS are you using? There are multiple OSs for the Raspberry Pi – Keltari Oct 24 '16 at 01:46
  • 2
    Note for future users finding this answer via Google etc: Editing `/etc/resolv.conf` isn't really the right way going about this anymore: You need to edit `/etc/dhcpcd.conf` instead. See my answer below. – starbeamrainbowlabs Apr 03 '19 at 14:51

6 Answers6

50

I've found that in the latest version of Raspbian (stretch I think?) you now need to edit the last line of /etc/dhcpcd.conf. There should be a line that starts with static domain_name_servers= - there you can customise it with a list of space-separated DNS servers, like this:

static domain_name_servers=1.1.1.1 1.0.0.1 208.69.38.205 8.8.8.8

DNS Servers Featured: Cloudflare, OpenDNS, and Google

Edit: As @DavidOliver points out, you may need to restart dhcpcd too: sudo systemctl restart dhcpcd.service.

starbeamrainbowlabs
  • 1,230
  • 4
  • 18
  • 29
  • 4
    This was the only solution that worked for me. I am using raspbian for the raspberry pi – Tono Nam May 24 '18 at 15:37
  • 1
    This one was the one that worked for me on Raspbian - From the other answers in this question, edits directory to resolv.conf got overwritten on reboot and the network/interfaces edits were ignored – dlrust Oct 29 '18 at 23:24
  • 1
    This should be the correct answer for latest (Raspbian Stretch or Debian Stretch), the accepted answer in 2013 and the higher vote so far of modifying `etc/resolv.conf` are simply no longer correct. – hcheung Apr 03 '19 at 06:06
  • 2
    Seemed like a restart of the service was necessary: `sudo systemctl restart dhcpcd.service` – David Oliver Aug 07 '19 at 21:47
  • This worked for me, what a hot mess, why are there 3 ways to change the dns names in raspbian alone? – TZubiri Mar 16 '20 at 08:50
  • 1
    @TomasZubiri It's actually changed quite a bit over the years. The method Described in my answer is most up-to-date version. Answers that suggest to edit `/etc/resolv.conf` are outdated because that file is now automatically populated with the current DNS resolution settings, and is auto-updated by NetworkManager/systemd/whatever. – starbeamrainbowlabs Mar 16 '20 at 15:24
31

Don't edit /etc/resolv.conf since that file is generated automatically. Instead edit /etc/network/interfaces and add the following to the end:

dns-nameservers 8.8.4.4 8.8.8.8
Justin
  • 531
  • 1
  • 5
  • 7
  • 5
    resolv.conf is just overwritten by the resolvconf tool. If this tool is not installed the first answer will work. But your solution will work anyway, that's why it should be marked as the right solution. – Ben Dec 07 '16 at 18:18
  • this worked for me on raspian stretch lite, thanks! – james-see Sep 13 '17 at 01:28
  • didn't work. startbeamrainbowlabs' solution worked! – lode Aug 13 '19 at 22:16
17

If you are using Debian on Raspberry Pi, then you need to edit /etc/resolv.conf

nano /etc/resolv.conf

then add the server IP of the openDNS

nameserver  208.67.222.222
nameserver 208.67.220.220

Btw, if you have any concern about speed of the DNS you may want to take a look at this post

Angs
  • 914
  • 3
  • 13
  • 32
  • I did this, but it's still not using OpenDNS. – Josiah Sprague Jul 10 '13 at 05:53
  • 4
    you restarted your board and are using Debian-server, right? If it is the case, please try to add `nameserver 208.67.220.220``and `nameserver 208.67.222.222` to `/etc/network/interfaces`then restart your board or do `/etc/init.d/networking restart`. If it is still not working, please paste output of `dig google.com` – Angs Jul 10 '13 at 06:07
  • Should the IPs be in both `/etc/resolv.conf` and `/etc/network/interfaces`? – Josiah Sprague Jul 10 '13 at 15:36
  • 1
    The /etc/resolv.conf entry is created from the /etc/network/interfaces config. Note: this works only if you're using static network configuration. If you're using dynamic settings, then you'll need to change the settings provided by the DHCP server. – joat Jul 13 '13 at 13:58
  • I just wanted to mention that today out of the blue, my Pi3 device couldn't see mirrordetector.raspbian.org. I added the OpenDNS addresses and it works fine. (I had Google's in there...) – kodybrown Jan 14 '17 at 21:33
6

I have found the answer from another website and this is the best. I used the very last part of the article as Raspbian comes with dchpcd already installed and i still want an automatic ip address not a static ip address. Running from a Raspberry Pi3 multiboot [berryboot] with Raspbian - Pixel type

sudo nano /etc/resolv.conf.head

in your terminal. You will have a blank slate to work with. Next copy and paste the following code:

#OpenDns Servers
nameserver 208.67.222.222
nameserver 208.67.220.220

click on cntrl + x to exit out and select y for the following options to save. restart your Raspberry Pi with

sudo reboot

To make sure you are using OpenDNS go to the following website: OpenDns welcome page

Robert Petet
  • 61
  • 1
  • 2
  • Could you add a link to the original forum source you found this answer on? – music2myear Apr 18 '17 at 19:36
  • I have found the exact link [old article from 2013 but works!] I have updated my answer to reflect the link – Robert Petet Apr 18 '17 at 20:07
  • Sweet. Context almost always makes a question better. – music2myear Apr 18 '17 at 20:11
  • I hope this has helped you. By the way the bootloader i use for my Raspberry PI3 is berryboot [http://www.berryterminal.com/doku.php/berryboot] and i love it! I have Raspbian-Pixel, Kali Linux2.0, OSMC, and RetroPie v3.6 running on a 16GB sd card without having to change sd cards. You can get the images for berryboot here: [http://berryboot.alexgoldcheidt.com/images/] In fact I'm using Raspbian and chromium to answer you. – Robert Petet Apr 18 '17 at 20:19
  • This worked for me. I really don't understand why setting up networks is becoming more and more complex and intransparent over time.... THanks for your help! – Tarator May 04 '17 at 06:17
  • This worked for me...in a kind of surprising (reverse) way. The file /etc/resolv.conf.head was *not* empty in my case; instead, it referred to three unwanted DNS server addresses (including 127.0.0.1, where no DNS server is running...). No clue where this came from. In any case, all I had to do was to delete these three unwanted lines, restart dhcpcd (sudo systemctl restart dhcpcd.service) and everything was fine again (with the correct DNS server address received via DHCP). – Klaws Mar 05 '22 at 19:03
-2

The openDNS servers worked for me thanks. During a Udemy learning session I had run into a problem after ditching my wifi sharing arrangement with my Mac, and setting up ethernet hub with the PI on a different home network. The problem with my previous IP sharing arrangement with WiFi.

When I originally setup the PI with the sharing arrangement the text Inside the resolve file was:​

nameserver 192.168.2.1 

which was entered automatically by the minibian OS, NOT ME!

This IP became the default DNS server, with the MacMini seamlessly providing the real DNS in the background. ​

SO NEED TO EDIT(vim) WITH

nameserver  208.67.222.222
nameserver 208.67.220.220       

​Then I could ping google.com Thank goodness for forums!

SDsolar
  • 1,578
  • 3
  • 18
  • 30
  • 1
    What does this do and how will it help? Read over ["Why do I need 50 reputation to comment"](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead) to ensure you understand how you can start commenting. – Vomit IT - Chunky Mess Style Sep 04 '17 at 02:27
  • The instructions here are incomplete. Which file needs editing? Where is it located? Are there any other steps one must complete before your solution solves the issue, and how can one verify the issue is solved? – starbeamrainbowlabs Feb 04 '21 at 15:51
-3

Add this line into file /etc/dhcp/dhclient.conf:

option domain-name-servers 192.168.1.8, 8.8.8.8, 8.8.4.4

Then it will work.

user
  • 29,449
  • 11
  • 99
  • 144
Larand
  • 1
  • 1