12

Is it possible to get an IP address over DHCP but force a DNS server instead of using the ones from the DHCP?

I should be able to do so with a static IP addresses, but I would like to know how to do it getting an IP address over DHCP. I thought that changing /etc/resolv.conf would be permanent, but it dismisses the changes after a reboot.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Albert Vonpupp
  • 310
  • 1
  • 2
  • 7

5 Answers5

9

The only thing that worked for me was:

Edit /etc/dhcp/dhclient.conf and un-comment the line:

prepend domain-name-servers 208.67.222.222;

Anyway thanks for your for your help!

Albert Vonpupp
  • 310
  • 1
  • 2
  • 7
5

dns-nameservers (and all others dns-xxx directives in /etc/network/interfaces) does not work in raspbian out of the box, since resolvconf is not installed by default.

sudo apt-get install resolvconf solves the issue.

Stefano Terna
  • 51
  • 1
  • 1
3

I fixed this following the steps from cuonglm's answer on Unix & Linux Stack Exchange.

Edit the file /etc/dhcp/dhclient.conf and add

supersede domain-name-servers 8.8.8.8, 8.8.4.4;

Then restart network or run dhclient to make changes.

From man dhclient.conf:

The supersede statement

   supersede [ option declaration ];

   If for some option the client should always  use  a  locally-configured
   value  or  values rather than whatever is supplied by the server, these
   values can be defined in the supersede statement.
Aurora0001
  • 6,308
  • 3
  • 23
  • 38
Apekatten
  • 31
  • 1
1

You can define them with a line in /etc/network/interfaces.

Underneath your interface, add the following line, replacing the x's with the actual IP of the DNS server:

dns-nameservers xxx.xxx.xxx.xxx

nc4pk
  • 1,378
  • 1
  • 13
  • 25
-1

It's an old threat, but for current Raspbian/Debian you have to add at the end of /etc/dhcpcd.conf:

static domain_name_servers=1.1.1.1 8.8.4.4