How to Change / Rename Ubuntu 16.04 LTS Server Name

The hostname is a unique name that are assigned to a server. It’s how the server gets identified on the network. If you’d like to rename your server to give it another name, the steps below is a good place to start

When it comes to Ubuntu, there are two files that must be edited in order to change the hostname for a machine… these files are text files and easy to access. One thing to remember though, only the system administrator can make this change.

Accounts with sudo rights should also be able to make this change… After editing the file, reboot and your server should be identified with its new name on the network.

To change your server name, follow the steps below:

Step 1: Change the Server name in the Hostname File

There are two files that must be edited to successfully change Ubuntu computer name. These files are located in the /etc directory. They are:

/etc/hostname
/etc/hosts

To change Ubuntu name in the hostname file, run the commands below to open the file.. your account must have administrative rights to making changes to this file.

sudo nano /etc/hostname

Then change whatever name in there to be the server new name.

ubuntu 16.04 server name change

 

Save the file and exit.

Step 2: Change Server name in the Hosts File

The next file to edit is the hosts file. There you should also replace all the old computer name with the new one.. To open the hosts file, run the commands below…

sudo nano /etc/hosts

The first line is always going to be for localhost with the loopback IP address. The second line is where you change the hostname… If you want to reference the hostname with the server public IP address and not the loopback, you can add a third line with server public IP and hostname.

ubuntu 16.04 server name change

 

Save the file and exit.

Step 3: Restart the Server

Finally, restart the server for the new name to apply… If you don’t restart, the new name will not properly be applied. Run the commands below to restart the server.

sudo reboot

When you log back on, type hostname and the new computer name should be displayed.

This is how one changes or renames Ubuntu servers

You may also like the post below:

VirtualBox 5.2 on Ubuntu 16.04 LTS Server (Headless)

One Reply to “How to Change / Rename Ubuntu 16.04 LTS Server Name”

  1. this didn’t work. my hostname is still the old.

    i also tried hostnamectl and even created cloud.cfg and all failed

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.