Thursday, August 13, 2009

Tweaking dhcp client configuration to change the default DNS servers to Open DNS

The DNS servers of my ISP is always behaving erratically. The DNS look up times are abysmally large and some times I get an address not found error while browsing. On ubuntu/debian systems the DNS servers are specified in /etc/resolv.conf. I tried to edit /etc/resolv.conf and put open dns servers as default DNS servers. But, my ISP supplies their DNS server address along with IP address for the system via DHCP. Every time my system renews its DHCP lease. my /etc/resolv.conf is also rewritten with their DNS address.

My /etc/resolv.conf ( supplied by ISP) looks like this.

$ cat /etc/resolv.conf
domain asianetindia.com
search asianetindia.com
nameserver 202.88.238.3
nameserver 202.88.238.5
nameserver 202.88.231.2

There is a trick I used to make Open DNS servers as my default DNS server.

Edit /etc/dhcp3/dhclient.conf and look for the line.
#prepend domain-name-servers 127.0.0.1;
Add the following line immediately below the above line.

prepend domain-name-servers 208.67.222.222;
prepend domain-name-servers 208.67.220.220;


You can also put any other DNS servers.

Now renew the lease with

$ sudo dhclient eth0

The new /etc/resolve.conf looks like this.
$ cat /etc/resolv.conf
domain asianetindia.com
search asianetindia.com
nameserver 208.67.220.220
nameserver 208.67.222.222
nameserver 202.88.238.3
nameserver 202.88.238.5
nameserver 202.88.231.2

DNS look up is made from open dns.

5 comments:

Anonymous said...

Try out OpenNIC: http://www.opennicproject.org/

rstanley said...

I also run debian, and I would recommend installing djbdns and run a dns resolver on your own system, as I have done.

I would then edit /etc/dhcp3/dhclient.conf, remove the comment from the existing localhost line, then add the two additional lines for OpneDNS, so that portion of the file looks like:

prepend domain-name-servers 127.0.0.1;
prepend domain-name-servers 208.67.222.222;
prepend domain-name-servers 208.67.220.220;

Reset the dns resolver list, or reboot the computer, then you will first use djbdns, as a first choice, OpenDNS as the secondary choice, and then your ISP's own dns resolvers last. Most of the time, you will only use the djbdns on your own system.

Sean said...

If it's a typical Debian installation, the automated edits on /etc/resolv.conf would be performed by software in the 'resolvconf' package. So, as an alternative to editing /etc/dhcp3/dhclient.conf you could also edit /etc/resolvconf/resolv.conf.d/head towards a similar result

I hadn't heard about OpenDNS, previously - someone in #linpeople on Freenode IRC had mentioned your blog entry, here.

My ISP, out here in Missouri, isn't necessarily so impressive, as far as their level of real (as contrasted to: Imaginary and not so real) technical aptitude. Their routing infrastructure doesn't seem to cope, well, with network load - e.g. during the typical load period on Sunday evenings, after everyone's home from the weekend - and their DNS servers may be what's making the browsing experience appear to be a good deal slower, here, for all the latency that gets added in while the browser/proxy waits the last DNS response. I'll have to take a look at OpenDNS, too - maybe it'll help to effectively speed things up, over here.

PS: OpenNIC, which another reader commented about, it isn't a resource about DNS caching. It is an alternate root servers network, in the nature of the thing. Substantively, it's orthogonal to DNS caching ^-^

Unknown said...

try setting your /etc/resolv.conf file the way you want
(i.e.
domain asianetindia.com
search asianetindia.com
nameserver 202.88.238.3
nameserver 202.88.238.5
nameserver 202.88.231.2
) and then typing

chattr +i /etc/resolv.conf

then see what happens - the file is now set so not even root can edit it.

use chattr -i /etc/resolv.conf when you want to edit it and then edit as usual

Anonymous said...

From a comment above:

"If it's a typical Debian installation, the automated edits on /etc/resolv.conf would be performed by software in the 'resolvconf' package. So, as an alternative to editing /etc/dhcp3/dhclient.conf you could also edit /etc/resolvconf/resolv.conf.d/head towards a similar result"

To be precise, this solution works if you use the base file rather than the head file which gets overwritten. That's how it works on the Debian platform, at least.