Change a Machine's Hostname¶
Actually Change the Hostname¶
Using hostnamectl is the best way to change it, editing /etc/hostname directly is also possible, but not recommended.
Example:
Update the Network "pointer"¶
Even though the hostname is changed now, the networking still uses the old hostname.
So you need to edit the hosts file:
Then find the 2 lines that starts with 127.0.1.1 and contain your previous hostname.
For example, on Debian this looks like:
Some other distro use:
others use
What's used really doesn't matter, what matters is that you just have to replace the previous hostname with the new one.
The End¶
It is recommended that you reboot after that, however it isn't mandatory.
Your shell might still display your old hostname so you will have to restart it (so either reconnect the SSH connection, or close the terminal)