18

Recently, I tried to run the command, sudo apt-get update and got the Temporary failure in name resolution error. But, after that the command proceeded and went on to update. Should I worried about the error. Below is the complete log:

sudo apt-get update
sudo: unable to resolve host {hostname}: Temporary failure in name resolution
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease                                                                                                                                                 
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]                                                                                                                                
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]                                                                                                                                 
Fetched 6,581 kB in 6s (1,180 kB/s)                                       
Reading package lists... Done

muru
  • 197,895
  • 55
  • 485
  • 740
User04
  • 181
  • 2
  • i guess your dns server is not properly setup. cat /etc/resolv.conf should point to a dns nameserver like your route / gateway. As alternative you can try one from google: type in as root (without sudo) echo nameserver 8.8.8.8 >> /etc/resolv.conf a second hint might be a wrong default route ip route should list a default route via your router / gateway ip. If not you can create such a route with sudo ip route add default via <routerip> – AlexOnLinux Jun 04 '21 at 08:27
  • Why does "sudo" need to do any name resolution anyway? – SomeoneElse Sep 24 '22 at 11:55

5 Answers5

27

It seems likely that your computer's hostname is not configured correctly. There are two files you should check; /etc/hostname contains just your computer's name, and /etc/hosts will have a line that maps the IP address 127.0.1.1 to your hostname. For example, those files might look like:

username@ubuntu ~ $ cat /etc/hostname
ubuntu

username@ubuntu ~ $ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 ubuntu

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters

If you don't have those, try adding them -- keep in mind that a hostname should only consist of letters, numbers, and hyphens -- then reboot and see if you have that error again.

Minneyar
  • 744
  • 2
    This is actually a perfect answer but I didn't understand the first time. This is the critical line: 127.0.1.1 ubuntu. Because ubuntu is so generic I didn't spot the connection to /etc/hostname. For example my /etc/hostname/ gives bo. So I needed 127.0.1.1 bo. This was also useful: https://en.wikipedia.org/wiki/Hosts_%28file%29#File_content – icc97 Oct 15 '22 at 09:34
  • this is solve my problem. note: dot too can be in name. – Ali Bagheri Jan 04 '23 at 06:21
4

I have a similar issue. I was trying to renew SSL certificate using: sudo certbot renew I kept on getting the error: Temporary failure in name resolution. “An unexpected error occurred” while issuing certificate bla bla bla. The error means there is a missing, wrongly configured or inactive resolve.conf file.

The fix is simple, you need to restart:

$ sudo systemctl restart systemd-resolved.service

Then check the status of the file with:

$ sudo systemctl status systemd-resolved.service

Then run the renew SSL command

sudo certbot renew

This resolved my issue

  • This is a great answer for situations where the hosts file looks okay. Just need to remove the dot in the of the first command: sudo systemctl restart systemd-resolved.service – Nirmal Feb 28 '23 at 04:04
1

I fixed it with:

hostnamectl set-hostname hostname.newdomain.local
cocomac
  • 3,394
0

I faced this issue in recent times. Please try to edit your /etc/hosts file by using any editor just as vi or nano after that you will see this line 127.0.0.1 localhost 127.0.1.1 ubuntu remove the line 127.0.1.1 ubuntu and edit it as 127.0.0.1 yourdomain

It is solved my issue; I hope it is also work for you.

anonymous2
  • 4,298
0

I ran into this error when I configured the hostname to include an underscore character (_). This is an invalid hostname, so it was never resolvable in the hosts file. Here's some information on creating a valid hostname:

A hostname can contain a maximum of 255 characters, including the dots. The text string in a hostname must be from ASCII characters. It includes the upper or lower case (A to Z or a to z), digits (0 to 9), the dot symbol (.), and the hyphen symbol (-).