ping 8.8.8.8 works but ping www.google.com doesn't
Solution 1
You need a Name Server in your /etc/resolv.conf
file. Edit your /etc/resolv.conf
and add a working Name Server. Google provides a free one, 8.8.8.8
.
Do this:
$ nano /etc/resolv.conf
Place this as the first non-commented line:
nameserver 8.8.8.8
You can verify this functionality with:
$ ping -c10 www.google.com
You can make this change permanent by adding the line to this file your /etc/resolvconf/resolv.conf.d/head
file.
Solution 2
The marked answer actually doesn't work on Ubuntu 18.04.01. To fix this issue, here's what I did:
- Execute
sudo gedit /usr/lib/systemd/resolv.conf
- Paste
nameserver 8.8.8.8
(and/or any other nameserver(s) you want), then save and exit. - Add a symlink by executing
sudo ln -sf /usr/lib/systemd/resolv.conf /etc/resolv.conf
Credits to https://askubuntu.com/a/1050280/899241
Solution 3
Could you post a link to the page that told you that file resolv.conf should be empty? My guess is that it is misleading at best.
Edit that file with command sudo nano /etc/resolv.conf
and put there a single line:
nameserver 8.8.8.8
That should fix your name resolution and the various programs that use it - ping, apt-get, etc.
You also ought to investigate why resolv.conf is empty. Perhaps your DHCP server isn't configured properly.
Related videos on Youtube
Gary Mercer
Updated on September 18, 2022Comments
-
Gary Mercer over 1 year
I'm running ubuntu server 16.04.2 and
apt-get update
returns temporary failure resolving "everything on the list".- When I ping www.google.com, it responds with unknown host.
- When I ping with 8.8.8.8, I get packets sent with no errors etc.
I have tried every "fix" I can find in Ubuntu forums and all over the rest of the internet world and nothing works. The
resolv.conf
is empty, ifconfig shows nic is functioning, firewall is off, and I threw away the hammer just in case. Unfortunately, I am typing this on another computer on the same network but can't attach text from the various outputs to show whats going on. Need help on this please.The resolv.conf file contains these lines:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN search 8.8.8.8 8.8.4.4
The last line is placed their by the interfaces file when you reboot the system. This is new for 16.04LTS. I'm thinking Windows NT4 wasn't so bad and neither was Ubuntu Server 12.
-
Terrance about 7 yearsHow is your system getting it's IP address? Is it coming from a DHCP server? It is a static IP? Being able to ping the IP address will work without a DNS server IP setup. But it sounds like you don't have a DNS address setup or your DHCP is not supplying it.
-
Gary Mercer about 7 yearsIP is static. I never setup the DNS server when I installed the server software.
-
Terrance about 7 yearsLook at askubuntu.com/questions/143819/… and add your DNS entry for like the Google DNS Servers at 8.8.8.8 and 8.8.4.4
-
Gary Mercer about 7 yearsI did all that. My static ip is coming from at&t vdsl box. Im using their dns name-servers and dns-search ip's. Only thing I can deduce is that at&t is blocking the dns querys.
-
Terrance about 7 yearsInteresting. Maybe you might want to contact AT&T and see if they are blocking it in anyway. I guess you could try replacing their DNS servers with the Google DNS servers and see if that works.
-
Gary Mercer about 7 yearsNo joy. I had commented out the dns namesserver and dns serach lines to see if that changed anything. It didn't.
-
Kaz Wolfe about 7 yearsWhat happens if you run
sudo systemctl restart network-manager.service
? Does your internet start working again? -
Gary Mercer about 7 yearsnetwork-manager.service not found.
-
wjandrea about 7 yearsDid you already restart your router?
-
Gary Mercer about 7 yearsWore out the power cord restarting it. This has got to be a problem with either AT&T, the lack of a DNS server on this server, the installation of the whole thing is broken or Ubuntu server 16.04 just doesn't like my hardware. I'm almost out of hair and have relocated my Windows NT4 install discs.
-
Gary Mercer about 7 yearsThis is what the file contains: # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN search 8.8.8.8 8.8.4.4 The last line is placed their by the interfaces file when you reboot the system.
-
wjandrea about 7 years@GaryMercer please add that to your question. It's difficult to read in a comment.
-
Gary Mercer about 7 yearsNo network-manager. Its a server with no gui. I did get dnsutils installed before it quit connecting to the repositories.
-
Gary Mercer about 7 yearsWhoopie! Success! excuse me, 36 straight hours banging on this box... It worked. I even put in the at&t ip's and it worked. Thanks to all you guys for your help and quickness. (Mr. Moderator, these guys needed a pat on the back so ease up on the whole emotionless junk)
-
Gerhard Stein about 7 years@Gary Mercer: how do you bring the network interface then? (ifup and ifdown?) The Network Managers GUI is an optional component.
nmtui
is the text-based of that one. -
Gary Mercer about 7 yearsI bring the nic up by rebooting the system. Since its a server, it never gets turned "off." I have found that using restart services doesn't always work because of the other inter-related components that make up all the services that use the interface. Its just easier and most efficient to restart all the services with a simple reboot command.
-
Gerhard Stein about 7 yearsBy rebooting your system something "a manager" has to bring your devices. In which did you configure the static IP Addresses?
-
Pablo Bianchi over 5 yearsIf is using netplan and Google DNS servers would be
addresses: [8.8.8.8,8.8.4.4]
(maybe better use Cloudflare's 1.1.1.1) on/etc/netplan/50-cloud-init.yaml
and thensudo netplan --debug apply
. -
Syam kumar KK almost 5 yearsresolv.conf is not giving permission to edit
-
Gwang-Jin Kim over 4 yearsin contrast to @Ragy Morkos' answer, it worked for me also in ubuntu 18.04 LTS
-
Gwang-Jin Kim over 4 yearsThanks a lot! I couldn't ping www.google.com after chroot-ing into my ubuntu. Thanks to your solution, now I can do installations etc in the chroot-ed partition.
-
Puspam over 3 yearsThanks a lot for this solution!! How do you people manage to solve these?
-
vineeshvs about 3 yearscreated an empty file with the suggested contents. It worked.