sudo: unable to resolve host legend27

I am new to this and need help I got this error and need step by step instructions

sudo: unable to resolve host legend27

I am running Ubuntu 16.04

3

2 Answers

Do you have your hostname entry present in /etc/hosts like this?

127.0.0.1 legend27

And BTW, /etc/hostname is a file which needs to be edited, not a command to be executed.

$ /etc/hostname # Executes /etc/hostname as a command; wrong way to do it
$ gedit /etc/hostname # Opens /etc/hostname for editing, right way to do it

You get that "Permission denied" error because /etc/hostname doesn't have the execute bit set on its file permissions, and it is not intended to be executed anyway.

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'

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like