Terminal

Bash scripts, command line tips, etc.

Change hostname on Ubuntu

Debian-based systems like Ubuntu use the file /etc/hostname to read the hostname of the computer at boot time and sets it up using the init script /etc/init.d/hostname.sh. We can edit the file, change the hostname and then run the script to change it for the current session (or just reboot).


Steps (to be performed as root):

  1. Run nano /etc/hostname
  2. Save the file with the hostname you like
  3. Edit nano /etc/hosts and again change the hostname
  4. Reboot or run service hostname restart