DNS Not Working

62

Solution 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

Solution 2

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
Share:
62

Related videos on Youtube

Learner_seeker
Author by

Learner_seeker

Updated on September 18, 2022

Comments

  • Learner_seeker
    Learner_seeker over 1 year

    i have a very sparse data set - below is a example of the format. I want to make changes to specific columns based on the logic explained below

    # create dummy data set
    pb=c('1','0','0','0','0','1','Not_ans','1','0','Not_ans')
    qa=c('1','1','0','0','1','0','Not_ans','1','Not_ans','Not_ans')
    #zy=c('1','Not_ans','0','1','Not_ans','0','1','1','1','Not_ans')
    
    #sub questions for pb
    pb.abr=c('1','0','0','0','0','1','0','1','0','0')
    pb.ras=c('0','0','0','0','1','0','0','1','0','0')
    pb.sfg=c('1','0','0','0','0','0','0','1','0','0')
    
    #sub questions for qa
    qa.fgs=c('1','0','0','0','0','0','0','1','0','0')
    qa.sdf=c('0','1','0','0','0','0','0','0','0','0')
    qa.tyu=c('0','0','0','0','1','0','0','1','0','0')
    
    df=data.frame(pb,qa,pb.abr,pb.ras,pb.sfg,qa.fgs,qa.sdf,qa.tyu)
    df
    
            pb      qa pb.abr pb.ras pb.sfg qa.fgs qa.sdf qa.tyu
    1        1       1      1      0      1      1      0      0
    2        0       1      0      0      0      0      1      0
    3        0       0      0      0      0      0      0      0
    4        0       0      0      0      0      0      0      0
    5        0       1      0      1      0      0      0      1
    6        1       0      1      0      0      0      0      0
    7  Not_ans Not_ans      0      0      0      0      0      0
    8        1       1      1      1      1      1      0      1
    9        0 Not_ans      0      0      0      0      0      0
    10 Not_ans Not_ans      0      0      0      0      0      0
    

    The two columns pb and qa are called base columns, and they have further sub columns for with naming convention as pb. and qa. - so we see three sub columns for pa and 3 for qa. I want to make changes to these sub columns based on a condition to the base column ( pa or qa) .

    Condition is if column pb =='Not_ans' then make all sub columns (pb.abr,pb.ras and pb.sfg) = 'Not_applicable'

    how do i write a function which achieves this? where i specify the base column name i.e. pb and naming of sub columns example 'pb.' below - would it be something like below but it wont give the result

    data.frame(ifelse(df['base_q']=='Not_ans',
    df[ , grepl( paste('base_q','.') , names(df) )]=='Not_applicable',df[,grepl( 
    paste('base_q','.') , names(df)) ])
    

    How do i write a generic function which takes the base column numbers as inputs for example 1,2 here - applies the function i.e whereever pb is Not_ans it changes sub_columns ( pb.abr,pb.ras,pb.sfg) to Not applicable and then moves to column 2 ( qa) and applies the same logic?

  • tsmith18256
    tsmith18256 over 9 years
    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
  • Alex Austin
    Alex Austin over 9 years
    can you paste the content of your resolv.conf?
  • chili555
    chili555 over 9 years
    According to the man page, the preferred format is: dns-nameservers 8.8.8.8 8.8.4.4
  • Anders
    Anders over 9 years
    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.
  • guntbert
    guntbert over 9 years
    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.
  • Jakuje
    Jakuje over 8 years
    example would not hurt, isn't it?
  • jfl
    jfl over 8 years
    edited with example and steps.
  • Learner_seeker
    Learner_seeker about 5 years
    Hi above solution works - but then do i use an lapply to apply it of the number of columns. Like in above data frame - i show two base columns but in my orignal data frame i have 100s of base question columns and 1000+s sub question columns. Naming convention follows as ('baseQ+".") but not for all. Would it make sense to have the function instead with input - base question column numbers & naming logic of sub questions
  • Learner_seeker
    Learner_seeker about 5 years
    again, do i use lapply to apply it over a multiple number of base q columns?
  • jazzurro
    jazzurro about 5 years
    @Pb89 You do not have to use lapply(). Basically, you are applying if_else() to all columns that begins with "pb.".
  • Learner_seeker
    Learner_seeker about 5 years
    No I meant with this I would have to run the code for pb and then again for qa. How do I apply this mutate to both column 1,2 which end up changing the sub cols of pb and qa
  • jazzurro
    jazzurro about 5 years
    Then, you can run mutate one more time. In the 2nd time, you change column names. So it would be something like mutate_at(vars(contains("qa.")), .funs = funs(ifelse(qa == "Not_ans", "Not_applicable",.)))
  • Learner_seeker
    Learner_seeker about 5 years
    Like I mentioned if it was 2 columns, would have done that. But I have 100s of columns like pb and qa. And can't apply it one by one to all
  • BENY
    BENY about 5 years
    @Pb89 if you know your base columns you can just apply it just need to modify the function with for loop in it
  • jazzurro
    jazzurro about 5 years
    @Pb89 It would be great if you would have mentioned such a detail in your original question.
  • Learner_seeker
    Learner_seeker about 5 years
    Sorry if I wasn't clear but the last paragraph of the original questions does say a function with column numbers as inputs and applies the logic to all.
  • John Baber-Lucero
    John Baber-Lucero almost 4 years
    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!