Monday, August 27, 2012

How to solve "sudo: unable to resolve host " problem ??

     Remember the previous post in which i wrote about changing your system's hostname from terminal. While many of you would have encountered a error message "sudo : unable to resolve host yourhostname" while you install or perform any task that requires root privileges. But wait, don't jump to the conclusion that you won't be able to continue your task, you can still continue with your task. There is a simple thing you have to do to get rid of this error.

  • When you edited the hostname file in /etc/hostname, the hostname file just contains the machine name.
  • You have to make the same change to the hosts file in /etc/hosts.
Viewing contents of both files in terminal:
  • Both the contents of the file can be viewed directly from the terminal using the commands,
      • cat /etc/hostname (or) hostname
      • cat /etc/hosts
  • From the above image you can see that, the hostname is aldo while the name in hosts is vms20591.
Viewing contents of both files in text editor: 
  • To view the contents of the file in text editor type the following commands,
      • sudo gedit /etc/hostname
      • sudo gedit /etc/hosts
  • Note:
    • Remember that still you will get the error "sudo : unable to resolve host yourhostname", but just ignore it and type your password.
    • Also don't forget to run the command using sudo without that you can't make any changes in the hosts.

    • You can see the hostname varies in both files.
Making changes to the files:
  • In order to get rid of the error, the name in the files /etc/hostname and /etc/hosts should be the same.
  • Use the command previously mentioned,
      • sudo gedit /etc/hostname
      • sudo gedit /etc/hosts 

  • After making the changes reboot the system and see if the error has been cleared.

     So, the error which occurred was eliminated just by making sure the hostname in both files were the same. Hope this information was useful.

No comments:

Post a Comment