I'm testing a VPS provider, and recently created a virtual machine with a hostname testserver using an ubuntu template. This VPS provider reserves and bills resources by the month, so if you create a VM for a small job, it's sensible to keep it around in case you need another VM for some other job later.

I came back to VM after a couple of weeks for another job, and wanted to rename the hostname to webserver. I edited /etc/hostname and rebooted, and the OS recognises that the hostname is now webserver. According to the VPS vendor, it's apparently impossible to change the hostname of the VM in the hypervisor resource group (read they haven't created a controller view and form template to do so), so I'm stuck with it being called testserver there. sudo works, but when I sudo I get a warning:

sudo: unable to resolve host webserver

Anyone know why? This is obviously just a minor inconvenience, but I thought I would ask in case anyone knows of a solution.

  • 1
    does your resolver (grep hosts: /etc/nsswitch.conf) include 'files'? If so, an entry in /etc/hosts should do it.
    – Jeff Schaller
    Apr 28, 2016 at 19:23
  • Yep, that was it; the original hostname was there next to the IP instead. Thanks! Paste as an answer and I can accept it.
    – Escher
    Apr 28, 2016 at 19:36

1 Answer 1


sudo uses the system resolver, configured by /etc/nsswitch.conf; in your case, host lookups were configured to use /etc/hosts, which had the previous hostname identified with the server's IP. To fix it, simply update /etc/hosts with the new hostname.

  • You'll also want to look at (for example) /etc/hostname and any other network configuration files (/etc/sysconfig/network on RHEL) for places that had the old hostname.
    – Jeff Schaller
    Apr 28, 2016 at 19:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.