Error message “sudo: unable to resolve host (none)”












673














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)


What can I do to solve it?










share|improve this question




















  • 2




    Please post the contents of /etc/hostname and /etc/hosts.
    – arrange
    Aug 31 '11 at 20:24






  • 44




    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.
    – Eliah Kagan
    Aug 18 '12 at 11:09








  • 7




    make sure your hostname same with hosts. e.g. the hostname is ubuntu-pc and hosts is ubuntu-pc must be same.
    – Muhammad Sholihin
    Apr 1 '13 at 8:17






  • 1




    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
    – Jim
    Mar 25 '17 at 21:16








  • 2




    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?
    – bli
    Jul 31 '17 at 8:45
















673














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)


What can I do to solve it?










share|improve this question




















  • 2




    Please post the contents of /etc/hostname and /etc/hosts.
    – arrange
    Aug 31 '11 at 20:24






  • 44




    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.
    – Eliah Kagan
    Aug 18 '12 at 11:09








  • 7




    make sure your hostname same with hosts. e.g. the hostname is ubuntu-pc and hosts is ubuntu-pc must be same.
    – Muhammad Sholihin
    Apr 1 '13 at 8:17






  • 1




    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
    – Jim
    Mar 25 '17 at 21:16








  • 2




    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?
    – bli
    Jul 31 '17 at 8:45














673












673








673


174





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)


What can I do to solve it?










share|improve this question















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)


What can I do to solve it?







sudo error-handling






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 16 '18 at 8:47

























asked Aug 31 '11 at 19:09









Kit Sunde

4,02671829




4,02671829








  • 2




    Please post the contents of /etc/hostname and /etc/hosts.
    – arrange
    Aug 31 '11 at 20:24






  • 44




    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.
    – Eliah Kagan
    Aug 18 '12 at 11:09








  • 7




    make sure your hostname same with hosts. e.g. the hostname is ubuntu-pc and hosts is ubuntu-pc must be same.
    – Muhammad Sholihin
    Apr 1 '13 at 8:17






  • 1




    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
    – Jim
    Mar 25 '17 at 21:16








  • 2




    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?
    – bli
    Jul 31 '17 at 8:45














  • 2




    Please post the contents of /etc/hostname and /etc/hosts.
    – arrange
    Aug 31 '11 at 20:24






  • 44




    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.
    – Eliah Kagan
    Aug 18 '12 at 11:09








  • 7




    make sure your hostname same with hosts. e.g. the hostname is ubuntu-pc and hosts is ubuntu-pc must be same.
    – Muhammad Sholihin
    Apr 1 '13 at 8:17






  • 1




    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
    – Jim
    Mar 25 '17 at 21:16








  • 2




    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?
    – bli
    Jul 31 '17 at 8:45








2




2




Please post the contents of /etc/hostname and /etc/hosts.
– arrange
Aug 31 '11 at 20:24




Please post the contents of /etc/hostname and /etc/hosts.
– arrange
Aug 31 '11 at 20:24




44




44




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.
– Eliah Kagan
Aug 18 '12 at 11:09






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.
– Eliah Kagan
Aug 18 '12 at 11:09






7




7




make sure your hostname same with hosts. e.g. the hostname is ubuntu-pc and hosts is ubuntu-pc must be same.
– Muhammad Sholihin
Apr 1 '13 at 8:17




make sure your hostname same with hosts. e.g. the hostname is ubuntu-pc and hosts is ubuntu-pc must be same.
– Muhammad Sholihin
Apr 1 '13 at 8:17




1




1




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
– Jim
Mar 25 '17 at 21:16






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
– Jim
Mar 25 '17 at 21:16






2




2




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?
– bli
Jul 31 '17 at 8:45




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?
– bli
Jul 31 '17 at 8:45










19 Answers
19






active

oldest

votes


















918














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.






share|improve this answer



















  • 29




    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.
    – Yashvit
    May 5 '13 at 15:22








  • 2




    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.
    – Ian M
    Jul 17 '16 at 20:19






  • 4




    I'm using Linux Subsystem in Windows and I faced this problem. After following your answer, It has been resolved.
    – amarVashishth
    Dec 28 '16 at 15:43






  • 2




    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)
    – Woodrow Barlow
    Sep 27 '17 at 14:51








  • 9




    Why does your example have 127.0.0.1 localhost but 127.0.1.1 my-machine?
    – Adam
    Dec 21 '17 at 23:11



















182














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



Mine looks like:



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.






share|improve this answer



















  • 2




    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
    Mar 29 '15 at 22:31






  • 7




    @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.
    – Lekensteyn
    Mar 29 '15 at 23:31



















57














Add your hostname to /etc/hosts like so:



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





share|improve this answer

















  • 9




    This was a brilliant answer that didnt get enough credit
    – Edziu Eames
    Oct 17 '16 at 1:55










  • Nice one! Agreed it doesn't get enough rep love. :-)
    – Peter K.
    Oct 13 '17 at 12:39










  • It's clever, but I don't think it tends to be a good idea to automate something like this.
    – mwfearnley
    Jan 4 '18 at 13:59










  • 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.
    – shivesh suman
    Sep 21 '18 at 21:05










  • this one saved my ass
    – hoffmanc
    Sep 27 '18 at 23:05



















30














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:



127.0.1.1   dave00-G31M-ES2


So it becomes:



127.0.1.1   dave00-G31M-ES2L


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



sudo gedit /etc/hosts


Add the letter L as mentioned, save and exit.






share|improve this answer



















  • 10




    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.
    – Jan
    Sep 26 '14 at 13:54






  • 2




    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
    Jul 12 '16 at 20:18










  • @Green: No sudo? The error message you mention comes from the sudo command. Perhaps you meant something different?
    – Thor
    Jul 14 '16 at 13:49










  • @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).
    – Wlerin
    Jul 28 '16 at 19:16








  • 4




    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.
    – Ave
    Aug 5 '16 at 2:13





















16














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



run this command:



sudo nano /etc/hosts


and then add:



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!






share|improve this answer

















  • 1




    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".
    – Waldir Leoncio
    Oct 26 '13 at 14:33






  • 2




    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.
    – Jan
    Sep 26 '14 at 13:55



















10














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.






