3

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.

2 Answers 2

3

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
3
  • 1
    example would not hurt, isn't it?
    – Jakuje
    Dec 8, 2015 at 20:26
  • edited with example and steps.
    – jfl
    Dec 10, 2015 at 8:38
  • The script didn't quite work for me, but this is a good reminder that while I'm solving my DNS problem, setting up /etc/hosts with what apt wants makes things a lot easier. Thanks! Jun 25, 2020 at 1:44
1

before anything test that you can actually resolve without configuration setup.

Try the following:

#nslookup
>server 8.8.8.8
>google.com

if that works make sure that your resolv.conf file contains the following:

nameserver 8.8.8.8

It might be that NetworkManager is running also, and that overrides manual changes

5
  • So this just worked perfectly, thank you very much. Any chance you can explain why this worked, but when I put the following in resolv.conf it failed? nameserver 8.8.8.8 nameserver 8.8.4.4 Nov 20, 2014 at 19:00
  • can you paste the content of your resolv.conf? Nov 20, 2014 at 19:45
  • According to the man page, the preferred format is: dns-nameservers 8.8.8.8 8.8.4.4
    – chili555
    Nov 20, 2014 at 21:31
  • I like the command getent hosts www.google.com. The command getent uses the systems way of looking up names. nslookup or ` dig` uses only the DNS system. Also look up the manual page for resolvconf. That is what is using the dns-nameserves directive in /e/n/interfaces and other DNS sources to manipulate /e/resolve.conf. So if the package resolveconf is installed, never change the contents of /e/resolv.conf manually. Use the command.
    – Anders
    Nov 21, 2014 at 2:36
  • 1
    careful! replacing the content of /etc/resolv.conf (which is a symlink actually) will break the package resolvconv. So don't recommend that without further inquirements.
    – guntbert
    Nov 23, 2014 at 17:14

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.