How to Change Hostname on CentOS 7.0/RHEL 7.0

In web hosting environments, the ability to change the hostname of your server is a crucial skill. This tutorial is designed for webmasters and website administrators who are using CentOS 7.0 or RHEL 7.0 on their virtual private servers (VPS). The default hostname for these servers is usually set to localhost.localdomain, but there may be instances where you need to change this to a preferred hostname or Fully Qualified Domain Name (FQDN).

This guide will walk you through four different methods to change the hostname on your CentOS 7.0/RHEL 7.0 server. Each method is detailed and explained step-by-step, ensuring you can follow along regardless of your technical expertise.

Before we dive in, it’s worth noting that the importance of understanding your server’s hostname cannot be overstated. The hostname is a label assigned to a device connected to a computer network and is used to distinguish one device from another on a specific network or over the internet. Therefore, knowing how to change your server’s hostname can be beneficial in many ways, especially when managing multiple servers.

For more in-depth information about different types of web servers, you can visit our articles on Apache, Nginx, and LiteSpeed. If you’re interested in learning more about different types of hosting, we have comprehensive guides on dedicated, VPS, cloud, shared, and even blockchain hosting.

See also  How to Test Posfix Mail Service using Telnet

Let’s get started!

Method 1: Changing the Hostname Temporarily

Start by logging into your VPS as a root user.
Once logged in, type the command hostname followed by your new hostname.
For example:

[root@localhost ~]# hostname mynewhostname.local
[root@localhost ~]# hostname

Please note that this change will be lost after a system reboot.

Method 2: Changing the Hostname Permanently Using hostnamectl

Log into your VPS as a root user.
Use the hostnamectl set-hostname command followed by your new hostname to change the current hostname.
For example:

[root@localhost ~]# hostnamectl set-hostname

Restart the systemd-hostnamed daemon to make the changes permanent:

[root@localhost ~]# systemctl restart systemd-hostnamed

Verify the new hostname:

[root@localhost ~]# hostnamectl status
 Static hostname:
 Icon name: computer-vm
 Chassis: vm
 Machine ID: 72863e389b584a4dab36fae7f3bffda2
 Boot ID: 1cf2f4b5478649549916c0a5bd5d2414
 Virtualization: xen
 Operating System: CentOS Linux 7 (Core)
 CPE OS Name: cpe:/o:centos:centos:7
 Kernel: Linux 3.15.4-x86_64-linode45
 Architecture: x86_64

Method 3: Changing the Hostname by Modifying /etc/hostname

Log into your VPS as a root user.
Modify the /etc/hostname file using your preferred text editor. Replace localhost.localdomain with your preferred hostname or FQDN.
For example:

[root@ns1 ~]# vi /etc/hostname

Edit the file to include your new hostname:

Verify the change by opening another terminal session and typing hostname:

[root@ns1 ~]# hostname

Method 4: Changing the Hostname Using nmtui

Log into your VPS as a root user.
Type nmtui in the terminal.

[root@ns1 ~]# nmtui

A text user interface will appear.
Use the arrow keys to select “Set system hostname” and press tab to select OK.
A confirmation message will appear. Press OK to complete the change.

See also  How to Start, Stop, and Restart the PostgreSQL on a Linux CentOS System

Commands Mentioned

  • hostname – Displays the current hostname or sets a new one temporarily.
  • hostnamectl set-hostname – Sets a new hostname permanently.
  • systemctl restart systemd-hostnamed – Restarts the systemd-hostnamed daemon to apply the new hostname permanently.
  • vi /etc/hostname – Opens the /etc/hostname file for editing.
  • nmtui – Opens the NetworkManager’s Text User Interface.


Changing the hostname on your CentOS 7.0/RHEL 7.0 server is a straightforward process once you understand the steps involved. Whether you need to make a temporary change or a permanent one, this guide provides you with four different methods to accomplish this task.

Remember, the hostname of your server plays a crucial role in network identification. Therefore, it’s essential to ensure that it accurately represents your server’s purpose or function, especially when managing multiple servers.

We hope this tutorial has been informative and helpful. If you have any questions or need further assistance, feel free to reach out.

See also  How to Update CentOS 6.4 System using 'yum update'

Happy hosting!


  1. What is a hostname?

    A hostname is a label assigned to a device connected to a computer network. It is used to distinguish one device from another on a specific network or over the internet.

  2. Why would I need to change my server’s hostname?

    Changing your server’s hostname can be beneficial in many ways, especially when managing multiple servers. It allows you to easily identify and distinguish between different servers.

  3. What is the difference between a temporary and a permanent hostname change?

    A temporary hostname change will only last until the next system reboot, at which point the hostname will revert back to its previous state. A permanent hostname change, on the other hand, will persist even after a system reboot.

  4. What is the /etc/hostname file?

    The /etc/hostname file is a system configuration file in Linux that contains the hostname of the system. It is one of the files that can be edited to change the hostname permanently.

  5. What is nmtui?

    nmtui stands for NetworkManager Text User Interface. It is a command-line utility that provides a text interface to configure networking by controlling NetworkManager, which can be used to change the hostname among other things.


Leave a Reply

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