Display the Current Hostname
- Enter one of the following commands
$ hostname
or
$ hostnamectl
Change the Hostname
- Edit /etc/hostname using nano or vi/vim text editor
$ sudo vim /etc/hostname
- Delete the old hostname and set the new hostname
- Repeat the process with any instances of the old hostname in /etc/hosts
$ sudo vim /etc/hosts
- Reboot the system for the changes to take effect
Change the Hostname without Rebooting
- Type the following to set the hostname
$ sudo hostname new-hostname
or
$ sudo hostnamectl set-hostname new-hostname
- Repeat the above steps to update /etc/hostname and /etc/hosts
Was this helpful?
0 / 0