I've got a system - accessible over local network but not connected to the internet. I'm facing issues when changing the hostname of this system. I know that changing hostname is a two step process:

  1. hostnamectl set-hostname myhost.mydomain
  2. sudo nano /etc/hosts -------> It takes ages to open the file/execute any command using sudo When the command does execute, I get the usual sudo: unable to resolve host myhost.mydomain: Name or service not known

The issue is the delay in sudo command that occurs. I can change hostnames using the above two step process on devices connected to other network easily (without observing the noticeable delay in the sudo command). It is only devices connected to this network that I'm facing the sudo delay issue.

Some more experiments - When I reverse the order of changing hostnames, i.e.

  1. sudo nano /etc/hosts - # append myhost.mydomain
  2. hostnamectl set-hostname myhost.mydomain

Everything works perfectly fine and no sudo delay issues are observed. This has led (or misled) me to believe that there might be some issues with DNS resolution. But apart from this I cannot make out why this delay is observed on this system on this specific network.

I've checked the logs of systemd-hostnamed service as well before and after setting hostname and there are no errors observed.

Please let me know how can debug this more effectively


1 Answer 1


I had the same issue, hostnamectl updated my /etc/hostname, but it did not update my /etc/hosts, and that was the issue that made sudo execution very slow.

The way I solved to do it was just manually editing /etc/hosts, for example, if you want to replace an old hostname "old_name" by "new_name", two steps to be done:

$ sudo hostnamectl set-hostname new_name

Just to visualize, as an example:

$ cat /etc/hosts   localhost   old_name

Let's update it to:

$ sudo vim /etc/hosts   localhost   new_name

After this, I just run sudo ls, and it worked quckly as usual.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .