Ubuntu – DNS Not Working

dnsnetworkingserver

I have setup an Ubuntu server with a static IP and I cannot get the DNS to work. Pinging any domain (such as google.com) will not redirect me. I have tried editing /etc/resolv.conf, but that didn't work and it just keeps getting overwritten.

I also tried adding the dns-nameservers x.x.x.x x.x.x.x line to /etc/network/interfaces. I tried this using both my ISP's DNS (obtained it from my Windows desktop with ipconfig) and Google's (8.8.8.8 8.8.4.4), but it still won't work.

Best Answer

A work around to solve this is to temporarily add the domains you need to the /etc/hosts file.

That provided enough connectivity to sudo aptitude to resolve the broken dependencies on the system.

After the upgrade, Ubuntu rebooted normally and I could remove the static IPs from the hosts file again.

I used the following to capture the domains I needed to update and put them into a text file: sudo apt-get update >> domains.txt

I used the following to grab the IPs I needed:

sh domain-nslookup.sh >> apt-domains.txt

The following is the sh file I created and saved as domain-nslookup.sh:

#!/bin/sh
for DOM in `cat ./apt-domains.txt`;
do
    nslookup $DOM 8.8.8.8 |gawk -F": " '/Address/{print $2}'
    printf "\t%-4s" $DOM
done
printf "\n"

After verifying that it worked as planned, I added the IPs and domains to the hosts file:

sudo sh domain-nslookup.sh >> hosts
Related Question