share|improve this answer





























    10














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






    share|improve this answer

















    • 2




      Welcome to askubuntu! Can you expand a bit on this? It's not abundantly clear what you mean (at least to me)..
      – Elder Geek
      Jan 15 '15 at 13:56










    • This may not be relevant to the question, but it greatly helped me. Thank you!
      – clayzermk1
      Apr 10 '15 at 17:35






    • 1




      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.
      – Chris Moore
      Jul 1 '15 at 1:16










    • the Enable DNS Hostnames option can be found (for example) in the right-click menu of the vpc entry
      – Matteo Scotuzzi
      Jan 3 '16 at 17:32










    • There is no DNS Hostnames
      – Green
      Jul 12 '16 at 20:11



















    5














    I encountered this same error message. I think this discussion thread at AWS Developer Forums is a better solution:



    "Go the the VPC management console, select the VPC, click on Actions, select Edit DNS Hostnames and select Yes."



    https://forums.aws.amazon.com/thread.jspa?messageID=699718






    share|improve this answer





























      5














      Some terminal emulators will not update prompt with the correct hostname until you close and restart the emulator (lxterminal, I'm talking to you).



      I spent 30min fighting with this error after editing my hostname and hosts files and running sudo service hostname restart until I ran sudo hostname and saw that the hostname was the new value, even though the prompt was showning the old value.






      share|improve this answer

















      • 1




        The issue isn't the terminal emulators, it's the shells that have cached the value.
        – Mark Stosberg
        Feb 16 '17 at 19:53



















      4














      In my case it was the problem, I changed the hostname to man because I wanted to know if there are some parameters you can use on hostname. Instead it changed my hostname to man and I always got the same message like you



      sudo: unable to resolve host (none)


      after changing the hostname back to `localhost everything worked fine again



      hostname localhost





      share|improve this answer





























        3














        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.






        share|improve this answer































          2














          Sorry I can't help you much but, since it says "can't resolve host" try running:



          hostname


          And see if the output is the hostname of the machine. If not, the problem is the host configuration, not sudo.






          share|improve this answer





















          • I did that got the hostname of my machine. I also have entry in /etc/hosts. I'm still getting the error.
            – chandresh
            May 6 '17 at 13:22










          • Did you reboot the machine after changing the hosts file?
            – animaletdesequia
            May 7 '17 at 18:52










          • No. Though my IT team said there was issue with lock file as well as gpg key with puppetlabs. Now, it got resolved without restart..
            – chandresh
            May 8 '17 at 9:28





















          2














          OP wrote:




          It was all in /etc/hostname. On two of our sick servers it looked like
          this:



          ubuntu@(none):~$ cat /etc/hostname
          linux-web-n ip-10-128-##-##


          While on a server without this issue we had:



          ubuntu@ip-10-128-##-###:~$ cat /etc/hostname
          ip-10-128-##-###


          Removed the linux-web-n portion, rebooted and everything was fine.







          share|improve this answer































            2














            you might be getting an error if your hosts or hostname file contain illegal characters. Only these symbols are permitted: a-z, A-Z, 0-9






            share|improve this answer





























              2














              I had this same problem! I changed my VPS's name through the online admin control panel which did not change the machine name in the hosts file All I did was run:



              sudo nano /etc/hosts


              Then I edited it from this:



              127.0.1.1 Megabyte Megabyte
              127.0.0.1 localhost


              To this:



              127.0.1.1 Debian Debian
              127.0.0.1 localhost


              and that fixed my error! Hope this helped!






              share|improve this answer





























                2














                Everybody advises to modify /etc/hosts. But in some cases this may not be possible (for example inside a docker container). So, I had to find a better way and I came up with this:



                echo "alias sudo='sudo -h 127.0.0.1'" >> ~/.bash_aliases
                source ~/.bashrc


                Aliases don't work in bash scripts, but we can use variables: sudo='sudo -h 127.0.0.1'






                share|improve this answer





























                  1














                  I had the same problem. I solved it by editing the /etc/hosts and /etc/hostname files... on the /etc/hosts file, just edit the top part as shown below.



                  #vi /etc/hosts
                  127.0.0.1 localhost
                  127.0.1.1 localhost myhostname




                  #vi /etc/hostname
                  myhostname





                  share|improve this answer























                  • 127.0.1.1 localhost myhostname or 127.0.1.1 myhostname?
                    – Mostafa Ahangarha
                    Mar 26 '16 at 18:43






                  • 2




                    How can you edit /etc/hosts without sudo. sudo doesn't work sudo: unable to resolve host ...
                    – Green
                    Jul 12 '16 at 20:02



















                  1














                  if you can't sudo you CAN log in as root via su.
                  IE: su root (in an x-term).
                  then give the root password when prompted, then you can edit the files with nano. The root password in 'buntu is the same as the password you would use for sudo.






                  share|improve this answer

















                  • 5




                    The root password in Ubuntu is not the same password for sudo. root is its own account, which doesn't have a password set by default.
                    – TheWanderer
                    Aug 24 '16 at 19:38



















                  1














                  If you are using Vagrant, then login into the guest and run
                  apt-get --no-install-recommends install virtualbox-guest-utils






                  share|improve this answer




















                    protected by Community Mar 31 '17 at 3:42



                    Thank you for your interest in this question.
                    Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                    Would you like to answer one of these unanswered questions instead?














                    19 Answers
                    19






                    active

                    oldest

                    votes








                    19 Answers
                    19






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    918














                    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.






                    share|improve this answer



















                    • 29




                      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.
                      – Yashvit
                      May 5 '13 at 15:22








                    • 2




                      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.
                      – Ian M
                      Jul 17 '16 at 20:19






                    • 4




                      I'm using Linux Subsystem in Windows and I faced this problem. After following your answer, It has been resolved.
                      – amarVashishth
                      Dec 28 '16 at 15:43






                    • 2




                      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)
                      – Woodrow Barlow
                      Sep 27 '17 at 14:51








                    • 9




                      Why does your example have 127.0.0.1 localhost but 127.0.1.1 my-machine?
                      – Adam
                      Dec 21 '17 at 23:11
















                    918














                    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.






                    share|improve this answer



















                    • 29




                      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.
                      – Yashvit
                      May 5 '13 at 15:22








                    • 2




                      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.
                      – Ian M
                      Jul 17 '16 at 20:19






                    • 4




                      I'm using Linux Subsystem in Windows and I faced this problem. After following your answer, It has been resolved.
                      – amarVashishth
                      Dec 28 '16 at 15:43






                    • 2




                      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)
                      – Woodrow Barlow
                      Sep 27 '17 at 14:51








                    • 9




                      Why does your example have 127.0.0.1 localhost but 127.0.1.1 my-machine?
                      – Adam
                      Dec 21 '17 at 23:11














                    918












                    918








                    918






                    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.






                    share|improve this answer














                    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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 22 '16 at 0:23









                    Thomas Ward

                    43.5k23120172




                    43.5k23120172










                    answered Sep 1 '11 at 3:26









                    Jeremy Kerr

                    19.1k33958




                    19.1k33958








                    • 29




                      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.
                      – Yashvit
                      May 5 '13 at 15:22








                    • 2




                      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.
                      – Ian M
                      Jul 17 '16 at 20:19






                    • 4




                      I'm using Linux Subsystem in Windows and I faced this problem. After following your answer, It has been resolved.
                      – amarVashishth
                      Dec 28 '16 at 15:43






                    • 2




                      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)
                      – Woodrow Barlow
                      Sep 27 '17 at 14:51








                    • 9




                      Why does your example have 127.0.0.1 localhost but 127.0.1.1 my-machine?
                      – Adam
                      Dec 21 '17 at 23:11














                    • 29




                      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.
                      – Yashvit
                      May 5 '13 at 15:22








                    • 2




                      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.
                      – Ian M
                      Jul 17 '16 at 20:19






                    • 4




                      I'm using Linux Subsystem in Windows and I faced this problem. After following your answer, It has been resolved.
                      – amarVashishth
                      Dec 28 '16 at 15:43






                    • 2




                      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)
                      – Woodrow Barlow
                      Sep 27 '17 at 14:51








                    • 9




                      Why does your example have 127.0.0.1 localhost but 127.0.1.1 my-machine?
                      – Adam
                      Dec 21 '17 at 23:11








                    29




                    29




                    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.
                    – Yashvit
                    May 5 '13 at 15:22






                    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.
                    – Yashvit
                    May 5 '13 at 15:22






                    2




                    2




                    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.
                    – Ian M
                    Jul 17 '16 at 20:19




                    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.
                    – Ian M
                    Jul 17 '16 at 20:19




                    4




                    4




                    I'm using Linux Subsystem in Windows and I faced this problem. After following your answer, It has been resolved.
                    – amarVashishth
                    Dec 28 '16 at 15:43




                    I'm using Linux Subsystem in Windows and I faced this problem. After following your answer, It has been resolved.
                    – amarVashishth
                    Dec 28 '16 at 15:43




                    2




                    2




                    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)
                    – Woodrow Barlow
                    Sep 27 '17 at 14:51






                    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)
                    – Woodrow Barlow
                    Sep 27 '17 at 14:51






                    9




                    9




                    Why does your example have 127.0.0.1 localhost but 127.0.1.1 my-machine?
                    – Adam
                    Dec 21 '17 at 23:11




                    Why does your example have 127.0.0.1 localhost but 127.0.1.1 my-machine?
                    – Adam
                    Dec 21 '17 at 23:11













                    182














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



                    Mine looks like:



                    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.






                    share|improve this answer



















                    • 2




                      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
                      Mar 29 '15 at 22:31






                    • 7




                      @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.
                      – Lekensteyn
                      Mar 29 '15 at 23:31
















                    182














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



                    Mine looks like:



                    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.






                    share|improve this answer



















                    • 2




                      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
                      Mar 29 '15 at 22:31






                    • 7




                      @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.
                      – Lekensteyn
                      Mar 29 '15 at 23:31














                    182












                    182








                    182






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



                    Mine looks like:



                    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.






                    share|improve this answer














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



                    Mine looks like:



                    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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Apr 13 '17 at 12:24









                    Community

                    1




                    1










                    answered Apr 7 '12 at 13:39









                    Lekensteyn

                    120k48263355




                    120k48263355








                    • 2




                      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
                      Mar 29 '15 at 22:31






                    • 7




                      @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.
                      – Lekensteyn
                      Mar 29 '15 at 23:31














                    • 2




                      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
                      Mar 29 '15 at 22:31






                    • 7




                      @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.
                      – Lekensteyn
                      Mar 29 '15 at 23:31








                    2




                    2




                    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
                    Mar 29 '15 at 22:31




                    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
                    Mar 29 '15 at 22:31




                    7




                    7




                    @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.
                    – Lekensteyn
                    Mar 29 '15 at 23:31




                    @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.
                    – Lekensteyn
                    Mar 29 '15 at 23:31











                    57














                    Add your hostname to /etc/hosts like so:



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





                    share|improve this answer

















                    • 9




                      This was a brilliant answer that didnt get enough credit
                      – Edziu Eames
                      Oct 17 '16 at 1:55










                    • Nice one! Agreed it doesn't get enough rep love. :-)
                      – Peter K.
                      Oct 13 '17 at 12:39










                    • It's clever, but I don't think it tends to be a good idea to automate something like this.
                      – mwfearnley
                      Jan 4 '18 at 13:59










                    • 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.
                      – shivesh suman
                      Sep 21 '18 at 21:05










                    • this one saved my ass
                      – hoffmanc
                      Sep 27 '18 at 23:05
















                    57














                    Add your hostname to /etc/hosts like so:



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





                    share|improve this answer

















                    • 9




                      This was a brilliant answer that didnt get enough credit
                      – Edziu Eames
                      Oct 17 '16 at 1:55










                    • Nice one! Agreed it doesn't get enough rep love. :-)
                      – Peter K.
                      Oct 13 '17 at 12:39










                    • It's clever, but I don't think it tends to be a good idea to automate something like this.
                      – mwfearnley
                      Jan 4 '18 at 13:59










                    • 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.
                      – shivesh suman
                      Sep 21 '18 at 21:05










                    • this one saved my ass
                      – hoffmanc
                      Sep 27 '18 at 23:05














                    57












                    57








                    57






                    Add your hostname to /etc/hosts like so:



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





                    share|improve this answer












                    Add your hostname to /etc/hosts like so:



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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 15 '14 at 16:03









                    Collin Anderson

                    2,2551118




                    2,2551118








                    • 9




                      This was a brilliant answer that didnt get enough credit
                      – Edziu Eames
                      Oct 17 '16 at 1:55










                    • Nice one! Agreed it doesn't get enough rep love. :-)
                      – Peter K.
                      Oct 13 '17 at 12:39










                    • It's clever, but I don't think it tends to be a good idea to automate something like this.
                      – mwfearnley
                      Jan 4 '18 at 13:59










                    • 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.
                      – shivesh suman
                      Sep 21 '18 at 21:05










                    • this one saved my ass
                      – hoffmanc
                      Sep 27 '18 at 23:05














                    • 9




                      This was a brilliant answer that didnt get enough credit
                      – Edziu Eames
                      Oct 17 '16 at 1:55










                    • Nice one! Agreed it doesn't get enough rep love. :-)
                      – Peter K.
                      Oct 13 '17 at 12:39










                    • It's clever, but I don't think it tends to be a good idea to automate something like this.
                      – mwfearnley
                      Jan 4 '18 at 13:59










                    • 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.
                      – shivesh suman
                      Sep 21 '18 at 21:05










                    • this one saved my ass
                      – hoffmanc
                      Sep 27 '18 at 23:05








                    9




                    9




                    This was a brilliant answer that didnt get enough credit
                    – Edziu Eames
                    Oct 17 '16 at 1:55




                    This was a brilliant answer that didnt get enough credit
                    – Edziu Eames
                    Oct 17 '16 at 1:55












                    Nice one! Agreed it doesn't get enough rep love. :-)
                    – Peter K.
                    Oct 13 '17 at 12:39




                    Nice one! Agreed it doesn't get enough rep love. :-)
                    – Peter K.
                    Oct 13 '17 at 12:39












                    It's clever, but I don't think it tends to be a good idea to automate something like this.
                    – mwfearnley
                    Jan 4 '18 at 13:59




                    It's clever, but I don't think it tends to be a good idea to automate something like this.
                    – mwfearnley
                    Jan 4 '18 at 13:59












                    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.
                    – shivesh suman
                    Sep 21 '18 at 21:05




                    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.
                    – shivesh suman
                    Sep 21 '18 at 21:05












                    this one saved my ass
                    – hoffmanc
                    Sep 27 '18 at 23:05




                    this one saved my ass
                    – hoffmanc
                    Sep 27 '18 at 23:05











                    30














                    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:



                    127.0.1.1   dave00-G31M-ES2


                    So it becomes:



                    127.0.1.1   dave00-G31M-ES2L


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



                    sudo gedit /etc/hosts


                    Add the letter L as mentioned, save and exit.






                    share|improve this answer



















                    • 10




                      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.
                      – Jan
                      Sep 26 '14 at 13:54






                    • 2




                      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
                      Jul 12 '16 at 20:18










                    • @Green: No sudo? The error message you mention comes from the sudo command. Perhaps you meant something different?
                      – Thor
                      Jul 14 '16 at 13:49










                    • @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).
                      – Wlerin
                      Jul 28 '16 at 19:16








                    • 4




                      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.
                      – Ave
                      Aug 5 '16 at 2:13


















                    30














                    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:



                    127.0.1.1   dave00-G31M-ES2


                    So it becomes:



                    127.0.1.1   dave00-G31M-ES2L


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



                    sudo gedit /etc/hosts


                    Add the letter L as mentioned, save and exit.






                    share|improve this answer



















                    • 10




                      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.
                      – Jan
                      Sep 26 '14 at 13:54






                    • 2




                      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
                      Jul 12 '16 at 20:18










                    • @Green: No sudo? The error message you mention comes from the sudo command. Perhaps you meant something different?
                      – Thor
                      Jul 14 '16 at 13:49










                    • @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).
                      – Wlerin
                      Jul 28 '16 at 19:16








                    • 4




                      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.
                      – Ave
                      Aug 5 '16 at 2:13
















                    30












                    30








                    30






                    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:



                    127.0.1.1   dave00-G31M-ES2


                    So it becomes:



                    127.0.1.1   dave00-G31M-ES2L


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



                    sudo gedit /etc/hosts


                    Add the letter L as mentioned, save and exit.






                    share|improve this answer














                    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:



                    127.0.1.1   dave00-G31M-ES2


                    So it becomes:



                    127.0.1.1   dave00-G31M-ES2L


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



                    sudo gedit /etc/hosts


                    Add the letter L as mentioned, save and exit.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Apr 13 '17 at 12:23









                    Community

                    1




                    1










                    answered Aug 18 '12 at 11:02









                    Thor

                    2,5231620




                    2,5231620








                    • 10




                      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.
                      – Jan
                      Sep 26 '14 at 13:54






                    • 2




                      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
                      Jul 12 '16 at 20:18










                    • @Green: No sudo? The error message you mention comes from the sudo command. Perhaps you meant something different?
                      – Thor
                      Jul 14 '16 at 13:49










                    • @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).
                      – Wlerin
                      Jul 28 '16 at 19:16








                    • 4




                      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.
                      – Ave
                      Aug 5 '16 at 2:13
















                    • 10




                      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.
                      – Jan
                      Sep 26 '14 at 13:54






                    • 2




                      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
                      Jul 12 '16 at 20:18










                    • @Green: No sudo? The error message you mention comes from the sudo command. Perhaps you meant something different?
                      – Thor
                      Jul 14 '16 at 13:49










                    • @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).
                      – Wlerin
                      Jul 28 '16 at 19:16








                    • 4




                      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.
                      – Ave
                      Aug 5 '16 at 2:13










                    10




                    10




                    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.
                    – Jan
                    Sep 26 '14 at 13:54




                    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.
                    – Jan
                    Sep 26 '14 at 13:54




                    2




                    2




                    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
                    Jul 12 '16 at 20:18




                    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
                    Jul 12 '16 at 20:18












                    @Green: No sudo? The error message you mention comes from the sudo command. Perhaps you meant something different?
                    – Thor
                    Jul 14 '16 at 13:49




                    @Green: No sudo? The error message you mention comes from the sudo command. Perhaps you meant something different?
                    – Thor
                    Jul 14 '16 at 13:49












                    @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).
                    – Wlerin
                    Jul 28 '16 at 19:16






                    @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).
                    – Wlerin
                    Jul 28 '16 at 19:16






                    4




                    4




                    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.
                    – Ave
                    Aug 5 '16 at 2:13






                    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.
                    – Ave
                    Aug 5 '16 at 2:13













                    16














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



                    run this command:



                    sudo nano /etc/hosts


                    and then add:



                    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!






                    share|improve this answer

















                    • 1




                      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".
                      – Waldir Leoncio
                      Oct 26 '13 at 14:33






                    • 2




                      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.
                      – Jan
                      Sep 26 '14 at 13:55
















                    16














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



                    run this command:



                    sudo nano /etc/hosts


                    and then add:



                    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!






                    share|improve this answer

















                    • 1




                      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".
                      – Waldir Leoncio
                      Oct 26 '13 at 14:33






                    • 2




                      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.
                      – Jan
                      Sep 26 '14 at 13:55














                    16












                    16








                    16






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



                    run this command:



                    sudo nano /etc/hosts


                    and then add:



                    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!






                    share|improve this answer












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



                    run this command:



                    sudo nano /etc/hosts


                    and then add:



                    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!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 1 '13 at 1:18









                    Luca D'Amico

                    436511




                    436511








                    • 1




                      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".
                      – Waldir Leoncio
                      Oct 26 '13 at 14:33






                    • 2




                      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.
                      – Jan
                      Sep 26 '14 at 13:55














                    • 1




                      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".
                      – Waldir Leoncio
                      Oct 26 '13 at 14:33






                    • 2




                      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.
                      – Jan
                      Sep 26 '14 at 13:55








                    1




                    1




                    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".
                    – Waldir Leoncio
                    Oct 26 '13 at 14:33




                    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".
                    – Waldir Leoncio
                    Oct 26 '13 at 14:33




                    2




                    2




                    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.
                    – Jan
                    Sep 26 '14 at 13:55




                    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.
                    – Jan
                    Sep 26 '14 at 13:55











                    10














                    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.






                    share|improve this answer


























                      10














                      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.






                      share|improve this answer
























                        10












                        10








                        10






                        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.






                        share|improve this answer












                        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.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Aug 13 '14 at 13:50









                        Chris.B

                        20123




                        20123























                            10














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






                            share|improve this answer

















                            • 2




                              Welcome to askubuntu! Can you expand a bit on this? It's not abundantly clear what you mean (at least to me)..
                              – Elder Geek
                              Jan 15 '15 at 13:56










                            • This may not be relevant to the question, but it greatly helped me. Thank you!
                              – clayzermk1
                              Apr 10 '15 at 17:35






                            • 1




                              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.
                              – Chris Moore
                              Jul 1 '15 at 1:16










                            • the Enable DNS Hostnames option can be found (for example) in the right-click menu of the vpc entry
                              – Matteo Scotuzzi
                              Jan 3 '16 at 17:32










                            • There is no DNS Hostnames
                              – Green
                              Jul 12 '16 at 20:11
















                            10














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






                            share|improve this answer

















                            • 2




                              Welcome to askubuntu! Can you expand a bit on this? It's not abundantly clear what you mean (at least to me)..
                              – Elder Geek
                              Jan 15 '15 at 13:56










                            • This may not be relevant to the question, but it greatly helped me. Thank you!
                              – clayzermk1
                              Apr 10 '15 at 17:35






                            • 1




                              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.
                              – Chris Moore
                              Jul 1 '15 at 1:16










                            • the Enable DNS Hostnames option can be found (for example) in the right-click menu of the vpc entry
                              – Matteo Scotuzzi
                              Jan 3 '16 at 17:32










                            • There is no DNS Hostnames
                              – Green
                              Jul 12 '16 at 20:11














                            10












                            10








                            10






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






                            share|improve this answer












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







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 15 '15 at 5:15









                            Erick

                            10912




                            10912








                            • 2




                              Welcome to askubuntu! Can you expand a bit on this? It's not abundantly clear what you mean (at least to me)..
                              – Elder Geek
                              Jan 15 '15 at 13:56










                            • This may not be relevant to the question, but it greatly helped me. Thank you!
                              – clayzermk1
                              Apr 10 '15 at 17:35






                            • 1




                              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.
                              – Chris Moore
                              Jul 1 '15 at 1:16










                            • the Enable DNS Hostnames option can be found (for example) in the right-click menu of the vpc entry
                              – Matteo Scotuzzi
                              Jan 3 '16 at 17:32










                            • There is no DNS Hostnames
                              – Green
                              Jul 12 '16 at 20:11














                            • 2




                              Welcome to askubuntu! Can you expand a bit on this? It's not abundantly clear what you mean (at least to me)..
                              – Elder Geek
                              Jan 15 '15 at 13:56










                            • This may not be relevant to the question, but it greatly helped me. Thank you!
                              – clayzermk1
                              Apr 10 '15 at 17:35






                            • 1




                              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.
                              – Chris Moore
                              Jul 1 '15 at 1:16










                            • the Enable DNS Hostnames option can be found (for example) in the right-click menu of the vpc entry
                              – Matteo Scotuzzi
                              Jan 3 '16 at 17:32










                            • There is no DNS Hostnames
                              – Green
                              Jul 12 '16 at 20:11








                            2




                            2




                            Welcome to askubuntu! Can you expand a bit on this? It's not abundantly clear what you mean (at least to me)..
                            – Elder Geek
                            Jan 15 '15 at 13:56




                            Welcome to askubuntu! Can you expand a bit on this? It's not abundantly clear what you mean (at least to me)..
                            – Elder Geek
                            Jan 15 '15 at 13:56












                            This may not be relevant to the question, but it greatly helped me. Thank you!
                            – clayzermk1
                            Apr 10 '15 at 17:35




                            This may not be relevant to the question, but it greatly helped me. Thank you!
                            – clayzermk1
                            Apr 10 '15 at 17:35




                            1




                            1




                            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.
                            – Chris Moore
                            Jul 1 '15 at 1:16




                            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.
                            – Chris Moore
                            Jul 1 '15 at 1:16












                            the Enable DNS Hostnames option can be found (for example) in the right-click menu of the vpc entry
                            – Matteo Scotuzzi
                            Jan 3 '16 at 17:32




                            the Enable DNS Hostnames option can be found (for example) in the right-click menu of the vpc entry
                            – Matteo Scotuzzi
                            Jan 3 '16 at 17:32












                            There is no DNS Hostnames
                            – Green
                            Jul 12 '16 at 20:11




                            There is no DNS Hostnames
                            – Green
                            Jul 12 '16 at 20:11











                            5














                            I encountered this same error message. I think this discussion thread at AWS Developer Forums is a better solution:



                            "Go the the VPC management console, select the VPC, click on Actions, select Edit DNS Hostnames and select Yes."



                            https://forums.aws.amazon.com/thread.jspa?messageID=699718






                            share|improve this answer


























                              5














                              I encountered this same error message. I think this discussion thread at AWS Developer Forums is a better solution:



                              "Go the the VPC management console, select the VPC, click on Actions, select Edit DNS Hostnames and select Yes."



                              https://forums.aws.amazon.com/thread.jspa?messageID=699718






                              share|improve this answer
























                                5












                                5








                                5






                                I encountered this same error message. I think this discussion thread at AWS Developer Forums is a better solution:



                                "Go the the VPC management console, select the VPC, click on Actions, select Edit DNS Hostnames and select Yes."



                                https://forums.aws.amazon.com/thread.jspa?messageID=699718






                                share|improve this answer












                                I encountered this same error message. I think this discussion thread at AWS Developer Forums is a better solution:



                                "Go the the VPC management console, select the VPC, click on Actions, select Edit DNS Hostnames and select Yes."



                                https://forums.aws.amazon.com/thread.jspa?messageID=699718







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Feb 13 '16 at 11:44









                                user93581

                                9112




                                9112























                                    5














                                    Some terminal emulators will not update prompt with the correct hostname until you close and restart the emulator (lxterminal, I'm talking to you).



                                    I spent 30min fighting with this error after editing my hostname and hosts files and running sudo service hostname restart until I ran sudo hostname and saw that the hostname was the new value, even though the prompt was showning the old value.






                                    share|improve this answer

















                                    • 1




                                      The issue isn't the terminal emulators, it's the shells that have cached the value.
                                      – Mark Stosberg
                                      Feb 16 '17 at 19:53
















                                    5














                                    Some terminal emulators will not update prompt with the correct hostname until you close and restart the emulator (lxterminal, I'm talking to you).



                                    I spent 30min fighting with this error after editing my hostname and hosts files and running sudo service hostname restart until I ran sudo hostname and saw that the hostname was the new value, even though the prompt was showning the old value.






                                    share|improve this answer

















                                    • 1




                                      The issue isn't the terminal emulators, it's the shells that have cached the value.
                                      – Mark Stosberg
                                      Feb 16 '17 at 19:53














                                    5












                                    5








                                    5






                                    Some terminal emulators will not update prompt with the correct hostname until you close and restart the emulator (lxterminal, I'm talking to you).



                                    I spent 30min fighting with this error after editing my hostname and hosts files and running sudo service hostname restart until I ran sudo hostname and saw that the hostname was the new value, even though the prompt was showning the old value.






                                    share|improve this answer












                                    Some terminal emulators will not update prompt with the correct hostname until you close and restart the emulator (lxterminal, I'm talking to you).



                                    I spent 30min fighting with this error after editing my hostname and hosts files and running sudo service hostname restart until I ran sudo hostname and saw that the hostname was the new value, even though the prompt was showning the old value.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jun 19 '16 at 16:29









                                    dagbel

                                    5111




                                    5111








                                    • 1




                                      The issue isn't the terminal emulators, it's the shells that have cached the value.
                                      – Mark Stosberg
                                      Feb 16 '17 at 19:53














                                    • 1




                                      The issue isn't the terminal emulators, it's the shells that have cached the value.
                                      – Mark Stosberg
                                      Feb 16 '17 at 19:53








                                    1




                                    1




                                    The issue isn't the terminal emulators, it's the shells that have cached the value.
                                    – Mark Stosberg
                                    Feb 16 '17 at 19:53




                                    The issue isn't the terminal emulators, it's the shells that have cached the value.
                                    – Mark Stosberg
                                    Feb 16 '17 at 19:53











                                    4














                                    In my case it was the problem, I changed the hostname to man because I wanted to know if there are some parameters you can use on hostname. Instead it changed my hostname to man and I always got the same message like you



                                    sudo: unable to resolve host (none)


                                    after changing the hostname back to `localhost everything worked fine again



                                    hostname localhost





                                    share|improve this answer


























                                      4














                                      In my case it was the problem, I changed the hostname to man because I wanted to know if there are some parameters you can use on hostname. Instead it changed my hostname to man and I always got the same message like you



                                      sudo: unable to resolve host (none)


                                      after changing the hostname back to `localhost everything worked fine again



                                      hostname localhost





                                      share|improve this answer
























                                        4












                                        4








                                        4






                                        In my case it was the problem, I changed the hostname to man because I wanted to know if there are some parameters you can use on hostname. Instead it changed my hostname to man and I always got the same message like you



                                        sudo: unable to resolve host (none)


                                        after changing the hostname back to `localhost everything worked fine again



                                        hostname localhost





                                        share|improve this answer












                                        In my case it was the problem, I changed the hostname to man because I wanted to know if there are some parameters you can use on hostname. Instead it changed my hostname to man and I always got the same message like you



                                        sudo: unable to resolve host (none)


                                        after changing the hostname back to `localhost everything worked fine again



                                        hostname localhost






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jan 9 '14 at 22:24









                                        XandruCea

                                        1435




                                        1435























                                            3














                                            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.






                                            share|improve this answer




























                                              3














                                              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.






                                              share|improve this answer


























                                                3












                                                3








                                                3






                                                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.






                                                share|improve this answer














                                                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.







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Sep 18 '17 at 22:23

























                                                answered Sep 18 '17 at 22:17









                                                nobar

                                                1,50621426




                                                1,50621426























                                                    2














                                                    Sorry I can't help you much but, since it says "can't resolve host" try running:



                                                    hostname


                                                    And see if the output is the hostname of the machine. If not, the problem is the host configuration, not sudo.






                                                    share|improve this answer





















                                                    • I did that got the hostname of my machine. I also have entry in /etc/hosts. I'm still getting the error.
                                                      – chandresh
                                                      May 6 '17 at 13:22










                                                    • Did you reboot the machine after changing the hosts file?
                                                      – animaletdesequia
                                                      May 7 '17 at 18:52










                                                    • No. Though my IT team said there was issue with lock file as well as gpg key with puppetlabs. Now, it got resolved without restart..
                                                      – chandresh
                                                      May 8 '17 at 9:28


















                                                    2














                                                    Sorry I can't help you much but, since it says "can't resolve host" try running:



                                                    hostname


                                                    And see if the output is the hostname of the machine. If not, the problem is the host configuration, not sudo.






                                                    share|improve this answer





















                                                    • I did that got the hostname of my machine. I also have entry in /etc/hosts. I'm still getting the error.
                                                      – chandresh
                                                      May 6 '17 at 13:22










                                                    • Did you reboot the machine after changing the hosts file?
                                                      – animaletdesequia
                                                      May 7 '17 at 18:52










                                                    • No. Though my IT team said there was issue with lock file as well as gpg key with puppetlabs. Now, it got resolved without restart..
                                                      – chandresh
                                                      May 8 '17 at 9:28
















                                                    2












                                                    2








                                                    2






                                                    Sorry I can't help you much but, since it says "can't resolve host" try running:



                                                    hostname


                                                    And see if the output is the hostname of the machine. If not, the problem is the host configuration, not sudo.






                                                    share|improve this answer












                                                    Sorry I can't help you much but, since it says "can't resolve host" try running:



                                                    hostname


                                                    And see if the output is the hostname of the machine. If not, the problem is the host configuration, not sudo.







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Aug 31 '11 at 19:16









                                                    animaletdesequia

                                                    6,58041938




                                                    6,58041938












                                                    • I did that got the hostname of my machine. I also have entry in /etc/hosts. I'm still getting the error.
                                                      – chandresh
                                                      May 6 '17 at 13:22










                                                    • Did you reboot the machine after changing the hosts file?
                                                      – animaletdesequia
                                                      May 7 '17 at 18:52










                                                    • No. Though my IT team said there was issue with lock file as well as gpg key with puppetlabs. Now, it got resolved without restart..
                                                      – chandresh
                                                      May 8 '17 at 9:28




















                                                    • I did that got the hostname of my machine. I also have entry in /etc/hosts. I'm still getting the error.
                                                      – chandresh
                                                      May 6 '17 at 13:22










                                                    • Did you reboot the machine after changing the hosts file?
                                                      – animaletdesequia
                                                      May 7 '17 at 18:52










                                                    • No. Though my IT team said there was issue with lock file as well as gpg key with puppetlabs. Now, it got resolved without restart..
                                                      – chandresh
                                                      May 8 '17 at 9:28


















                                                    I did that got the hostname of my machine. I also have entry in /etc/hosts. I'm still getting the error.
                                                    – chandresh
                                                    May 6 '17 at 13:22




                                                    I did that got the hostname of my machine. I also have entry in /etc/hosts. I'm still getting the error.
                                                    – chandresh
                                                    May 6 '17 at 13:22












                                                    Did you reboot the machine after changing the hosts file?
                                                    – animaletdesequia
                                                    May 7 '17 at 18:52




                                                    Did you reboot the machine after changing the hosts file?
                                                    – animaletdesequia
                                                    May 7 '17 at 18:52












                                                    No. Though my IT team said there was issue with lock file as well as gpg key with puppetlabs. Now, it got resolved without restart..
                                                    – chandresh
                                                    May 8 '17 at 9:28






                                                    No. Though my IT team said there was issue with lock file as well as gpg key with puppetlabs. Now, it got resolved without restart..
                                                    – chandresh
                                                    May 8 '17 at 9:28













                                                    2














                                                    OP wrote:




                                                    It was all in /etc/hostname. On two of our sick servers it looked like
                                                    this:



                                                    ubuntu@(none):~$ cat /etc/hostname
                                                    linux-web-n ip-10-128-##-##


                                                    While on a server without this issue we had:



                                                    ubuntu@ip-10-128-##-###:~$ cat /etc/hostname
                                                    ip-10-128-##-###


                                                    Removed the linux-web-n portion, rebooted and everything was fine.







                                                    share|improve this answer




























                                                      2














                                                      OP wrote:




                                                      It was all in /etc/hostname. On two of our sick servers it looked like
                                                      this:



                                                      ubuntu@(none):~$ cat /etc/hostname
                                                      linux-web-n ip-10-128-##-##


                                                      While on a server without this issue we had:



                                                      ubuntu@ip-10-128-##-###:~$ cat /etc/hostname
                                                      ip-10-128-##-###


                                                      Removed the linux-web-n portion, rebooted and everything was fine.







                                                      share|improve this answer


























                                                        2












                                                        2








                                                        2






                                                        OP wrote:




                                                        It was all in /etc/hostname. On two of our sick servers it looked like
                                                        this:



                                                        ubuntu@(none):~$ cat /etc/hostname
                                                        linux-web-n ip-10-128-##-##


                                                        While on a server without this issue we had:



                                                        ubuntu@ip-10-128-##-###:~$ cat /etc/hostname
                                                        ip-10-128-##-###


                                                        Removed the linux-web-n portion, rebooted and everything was fine.







                                                        share|improve this answer














                                                        OP wrote:




                                                        It was all in /etc/hostname. On two of our sick servers it looked like
                                                        this:



                                                        ubuntu@(none):~$ cat /etc/hostname
                                                        linux-web-n ip-10-128-##-##


                                                        While on a server without this issue we had:



                                                        ubuntu@ip-10-128-##-###:~$ cat /etc/hostname
                                                        ip-10-128-##-###


                                                        Removed the linux-web-n portion, rebooted and everything was fine.








                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        answered Apr 13 '14 at 5:19


























                                                        community wiki





                                                        Radu Rădeanu
























                                                            2














                                                            you might be getting an error if your hosts or hostname file contain illegal characters. Only these symbols are permitted: a-z, A-Z, 0-9






                                                            share|improve this answer


























                                                              2














                                                              you might be getting an error if your hosts or hostname file contain illegal characters. Only these symbols are permitted: a-z, A-Z, 0-9






                                                              share|improve this answer
























                                                                2












                                                                2








                                                                2






                                                                you might be getting an error if your hosts or hostname file contain illegal characters. Only these symbols are permitted: a-z, A-Z, 0-9






                                                                share|improve this answer












                                                                you might be getting an error if your hosts or hostname file contain illegal characters. Only these symbols are permitted: a-z, A-Z, 0-9







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered Jan 18 '15 at 3:26









                                                                Marcello

                                                                1211




                                                                1211























                                                                    2














                                                                    I had this same problem! I changed my VPS's name through the online admin control panel which did not change the machine name in the hosts file All I did was run:



                                                                    sudo nano /etc/hosts


                                                                    Then I edited it from this:



                                                                    127.0.1.1 Megabyte Megabyte
                                                                    127.0.0.1 localhost


                                                                    To this:



                                                                    127.0.1.1 Debian Debian
                                                                    127.0.0.1 localhost


                                                                    and that fixed my error! Hope this helped!






                                                                    share|improve this answer


























                                                                      2














                                                                      I had this same problem! I changed my VPS's name through the online admin control panel which did not change the machine name in the hosts file All I did was run:



                                                                      sudo nano /etc/hosts


                                                                      Then I edited it from this:



                                                                      127.0.1.1 Megabyte Megabyte
                                                                      127.0.0.1 localhost


                                                                      To this:



                                                                      127.0.1.1 Debian Debian
                                                                      127.0.0.1 localhost


                                                                      and that fixed my error! Hope this helped!






                                                                      share|improve this answer
























                                                                        2












                                                                        2








                                                                        2






                                                                        I had this same problem! I changed my VPS's name through the online admin control panel which did not change the machine name in the hosts file All I did was run:



                                                                        sudo nano /etc/hosts


                                                                        Then I edited it from this:



                                                                        127.0.1.1 Megabyte Megabyte
                                                                        127.0.0.1 localhost


                                                                        To this:



                                                                        127.0.1.1 Debian Debian
                                                                        127.0.0.1 localhost


                                                                        and that fixed my error! Hope this helped!






                                                                        share|improve this answer












                                                                        I had this same problem! I changed my VPS's name through the online admin control panel which did not change the machine name in the hosts file All I did was run:



                                                                        sudo nano /etc/hosts


                                                                        Then I edited it from this:



                                                                        127.0.1.1 Megabyte Megabyte
                                                                        127.0.0.1 localhost


                                                                        To this:



                                                                        127.0.1.1 Debian Debian
                                                                        127.0.0.1 localhost


                                                                        and that fixed my error! Hope this helped!







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Jan 10 '17 at 2:18









                                                                        Synth

                                                                        211




                                                                        211























                                                                            2














                                                                            Everybody advises to modify /etc/hosts. But in some cases this may not be possible (for example inside a docker container). So, I had to find a better way and I came up with this:



                                                                            echo "alias sudo='sudo -h 127.0.0.1'" >> ~/.bash_aliases
                                                                            source ~/.bashrc


                                                                            Aliases don't work in bash scripts, but we can use variables: sudo='sudo -h 127.0.0.1'






                                                                            share|improve this answer


























                                                                              2














                                                                              Everybody advises to modify /etc/hosts. But in some cases this may not be possible (for example inside a docker container). So, I had to find a better way and I came up with this:



                                                                              echo "alias sudo='sudo -h 127.0.0.1'" >> ~/.bash_aliases
                                                                              source ~/.bashrc


                                                                              Aliases don't work in bash scripts, but we can use variables: sudo='sudo -h 127.0.0.1'






                                                                              share|improve this answer
























                                                                                2












                                                                                2








                                                                                2






                                                                                Everybody advises to modify /etc/hosts. But in some cases this may not be possible (for example inside a docker container). So, I had to find a better way and I came up with this:



                                                                                echo "alias sudo='sudo -h 127.0.0.1'" >> ~/.bash_aliases
                                                                                source ~/.bashrc


                                                                                Aliases don't work in bash scripts, but we can use variables: sudo='sudo -h 127.0.0.1'






                                                                                share|improve this answer












                                                                                Everybody advises to modify /etc/hosts. But in some cases this may not be possible (for example inside a docker container). So, I had to find a better way and I came up with this:



                                                                                echo "alias sudo='sudo -h 127.0.0.1'" >> ~/.bash_aliases
                                                                                source ~/.bashrc


                                                                                Aliases don't work in bash scripts, but we can use variables: sudo='sudo -h 127.0.0.1'







                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Jul 28 '18 at 17:24









                                                                                dashohoxha

                                                                                10329




                                                                                10329























                                                                                    1














                                                                                    I had the same problem. I solved it by editing the /etc/hosts and /etc/hostname files... on the /etc/hosts file, just edit the top part as shown below.



                                                                                    #vi /etc/hosts
                                                                                    127.0.0.1 localhost
                                                                                    127.0.1.1 localhost myhostname




                                                                                    #vi /etc/hostname
                                                                                    myhostname





                                                                                    share|improve this answer























                                                                                    • 127.0.1.1 localhost myhostname or 127.0.1.1 myhostname?
                                                                                      – Mostafa Ahangarha
                                                                                      Mar 26 '16 at 18:43






                                                                                    • 2




                                                                                      How can you edit /etc/hosts without sudo. sudo doesn't work sudo: unable to resolve host ...
                                                                                      – Green
                                                                                      Jul 12 '16 at 20:02
















                                                                                    1














                                                                                    I had the same problem. I solved it by editing the /etc/hosts and /etc/hostname files... on the /etc/hosts file, just edit the top part as shown below.



                                                                                    #vi /etc/hosts
                                                                                    127.0.0.1 localhost
                                                                                    127.0.1.1 localhost myhostname




                                                                                    #vi /etc/hostname
                                                                                    myhostname





                                                                                    share|improve this answer























                                                                                    • 127.0.1.1 localhost myhostname or 127.0.1.1 myhostname?
                                                                                      – Mostafa Ahangarha
                                                                                      Mar 26 '16 at 18:43






                                                                                    • 2




                                                                                      How can you edit /etc/hosts without sudo. sudo doesn't work sudo: unable to resolve host ...
                                                                                      – Green
                                                                                      Jul 12 '16 at 20:02














                                                                                    1












                                                                                    1








                                                                                    1






                                                                                    I had the same problem. I solved it by editing the /etc/hosts and /etc/hostname files... on the /etc/hosts file, just edit the top part as shown below.



                                                                                    #vi /etc/hosts
                                                                                    127.0.0.1 localhost
                                                                                    127.0.1.1 localhost myhostname




                                                                                    #vi /etc/hostname
                                                                                    myhostname





                                                                                    share|improve this answer














                                                                                    I had the same problem. I solved it by editing the /etc/hosts and /etc/hostname files... on the /etc/hosts file, just edit the top part as shown below.



                                                                                    #vi /etc/hosts
                                                                                    127.0.0.1 localhost
                                                                                    127.0.1.1 localhost myhostname




                                                                                    #vi /etc/hostname
                                                                                    myhostname






                                                                                    share|improve this answer














                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited Mar 26 '16 at 17:59









                                                                                    muru

                                                                                    1




                                                                                    1










                                                                                    answered Mar 26 '16 at 17:53









                                                                                    Centy

                                                                                    211




                                                                                    211












                                                                                    • 127.0.1.1 localhost myhostname or 127.0.1.1 myhostname?
                                                                                      – Mostafa Ahangarha
                                                                                      Mar 26 '16 at 18:43






                                                                                    • 2




                                                                                      How can you edit /etc/hosts without sudo. sudo doesn't work sudo: unable to resolve host ...
                                                                                      – Green
                                                                                      Jul 12 '16 at 20:02


















                                                                                    • 127.0.1.1 localhost myhostname or 127.0.1.1 myhostname?
                                                                                      – Mostafa Ahangarha
                                                                                      Mar 26 '16 at 18:43






                                                                                    • 2




                                                                                      How can you edit /etc/hosts without sudo. sudo doesn't work sudo: unable to resolve host ...
                                                                                      – Green
                                                                                      Jul 12 '16 at 20:02
















                                                                                    127.0.1.1 localhost myhostname or 127.0.1.1 myhostname?
                                                                                    – Mostafa Ahangarha
                                                                                    Mar 26 '16 at 18:43




                                                                                    127.0.1.1 localhost myhostname or 127.0.1.1 myhostname?
                                                                                    – Mostafa Ahangarha
                                                                                    Mar 26 '16 at 18:43




                                                                                    2




                                                                                    2




                                                                                    How can you edit /etc/hosts without sudo. sudo doesn't work sudo: unable to resolve host ...
                                                                                    – Green
                                                                                    Jul 12 '16 at 20:02




                                                                                    How can you edit /etc/hosts without sudo. sudo doesn't work sudo: unable to resolve host ...
                                                                                    – Green
                                                                                    Jul 12 '16 at 20:02











                                                                                    1














                                                                                    if you can't sudo you CAN log in as root via su.
                                                                                    IE: su root (in an x-term).
                                                                                    then give the root password when prompted, then you can edit the files with nano. The root password in 'buntu is the same as the password you would use for sudo.






                                                                                    share|improve this answer

















                                                                                    • 5




                                                                                      The root password in Ubuntu is not the same password for sudo. root is its own account, which doesn't have a password set by default.
                                                                                      – TheWanderer
                                                                                      Aug 24 '16 at 19:38
















                                                                                    1














                                                                                    if you can't sudo you CAN log in as root via su.
                                                                                    IE: su root (in an x-term).
                                                                                    then give the root password when prompted, then you can edit the files with nano. The root password in 'buntu is the same as the password you would use for sudo.






                                                                                    share|improve this answer

















                                                                                    • 5




                                                                                      The root password in Ubuntu is not the same password for sudo. root is its own account, which doesn't have a password set by default.
                                                                                      – TheWanderer
                                                                                      Aug 24 '16 at 19:38














                                                                                    1












                                                                                    1








                                                                                    1






                                                                                    if you can't sudo you CAN log in as root via su.
                                                                                    IE: su root (in an x-term).
                                                                                    then give the root password when prompted, then you can edit the files with nano. The root password in 'buntu is the same as the password you would use for sudo.






                                                                                    share|improve this answer












                                                                                    if you can't sudo you CAN log in as root via su.
                                                                                    IE: su root (in an x-term).
                                                                                    then give the root password when prompted, then you can edit the files with nano. The root password in 'buntu is the same as the password you would use for sudo.







                                                                                    share|improve this answer












                                                                                    share|improve this answer



                                                                                    share|improve this answer










                                                                                    answered Aug 24 '16 at 15:07









                                                                                    ken scharf

                                                                                    111




                                                                                    111








                                                                                    • 5




                                                                                      The root password in Ubuntu is not the same password for sudo. root is its own account, which doesn't have a password set by default.
                                                                                      – TheWanderer
                                                                                      Aug 24 '16 at 19:38














                                                                                    • 5




                                                                                      The root password in Ubuntu is not the same password for sudo. root is its own account, which doesn't have a password set by default.
                                                                                      – TheWanderer
                                                                                      Aug 24 '16 at 19:38








                                                                                    5




                                                                                    5




                                                                                    The root password in Ubuntu is not the same password for sudo. root is its own account, which doesn't have a password set by default.
                                                                                    – TheWanderer
                                                                                    Aug 24 '16 at 19:38




                                                                                    The root password in Ubuntu is not the same password for sudo. root is its own account, which doesn't have a password set by default.
                                                                                    – TheWanderer
                                                                                    Aug 24 '16 at 19:38











                                                                                    1














                                                                                    If you are using Vagrant, then login into the guest and run
                                                                                    apt-get --no-install-recommends install virtualbox-guest-utils






                                                                                    share|improve this answer


























                                                                                      1














                                                                                      If you are using Vagrant, then login into the guest and run
                                                                                      apt-get --no-install-recommends install virtualbox-guest-utils






                                                                                      share|improve this answer
























                                                                                        1












                                                                                        1








                                                                                        1






                                                                                        If you are using Vagrant, then login into the guest and run
                                                                                        apt-get --no-install-recommends install virtualbox-guest-utils






                                                                                        share|improve this answer












                                                                                        If you are using Vagrant, then login into the guest and run
                                                                                        apt-get --no-install-recommends install virtualbox-guest-utils







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Jul 13 '17 at 7:27









                                                                                        tanmoy

                                                                                        364




                                                                                        364

















                                                                                            protected by Community Mar 31 '17 at 3:42



                                                                                            Thank you for your interest in this question.
                                                                                            Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                            Would you like to answer one of these unanswered questions instead?



                                                                                            Popular posts from this blog

                                                                                            Quarter-circle Tiles

                                                                                            build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                                                                                            Mont Emei