2

I'm trying to configure Debian as a router/gateway on my network with eth0 going to my ISP's modem and eth1 to my LAN.

eth0 needs DHCP so that it gets the proper IP address from my ISP modem, but in using DHCP, I'm also getting my ISP's DNS servers thrown into the /etc/resolv.conf file. I would like to override the ISP provided DHCP servers with OpenDNS servers, but am not having much success. The documentation I found for Debian networking suggests setting the dns-nameservers option like so:

/etc/network/interfaces

iface eth0 inet dhcp
    dns-nameservers 208.67.222.222 208.67.220.220

But the /etc/resolv.conf continues to populate with the ISP nameservers. If I edit /etc/resolv.conf and set openDNS servers in the file it is periodically wiped out, presumably by the DHCP lease refreshing itself.

How do I get the OpenDNS nameservers to stick?

2
  • you could always make a copy of resolv.conf and copy it back to /etc after ifup completes at boot if you like, but the very best recommendation is just get a router. that way you can control your own DHCP assignments and configuration. xmodulo.com/2013/02/… Oct 2, 2013 at 15:59
  • I already tried the stash and copy back approach, but the /etc/resolv.conf is getting refreshed every so often and I'm not entirely sure which system service is actually updating the resolv.conf file -- as I mentioned, my best guess is the dhcp client is refreshing when it checks the lease on the ip address. Oct 2, 2013 at 16:06

1 Answer 1

4

Probably the most correct way to do what you want is to break open your dhclient.conf and include the appropriate supersede option, which will tell dhclient - the program actually making the DHCP request and performing the requested operations, ignore what it receives from the server and use what's in the configuration file instead. Something like:

interface "eth0" {
 supersede domain-name-servers 208.67.222.222, 208.67.220.220;
 }

I'd then make a comment in your /etc/network/interfaces that you did this just in case you change it in the future and are looking for why it won't change from OpenDNS.

The way I ended up doing it was taking advantage of the fact that dhclient executes hook scripts, and you can actually override the function performing the IP address assignment and tell it to just simply return. But the above is simpler and more correct.

3
  • That worked. I didn't think that was the place to add because the comments in the file said the config was part of debian's dhcp3-client package and I was thinking the dnsmasq package was providing all my dhcp services. Anyway, one typo in your example above is adding a comma between the ip addresses -- once corrected and network restarted, has DNS resolution working as intended now. Oct 2, 2013 at 16:43
  • Good to hear. I've corrected.
    – LawrenceC
    Oct 2, 2013 at 16:45
  • if you have both /etc/dhcp/dhclient.conf and /etc/dhcp3/dhclient.conf edit the last one. Nov 8, 2013 at 10:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .