0

Suddenly, my machine changed its hostname for unknown reason. I want to set the previous hostname. I can change hostname, very easily temporarily but not permantly! when I say hostname I mean the word that it appears at terminal after username eg. username@hostname :~$

What I did:

  • added "kernel.hostname = name" in /etc/sysctl.conf - no change after reboot.
  • echo 'name' > /proc/sys/kernel/hostname only temporarily change it
  • hostnamectl set-hostname name only temporarily change it
  • sudo hostname name only temporarily change it
  • cat /etc/hostname already contains "name"
  • sudo sysctl -w kernel.hostname=name - no change after reboot.

problems if change temporarily hostname from terminal when using sudo

  • Authorization required, but no authorization protocol specified
  • without changing current hostname system output cannot connect to display:0. This message is gone when I change (temporarily) hostname to the proper hostname. I believe somehow system has kept my previous hostname and it conflicts.

so, until now, i am out of options. any suggestion?

3
  • 1
    Out of curiosity. 1) What did the hostname suddenly change to? 2) Does it remain changed if you boot with network disabled? Commented Dec 4, 2023 at 13:41
  • I think after some thundestorm, hostname changed! Not tried with network disabled! Commented Dec 4, 2023 at 13:48
  • 1
    What distribution are you using? The answer may vary Commented Dec 4, 2023 at 14:15

2 Answers 2

1

For Debian distributions the primary point for changing the hostname is to edit /etc/hostname and /etc/hosts, and then reboot.

There may be secondary considerations within specific applications and subsystems. For example, here is one I consider on my systems:

  • Exim4 MTA subsystem: edit /etc/exim4/update-exim4.conf.conf or run dpkg-reconfigure exim4-config
0

I found out how to change hostname permantly. Changes in /etc/sysctl.conf are not automatically written to kernel!

However, after running

sudo sysctl -w kernel.hostname=name and/or
sudo nano /etc/sysctl.conf  to add `kernel.hostname=name`

Changes are applied to kernel by using

sudo sysctl -p --system -w

So, I think debian distributions something is missing here?

UPDATE: if your hostname is changing to easy or any other name than yours, please consider that: sudo nano /var/lib/dhcp/dhclient.enp3s0.leases and change it. If not there, sudo grep -rnw -e easy to find where it lies.

1
  • "Changes in /etc/sysctl.conf are not automatically written to kernel" - they are written at boot time Commented Dec 4, 2023 at 18:51

You must log in to answer this question.

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