Unable to resolve host address linux

Error message «sudo: unable to resolve host (none)»

When I run sudo the terminal is stuck for a few seconds and then outputs an error message. My terminal looks like this:

ubuntu@(none):~$ sudo true sudo: unable to resolve host (none) 

I recommend against closing this question as too localized. There are many users who may mistakenly think they’ve put one name in their hosts file but put in a different name instead, especially since on many networks, computers are similarly named. This question (and answer) would show up when someone searches with that problem, and the answer would prompt them to check for such discrepancies, even though the exact misspelling would be different.

make sure your hostname same with hosts . e.g. the hostname is ubuntu-pc and hosts is ubuntu-pc must be same.

I ran into this today. The problem was that what I had in hostname wasn’t in /etc/hosts. To wit: $ hostname => ‘mybox’ $ grep ‘mybox’ /etc/hosts => 192.168.1.2 mybox.example.com. I needed to add ‘mybox’ after my domain name in /etc/hosts => 192.168.1.2 mybox.example.com mybox

I can’t post an answer because this question is protected and I don’t have enough reputation here. In my case, I solved the problem by restarting network-manager: sudo /etc/init.d/network-manager restart . However, I’m wondering why in the first place sudo wastes time waiting for network-related stuff. Shouldn’t sudo work without problems when network is not available?

20 Answers 20

Two things to check (assuming your machine is called my-machine , you can change this as appropriate):

  1. That the /etc/hostname file contains just the name of the machine.
  2. That /etc/hosts has an entry for localhost . It should have something like:
127.0.0.1 localhost.localdomain localhost 127.0.1.1 my-machine

If either of these files aren’t correct (since you can’t sudo), you may have to reboot the machine into recovery mode and make the modifications, then reboot to your usual environment.

The hostname will not change until you reboot. If you wish to change it without rebooting the machine then follow the above steps and after that run:- «sudo hostname my-machine» to see if this has worked run «sudo hostname» It will show your machine’s host name. This method maybe used as a temporary method to change hostname also. after a restart, the value from the /etc/hostname file is used.

Note: since you can’t sudo to begin with, it is difficult to edit those files. My solution was I was somehow able to sudo visudo and change #%admin ALL=(ALL) ALL to %admin ALL=NOPASSWD: ALL , then reboot, and sudo su -, edit those files, set/correct hostname, reboot again, and everything worked.

I’m using Linux Subsystem in Windows and I faced this problem. After following your answer, It has been resolved.

you may also need to add ::1 localhost to /etc/hosts (this is the IPv6 version of 127.0.0.1, aka the loopback address)

Edit /etc/hosts and append your new hostname to the 127.0.0.1 line (or create a new line if you prefer that).

127.0.0.1 localhost localhost.localdomain penguin # 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 

Replace penguin in the above example by your new hostname as stated in the /etc/hostname file.

How can he edit the /etc/hosts file if he can’t sudo? Unless he created a rood account with a password (bad idea)

@Dennis You can still execute sudo even if that message is displayed. IIRC you still have to enter your password at each invocation though. If this does not work, you can reboot into the recovery console and apply the changes. A root account with password is discouraged.

as a debian user, there is no gksudo or gksu, i had to resort to using sed: step 1. run touch myscript step 2. edit «myscript» (you can do this without sudo most of the time) and insert sed -i ‘s/127.0.0.1 localhost/127.0.0.1 localhost NEWHOSTHERE/’ /etc/hosts step 3. sudo bash myscript . Please note the tabs are there on purpose because it searches for 127.0.0.1 localhost to be replaced with 127.0.0.1 localhost NEWHOSTHERE .

Add your hostname to /etc/hosts like so:

echo $(hostname -I | cut -d\ -f1) $(hostname) | sudo tee -a /etc/hosts 

This does an append of the hostname to the hosts file. There is an inherent assumption that there is nothing in between the loopback ip the mapping to localhost and end of file, but there is now some IPv6 stuff between this line and end of file, in which case this solution does not really end up giving you what you would want. A related comment: Editing this or other files requires use of sudo and it is sudo that we are trying to fix. We still need to be able to run sudo. In this case sudo -h hostname can be used to first change permissions on the files or gain the elevation to edit them.

this fails because I can’t «sudo tee..» but this did the trick: echo $(hostname -I | cut -d\ -f1) $(hostname) | sudo -h 127.0.0.1 tee -a /etc/hosts

Note, this is an answer to this question which has been merged with this one.

Your hostname ( dave00-G31M-ES2L ) is not represented in /etc/hosts . Add an L to this line:

In order to accomplish this, open a console (press Ctrl + Alt + T ) and type:

Add the letter L as mentioned, save and exit.

Remember! Use sudoedit (or sudo -e ). To specify preferred editor, use the EDITOR environment variable (eg. export EDITOR=vim ) as it creates an offline copy for editing and then cleanly overwrites after editing.

