35

Whenever I do 'sudo' I get an error saying 'sudo: unable to resolve host HP-Pavilion'. I recently change my hostname to "HP-Pavilion". I wonder if I screw up something.

$ sudo mkdir SourceCodePro
sudo: unable to resolve host HP-Pavilion
[sudo] password for mike:

Thank you for your help.

terdon
  • 98,183
  • 15
  • 197
  • 293
n179911
  • 641
  • 2
  • 8
  • 14
  • The question linked as duplicate actually isn't an exact duplicate. There the user has no host at all (`none` is displayed instead of hostname), while here it is not the case. The questions are related but not exactly the same, as is also apparent from the titles. – texnic Jun 11 '17 at 19:41

1 Answers1

69

You changed the host name to HP-Pavilion, but it's not in the file /etc/hosts. So try to add the name to /etc/hosts file and also don't forget to add it to /etc/hostname file .

Your /etc/hosts and /etc/hostname files will look like this,

$ cat /etc/hostname
HP-Pavilion
$ cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   HP-Pavilion

Restart your pc to make changes work.

Avinash Raj
  • 77,204
  • 56
  • 214
  • 254
  • if you want to add the entry in the file, you can use `vi` command: 1. `sudo vi /etc/hosts` 2. press Insert key to be able to add content. 3. add the `127.0.1.1 YOUR_NEW_HOST_NAME_HERE` in the file. 4. press Esc, then `:wq` and then Enter, to save the file – Reza Bayat Mar 21 '23 at 08:43