How to Change the Hostname on Ubuntu Server

Got an ugly command prompt? Learn how to change the name of your computer.

To change the hostname on an Ubuntu server, you need to edit two files:

  1. /etc/hostname
  2. /etc/hosts

You'll need root permissions to edit. So, for #1:

$ sudo vim /etc/hostname

Note: Replace vim with the editor of your choice.

This file should just contain your hostname, so you can change the old name to the new name, then save and quit.

Next file:

$ sudo vim /etc/hosts

You probably see something like this near the top of the file:

/etc/hosts       localhost old_server_name

# ...

Here change what you find at old_server_name to your new hostname.

And reboot.

$ sudo reboot

Let's Connect

Keep Reading

The Best Thing about Jamstack

In exploring the artifacts of the early Jamstack movement, I’ve come to discover the best part of the Jamstack. This now guides how I describe Jamstack.

May 18, 2022

Use Dynamic Property Maps over Switch Case Statements

An everyday JavaScript pattern to avoid clunky switch-case statements and unnecessary if conditionals.

May 19, 2022

What Made the Essence of Jamstack Possible

The Jamstack may have been born out of pain, but it couldn't have existed without the convergence of a few key factors.

Oct 07, 2021