And there is another one here who suggest sudo when there is no longer sudo . sudo doesn’t work, sir. sudo: unable to resolve host .

@Green: No sudo ? The error message you mention comes from the sudo command. Perhaps you meant something different?

@Green sudo works just fine. It just can’t store any state (i.e. as Lekensteyn said elsewhere you have to enter your password every time).

If you have this issue on W10’s Bash and came to this question from google, this is the answer that worked for me. I changed the 127.0.0.1 to look like «127.0.0.1 localhost DESKTOP-SLQK4CV» (by doing «sudo vim /etc/hosts» (quick tip for vim newbies: press i before typing to switch to insert mode, press esc to exit that, write «:wq» to save and exit or «:q!» to exit without saving), in my case sudo worked but just said that it can’t connect to DESKTOP-SLQK4CV) and it started worked for me.

I had this issue when I was using ubuntu on a VPS. I solved it editing /etc/hosts file.

127.0.0.1 localhost.localdomain localhost 127.0.1.1 ubuntu 

I hope that will solve your issue 🙂

PS: Remember to reboot your computer!

Also, see if your device name (printed on the Terminal title bar after the @ sign) matches the name on the second line of the hosts file («ubuntu» in Luca’s example). The first line may also be just «localhost».

Remember! Use sudoedit (or sudo -e ). To specify preferred editor, use the EDITOR environment variable (eg. export EDITOR=vim ) as it creates an offline copy for editing and then cleanly overwrites after editing.

I was having the same issue even though the hostname in my /etc/hostname file and /etc/hosts file matched.

My hostname was «staging_1». It turns out that you can’t have an underscore in your hostname, which is why I was getting this error. Changing the underscore to a hyphen fixed my problem.

In AWS, go to your vpc and turn on «DNS Hostnames».

Welcome to askubuntu! Can you expand a bit on this? It’s not abundantly clear what you mean (at least to me)..

This was the answer that helped me. Amazon AWS changed since the last time I looked at it. VPCs have DNS options, and they need to be turned on before any DNS resolution will work.

Similar issue occurred on Azure for me when I changed the default DNS servers in the VNet. I fixed it by adding my current hostname to the hosts file using sudo —host 127.0.0.1 vi /etc/hosts , as suggested in other answers.

The symptom given in the question may correlate strongly with this more specific problem:

$ hostname --fqdn hostname: Temporary failure in name resolution 

There are different ways that this could be resolved, one of which is to add your hostname as localhost in /etc/hosts (as shown in several other answers). This may be the right thing to do in general, but it isn’t the only possible resolution.

A «fully qualified domain name» may be supplied by an external DNS server or similar (if such is available on your network). In this case, sudo will not complain, despite the missing entry in /etc/hosts .

Note: sudo attempts to dereference the hostname, even though it isn’t necessarily required, due to optional capabilities in the sudoers file. See sudo command trying to search for hostname.

As long as the delay isn’t too long, this error message is typically harmless.

Источник

wget: unable to resolve host address `http’

I have encountered this problem earlier when I got it for any web pages (and not http), which required me to add my nameserver to /etc/resolv.conf . However, here that doesn’t seem to be the problem, instead it is recognizing http as something different. Any advise?

you won’t be able to wget anything then. You have an issue with your nameserver configuration. As @WhiteCoffee suggests below, add in the google public DNS servers and try to ping then. If that works, wget should work.

You cannot use ping for some proxies. Nor can you use a DNS lookup from the client in question. Some corporate networks do not allow external resolution. The proxy server must handle that. I suspect in @techEnthusiast’s case, the proxy is required to handle the DNS.

6 Answers 6

The DNS server seems out of order. You can use another DNS server such as 8.8.8.8. Put nameserver 8.8.8.8 to the first line of /etc/resolv.conf .

@Mouin 8.8.8.8 is the Google public DNS which is a common used server, if you are looking for a open/democratic one have a look at: opennicproject.org

remove the http or https from wget https:github.com/facebook/facebook-php-sdk/archive/master.zip . this worked fine for me.

I have this issue too. I suspect there is an issue with DigitalOcean’s nameservers, so this will likely affect a lot of other people too. Here’s what I’ve done to temporarily get around it — but someone else might be able to advise on a better long-term fix:

  1. Make sure your DNS Resolver config file is writable: sudo chmod o+r /etc/resolv.conf
  2. Temporarily change your DNS to use Google’s nameservers instead of DigitalOcean’s: sudo nano /etc/resolv.conf

Change the IP address in the file to: 8.8.8.8

Press CTRL + X to save the file.

This is only a temporary fix as this file is automatically written/updated by the server, however, I’ve not yet worked out what writes to it so that I can update it permanently.

Источник

Читайте также:  Информация о процессоре линукс
Оцените статью
Adblock
detector