Ubuntu – How to Change Hostname Without Rebooting

1. Update the current hostname

This command will instantly update the hostname which prevents having to reboot. It is not, however, persistent so your changes will be lost the next time you do reboot.

2. Update hostname File

Delete the current hostname and replace it with yours. This makes the new hostname persist when you reboot.

3. Update hosts File

If the new hostname isn’t added to the hosts file the sudo command won’t function properly.

Add the following on a new line after the localhost line:

Your hosts file should look similar to the following: