Learn how to permanently change the hostname on Ubuntu. Our Server Management Support team is here to help you with your questions and concerns.
How to Permanently Change the Hostname on Ubuntu
Did you know that changing the hostname on your Ubuntu system is as easy as 1-2-3 and can be done without rebooting?
Our experts have put together these steps to help you out:
- First, we have to check the current hostname. So, open a terminal.
- Then, run this command:
hostnamectl
Copy CodeThis command displays the current hostname along with other system information like architecture and kernel version.
- Then, run the following command to change the hostname:
sudo hostnamectl set-hostname newhostname
Copy CodeRemember to replace `newhostname` with our desired hostname.
This command changes the static (standard), transient (dynamic), and pretty (descriptive) hostnames all at once.
- Furthermore, we can change certain types of hostnames using additional options:
- Static Hostname:
sudo hostnamectl set-hostname --static newhostname
Copy Code
This updates the `/etc/hostname` file with the new static hostname without changing the transient or pretty hostnames. - Transient Hostname:
sudo hostnamectl set-hostname --transient newhostname
Copy Code - Pretty Hostname:
sudo hostnamectl set-hostname --pretty "New Hostname"
Copy Code
Note that the pretty hostname can contain spaces and special characters, while static and transient hostnames should stick to letters, numbers, and hyphens.
- Static Hostname:
- After changing the hostname, verify it by running:
hostnamectl
Copy Code - If the hostname hasn’t changed, we may need to restart the `systemd-hostnamed` service:
sudo systemctl restart systemd-hostnamed
Copy Code
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
In brief, our Support Experts demonstrated how to permanently change the hostname on Ubuntu.
0 Comments