Ubuntu 12.04 - Can't Resolve Hostname

I have a small dedi server on which I have installed Ubuntu 12.04. I access it via x2go since I have a desktop installed.

All worked fine until 2 days ago when, after a reboot, I lost any Internet access and started getting "Can't Resolve Hostname" errors.

If I try to ping google I get:

ping: unknown host google.com

To access some sites I added them to the hosts file and it works for most of them but not all. Of course this is just a temporary solution.

If I look into "System Settings - Network", I get this:

I am not very competent, so I don't know what other info to post but please ask anything you wish me to find out.

Thank you.

16

1 Answer

The problem is purely related to DNS. As there was no DNS nameserver entries in the /etc/resolv.conf file so the name resolution was failing while pinging by hostname to hosts outside your /etc/hosts entries.

In Ubuntu 12.04 the Network Manager package provides the network related functionality (rather than the old networking program), with the resolvconf (and dnsmasq to some extent) program providing the mass DNS functionality. But surprisingly in your case the resolvconf is not installed so we have to manually update the /etc/resolv.conf file.

So by running the command

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

we are basically setting the Google's free DNS server (8.8.8.8) as the nameserver.

This command will insert the text "nameserver 8.8.8.8" into the "/etc/resolv.conf" file and display the text on the screen too. In this way we have a working name resolver that will resolve the hostnames we give into IP addresses.

One very important thing to note here, we are using google's DNS which is not ideal, you should use your ISP's DNS here. Ask your ISP to give you their DNS address (can be multiple) and add the address as the nameserver. Although you can keep the Google's DNS as the backup in case your ISP's one fails for some reason. Let's assume that your ISP's DNS is vv.xx.yy.zz , so you need to run the following commands to make it as the primary DNS and keeping the Google's DNS as a backup.

echo "nameserver vv.xx.yy.zz" | sudo tee /etc/resolv.conf && echo -e "nameserver 8.8.8.8" "\nnameserver 8.8.4.4" | sudo tee -a /etc/resolv.conf

See the -a switch in tee command, that is used to append rather than overwrite. Here 8.8.4.4 is also Google's DNS.

You can add as many nameservers as you want in /etc/resolv.conf but that would be overkill. Just keep it simple yet compact.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like