2

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.

2
  • 1
    does your resolver (grep hosts: /etc/nsswitch.conf) include 'files'? If so, an entry in /etc/hosts should do it. Commented 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. Commented Apr 28, 2016 at 19:36

1 Answer 1

4

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.

1
  • 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. Commented Apr 28, 2016 at 19:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.