Validation

validation

How to Change the server (hostname) in Ubuntu

Changing the hostname (computer name) in Ubuntu can be done through various methods. Keep in mind that altering the hostname might require a system reboot for the changes to take effect. Here’s a detailed guide on how to change the hostname in Ubuntu.

Changing the Hostname via the Command Line:

1) Open the Terminal:

Press Ctrl + Alt + T to open the terminal.

2) Check the Current Hostname:

Execute the following command:

hostname

3) Modify the Hostname:

Edit the /etc/hostname file using a text editor, e.g., using nano:

sudo nano /etc/hostname

Replace the current hostname with the new one and save the changes ( ctrl + x ).

Это изображение имеет пустой атрибут alt; его имя файла - name-server.jpg

4) Update the Hostname in the hosts file:

Edit the /etc/hosts file:

sudo nano /etc/hosts

4) Apply the Changes:

Reboot the server to apply the new hostname:

sudo reboot



Changing the Hostname using hostnamectl command:

1) Check the Current Hostname:

hostnamectl

2) Modify the Hostname:

sudo hostnamectl set-hostname new_hostname

3) Apply the Changes:

sudo systemctl restart systemd-hostnamed

Or, reboot the server.



Verify the Changes:

After the server reboot, check if the changes have taken effect:

hostname

You should now see the new hostname.

Changing the hostname in Ubuntu is a standard procedure, but be aware that some programs and services may rely on the hostname. Therefore, exercise caution when making these changes in a production environment, and test in a safe environment before applying them.