How to set DNS servers manually?

Old Geezer picture Old Geezer · Nov 10, 2015 · Viewed 14k times · Source

How do I exclude DNS from the DHCP lease request on a Raspberry Pi?

I tried updating /etc/resolv.conf but it's reset after a while.

Reason: I am on a home network, and the home router uses itself as the DNS server, but the router's DNS service isn't working properly sometimes.

Answer

Tony Allan picture Tony Allan · Oct 31, 2016

Most of the answers didn't work for me, but I found that this worked:

sudo vi /etc/dhcpcd.conf

Added a line (note that there is no comma):

static domain_name_servers=8.8.8.8 8.8.4.4

And unplugged and replugged my ethernet cable, which updates the resolver...

cat /etc/resolv.conf

Now shows:

# Generated by resolvconf
domain example.com
nameserver 8.8.8.8
nameserver 8.8.4.4

This also a better way to fix the problem where changes to /etc/resolv.conf are lost on reboot.