Low Orbit Flux Logo 2 F

Linux How To Change Hostname

If you are setting up or managing a Linux system there is a good chance that you will want to change the hostname at some point. Fortunately this is relatively easy to do.

If you are running systemd ( modern Ubuntu/Debian systems, Arch, Red Hat, etc. ) you can use the hostnamectl command to change your hostname like this. This will immediately change the hostname and update the configuration in the /etc/hostname file but may not necessarily update the /etc/hosts file for you.

Update your hostname with systemd:


hostnamectl set-hostname zippy-zap

Check that the hostname was updated:


hostname

Alternative Method to Change Hostname on Linux

You can also use these steps.

Change your hostname now with this command:


sudo hostname zippy-zap

Change the hostname in this file ( swap old name for new ):


sudo nano /etc/hostname

Change it in this file as well ( swap old name for new ):


sudo nano /etc/hosts

Reboot to make sure that your configs are valid and that the change will survive a reboot.


sudo reboot

Check your hostname to verify that it was in fact changed to what you want.


hostname