16

I am getting the following error from ubuntu 20.04 terminal, connected via wired ethernet connection: When I type the following command which I am using in a bash script:

ping -c 1 google.com

for a health check to ensure it has access, I get the following error:

ping: google.com: Temporary failure in name resolution

Some background

I overwrote my older gaming rig to be a ubuntu multi purpose server (including smart home automation) in my home network. It used to be windows 10, but I formatted the drive and installed ubuntu on it.

I have not yet been able to access the internet with ubuntu, however, I do know that the equipment works because I left the internet wired in, I actually downloaded ubuntu via that machine onto the usb before installing.

Now I cannot see or connect to the ubuntu server from other devices and cannot reach the internet to download even basic tools like netstat.

At this point, I feel like I've bashed my head against a wall and scoured the internet (and lots of other stack overflow threads) and tried a bunch of things that didn't work.

Any help would be greatly appreciated!

Edit: As requested in comments, I am attaching a screenshot, since I am not able access the computer via any network. Only via hdmi.

enter image description here

Edit 2: Second screenshot as requested.

enter image description here

Zedd
  • 317

4 Answers4

27

It's likely your default DNS server is pointing to an IP address that is not capable of resolving DNS queries. You should check the DNS settings in the file that /etc/resolv.conf is pointing to. When you go to that file (/var/run/systemd/resolve/resolve.conf), look at the IP that is right next to the keyword namespace. You should set it to your router's IP address (which can be found with the command route -n. Look for the gateway column and take the one that's not 0.0.0.0) or you can also set it to a public DNS server such as 1.1.1.1, 8.8.8.8 etc.

EDIT: Please follow these instructions:

Execute sudo rm /etc/resolv.conf

Execute sudo touch /etc/resolv.conf

Edit the file with sudo nano /etc/resolv.conf

Add this line to the file: nameserver 1.1.1.1

Press ctrl + s to save and ctrl + x to exit

Restart the service:

sudo systemctl restart systemd-resolved.service

Then try to access the internet again. If it still doesn't work, reboot the system and try again. That should solve your problem.

Lucas
  • 109
  • 3
  • 2
    "cat: /var/run/systemd/resolve/resolve.conf: No such file or directory" – chili555 Aug 16 '21 at 01:41
  • impossible to do what you are asking since the commands you are asking me to execute are not installed and i have no internet access. – Zedd Aug 16 '21 at 15:32
  • 1
    route and nano are basic commands that are in every linux distributions. I guess I understand the problem now. If you're getting this error "cat: /var/run/systemd/resolve/resolve.conf: No such file or directory", then it means you dont have any DNS server configured for your OS at all. The file that is supposed to contain DNS settings is not even present. We can fix this if you follow my instructions. I'll include them in my answer in just a little bit since I have character limitation here. Check out the answer please. – Muhammed Özen Aug 16 '21 at 15:52
  • 1
    I just saw your answer. I didnt know you'd solved the problem. Awsome work. But the problem was you didnt have and DNS config file. If you run into any problem like that again, you can try the steps I explained above – Muhammed Özen Aug 16 '21 at 16:11
  • 1
    Thank you so much Muahammed! yeah it was weird, it didn't even have ifconfig installed, let alone route lol

    And I can't take credit for the awesome work, it was all @chili555

    – Zedd Aug 16 '21 at 18:19
  • 2
    You're welcome Zedd. Wow that must have been tough. I'm glad you solved it. Then thanks are for @chili555 – Muhammed Özen Aug 16 '21 at 18:31
  • Good temporary fix to update packages in an emergency, but it gets overwritten by the system eventually. But definitely a quick fix to get updates and packages installed to resolve the issue. – Stephen Punwasi Oct 31 '21 at 21:16
  • I had same issue, I followed your steps, each step worked except when I tried to restart the service. It gave an error message. Then I restarted the OS and boom, everything started working. I also shutdown the OS running on my VMware station before the OS restart – chized Mar 13 '23 at 20:21
  • 1
    Do not do this. It is by design that /etc/resolv.conf always points the user to systemd-resolved running locally. If systemd-resolved has the wrong DNS servers configured, then you should address that by modifying the configuration of systemd-resolved via /etc/systemd/resolved.conf. – slangasek Apr 11 '23 at 20:13
  • I suggest to just restart the service as a first check. This solved the problem for me: sudo systemctl restart systemd-resolved.service – Nir Apr 22 '24 at 07:53
  • this address is correct: /var/run/systemd/resolve/resolv.conf – Sam Aghamohammdi Apr 22 '24 at 14:58
9

This is what helped in my case:

Ubuntu is now using systemd-resolve, which is controlled by resolvectl.

I found that no nameservers were configured:

$ resolvectl dns
Global:
Link 2 (enp1s0):
Link 3 (wlp2s0):

So I added one:

$ resolvectl dns wlp2s0 8.8.8.8 8.8.4.4 1.1.1.1

and now DNS lookup works!

$ nslookup example.com
Server:     127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer: Name: example.com Address: 93.184.215.14 Name: example.com Address: 2606:2800:21f:cb07:6820:80da:af6b:8b2c

kolypto
  • 721
2

Firstly, I have to give a shout out to @chili555 for spending literally hours last night helping me troubleshoot.

After many hours of troubleshooting, the simplest answer was the solution. Something must have gone wrong during installation, because after a reinstall from the same usb flash drive, my computer is on the network and accessing the internet.

I still don't know the true cause, but my server is up and running.

Thanks @chili555!

Zedd
  • 317
1

Adding to the discussion here, I had a similar issue with my Xubutu 22.10 + gnome today.

In the past, recreating resolv.conf had helped me for a similar issue, but today it did not.

Ultimately I realised that I had a VPN client (windscribe) installed that I had switched off recently. As soon as I used the .Deb file to uninstall the package, my internet came back.

I'm leaving this resolution here for others who might have a similar issue.