Sunday 2 March 2008

DNS problems

I personally have had problems in the past with domain name server issues when running Linux. Essentially, a domain name server takes the URL (web address) of the site you're looking for, and translates it into a numerical IP (Internet Protocol) address, which is used to actually get to the website. Your computer has to query the domain name server (normally provided by your Internet Service Provider) to discover the IP address of the URL you've given. Without that, it's stumped.

Normally this works fine in Linux. But, a small number of routers (including my own, a D-Link wireless router), don't seem to play well with Linux. The router has its own IP address and when you request data (ie enter a URL or click on a link) the request will reach the router's IP address and will then be forwarded to the ISP's domain name server. For some reason, that doesn't seem to work with these routers, and they fail to forward the request on to the domain name server.

This can be very frustrating, as it means that many applications will not be able to access the Internet. I found that Firefox and apt-get could not access the Internet, but Konqueror could, so I could browse but I couldn't install anything new. This doesn't always happen - it happened with Ubuntu Edgy and also happens with Ubuntu Gutsy, but wasn't present in Ubuntu Feisty, and it very nearly stopped me from using Kubuntu Gutsy at all.

Fortunately, there's a great service which can help with this. Open DNS is a third-party domain name server you can use instead, and also works better and faster than most ISP's DNS service.

You can configure your router to use Open DNS if you want - just follow this link to get full instructions. Or to just configure your Ubuntu machine, here's full instructions:

First, enter the following in a terminal:
sudo network-admin

Please note, this works on Ubuntu and Xubuntu only. Kubuntu users will need to open KnetworkManager (which normally starts up at outset, and is in the system tray on the bottom right by default - look for a picture of a cable if you're connected via Ethernet, a signal strength meter if you're using Wi-Fi, or an unplugged socket if you're not connected to the Internet), and then click on Manual Configuration to open the configuration screen.

Whichever program you're using, you'll see a tab marked "DNS". Click on that, remove the existing domain name servers, and replace them with the following:

  1. 208.67.222.222 as your preferred DNS (or just first in line)
  2. 208.67.220.220 as your alternate DNS (or just second)

That will set Open DNS as your domain name server, so you can now exit the program. To make sure it sticks though, we're going to have to edit a text file. Enter the following in a terminal:
sudo cp /etc/resolv.conf /etc/resolv.conf.auto

This copies a text file into a new name. Now enter the following:
sudo nano /etc/dhcp3/dhclient.conf

That opens the text file /etc/dhcp3/dhclient.conf. Add the following line to the end of the document:
prepend domain-name-servers 208.67.222.222,208.67.220.220;

Then save and exit the document. You will now also have to switch off IPv6, which is easy:
sudo nano /etc/modprobe.d/aliases

Now look for a line that reads as follows:
alias net-pf-10 ipv6

and edit it to this:
alias net-pf-10 off

Now all you need to do is restart your connection. Enter the following:
sudo ifdown eth0

substituting the name of your connection for eth0. Then:
sudo ifup eth0

That should restart your connection. If not, and you still can't get online, try rebooting.

This method is what I used to get online. Apparently it's not an issue with Linux, but with the router's firmware, and some people have reported success in overcoming this issue simply by updating their router's firmware. In addition, I've found that some Ubuntu-based distros, such as Linux Mint, have already taken care of this issue before release. However, you may wish to use your laptop running Ubuntu in a public place such as a cafe where there is free wi-fi, and under those circumstances you can't expect to be able to update the router, so you may need to do this anyway.

It also goes to show that with wireless routers, you get what you pay for - if you're thinking of getting one, don't just opt for the cheapest. I was confronted with the choice between a Belkin and a D-Link, and I opted to save £10 by going for the D-Link. Two weeks later I read an article in a magazine that had a round-up of wireless routers, and they had both of them in there, and it said the D-Link was terrible and to get the Belkin instead as it had a stronger signal and was a lot more reliable. I'm willing to bet it would probably work better with Linux too!

2 comments:

daniel said...

Thanks, I'm going to try this advice as I've been having trouble with a particular hotspot.

This doesn't sound like it's a "router problem". I mean, why can some applications use the DNS and others not? dig seems to work, firefox does not. I can't get nslookup to work either.

And if this wasn't a problem in feisty at all but is in gutsy, wouldnt' that signal a problem in ubuntu?

MattBD said...

Curiously enough, the same issue was mentioned in the current issue of Linux Format. Apparently it's caused by your browser trying to talk to the modem or router using IPv6. If it doesn't work, it's supposed to fall back to IPv4, but some routers don't do this and get confused when dealing with a client that talks IPv6 and an ISP that doesn't. So basically there are three ways to deal with it:
1) Upgrade the firmware for the router (I need to get round to doing this sometime!)
2) Disable IPv6 at system level (as we have done here)
3) Disable it in the browser only (which still means other applications will be affected by this, such as apt-get)
Konqueror works fine with this, so I suspect that by default it uses IPv4, and I expect the same applies to other apps that work fine. Fortunately, the issue no longer exists in Hardy - although it could potentially recur in future versions. I'm not entirely sure why it only happens with some editions of Ubuntu. I've known it to happen with other distros too, so it's not just Ubuntu.