8

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.

  • 1
    Shouldn't that file contain a line »DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN« ? – FUZxxl Mar 1 '13 at 15:21
  • not in raspbian... – Albert Vonpupp Mar 2 '13 at 15:14
  • Not in stock debian either -- learned my lesson lol. – Sirens Oct 31 '17 at 3:43
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!

4

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.

2

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.
  • Raspbian version? – Fabian Apr 21 '18 at 13:34
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

  • Thanks for your answer. It didn't work for me, it keeps getting the DNS server from the DHCP. The one I used on the /etc/network/interfaces file was in second place. – Albert Vonpupp Mar 3 '13 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.