Ubuntu 12.04 - Can't Resolve Hostname

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.