Changing the hostname on CentOS and Ubuntu is an easy task, just follow our guide carefully and you should have the hostname changed on CentOS or Ubuntu in less than 5 minutes. The hostname is used to identify the server when connected on a network and it is configured during the initial server setup. Changing the initial server hostname is a task that you might like to perform while you are using the server and in this tutorial, we will show you how to change the hostname on a Linux VPS running CentOS 7 or Ubuntu 16.04 as an operating system.
Table of Contents
1. What is a hostname?
Hostname is a label used to identify the machine and will help you to easily distinguish the server from another one. The hostname should be a Fully Qualified Domain Name (FQDN) and should point to the server IP address so you can access the server by using it.
2. Check the current hostname on CentOS or Ubuntu
Changing the hostname is a fairly simple process and requires only a few minutes of your time. You will need to connect to your server via SSH in order to be able to make that change.
Once you log in you should determine the current hostname. If you are using a CentOS 7 VPS or an Ubuntu 16.04 VPS, you can use the hostnamectl
command.
# hostnamectl status
The status output should be very similar to the one below:
Static hostname: vps.server.com Icon name: computer-container Chassis: container Machine ID: * * * Boot ID: * * * Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 2.6.32-042stab120.3 Architecture: x86-64
The value static hostname is the value you should look at.
3. Change the current hostname on CentOS or Ubuntu
To change the hostname on your CentOS or Ubuntu machine you should run the following command:
# hostnamectl set-hostname virtual.server.com
Please note that you need to replace virtual.server.com
with the new hostname you like to use.
Now, when you check the current hostname status using the command hostnamectl status
you will see the new hostname virtual.server.com
instead of the old one vps.server.com
. That means you have successfully changed the hostname on your server.
4. More command options
For more command options you can add the --help
flag at the end.
# hostnamectl --help hostnamectl [OPTIONS...] COMMAND ... Query or change system hostname. -h --help Show this help --version Show package version --no-ask-password Do not prompt for password -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container --transient Only set transient hostname --static Only set static hostname --pretty Only set pretty hostname Commands: status Show current hostname settings set-hostname NAME Set system hostname set-icon-name NAME Set icon name for host set-chassis NAME Set chassis type for host set-deployment NAME Set deployment environment for host set-location NAME Set location for host
Of course you don’t have to change the hostname on CentOS or Ubuntu if you use one of our VPS hosting services, in which case you can simply ask our expert Linux admins to change hostname on CentOS and Ubuntu, for you. They are available 24×7 and will take care of your request immediately. Changing the hostname on CentOS and Ubuntu is an easy task if you followed this guide carefully.
PS. If you liked this post, on how to change hostname on CentOS and Ubuntu, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.