ping 8.8.8.8 works but ping www.google.com doesn't
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.
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.
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