Tuesday, May 21, 2013

HOWTO override DHCP resolv.conf nameserver setting on Debian Wheezy running Network Manager

Why run a DNS server on your laptop?

  • It is easy.
  • You are getting jerked around
    1. DNS built into the wireless access point is slow or broken
    2. Your ISP is evil and hijacks DNS

Evil is the big issue. DNS (Domain Name Service) translates names. for example, "howto.omacneil.org" should be IP# 173.194.76.121 . An evil DNS server might send it to 208.67.217.136 instead and show you a page of ads.

Assumptions

  • You are running Debian Wheezy (not tested with Ubuntu)
  • You use a dynamic (DHCP) address
  • You use Network Manager

If you are using a static IP address on one interface you can edit /etc/network/interfaces and set " dns-nameservers 127.0.0.1" for the interface in question.

With DHCP (via Network Manager), your computer connects to the network, sends a broadcast asking for an IP address. The DHCP (dynamc host configuration protocal ) server replies with an IP address, default gateway, nameserver(s) and other network information.

Your goal to over-ride nameserver that your ISP sends you via DHCP

These steps should work on Debian Etch/Squeeze/Wheezy , but I've tested them only on Wheezey


     # Install the DNS server
     sudo apt-get install bind9

     # install the package that lets you tell Network Manager 
     # what nameservers to use
     sudo apt-get install resolvconf

Add these lines to /etc/resolvconf/resolv.conf.d/head


  #    edit /etc/resolvconf/resolv.conf.d/* as appropriate

  # google's no cost , non-evil , free DNS server
  nameserver 8.8.8.8

  # copy of bind running locally the cache 
  # probably isn't as big as google's
  nameserver 127.0.0.1
 

Ignore the comment that tells you not to edit the file. The purpose is to tell you not to edit the generated /etc/resolv.conf file

If things don't work

  • Revert to your backed-up copy of /etc/resolvconf/resolv.conf.d/head
  • Consider DNSmasq

Other possibilities

Use the Network Manager GUI to edit each individual connection, one-at-a-time-tediously

  1. Right click the icon
  2. Edit Conections
  3. Wireless
  4. Double click <your connection name>
  5. IPv4 settings
  6. Change "Automatic (DHCP)" to "Automatic (DHCP) address only"
  7. set DNS Servers to: '8.8.8.8 127.0.0.1'
  8. Save

Thanks

Thanks to Thomas Hood for writing the resolvconf package