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

Ignore _site Build Directory in Eleventy

How to ignore the build output when adding it to gitignore causes problems.

May 04, 2020

WTF is a Closure?

A brief explanation of JavaScript closures, along with a few examples and references to other in-depth explorations on the topic.

Aug 03, 2020

How to Use Netlify Forms in a Gatsby Project

Netlify form handling is an extremely powerful feature that enables you to collect dynamic data from your users on your static sites. But it's a little tricky to get it working right within a Gatsby project. Here's a detailed look at a couple different ways of approaching Netlify forms for a Gatsby site.

May 06, 2019