CentOSLinuxTutorials

How To Change Hostname on CentOS 8

Change Hostname on CentOS 8

In this tutorial, we will show you how to change the hostname on your CentOS 8. Before we dive into the process of changing the hostname, let’s first understand what a hostname is and its significance in CentOS 8. A hostname is a label assigned to a device on a network that uniquely identifies it. CentOS 8 distinguishes between three types of hostnames: static, pretty, and transient. The static hostname is the traditional hostname set in the /etc/hostname file, while the pretty hostname is a user-friendly name that can contain spaces and special characters. The transient hostname is a dynamic hostname that can change based on network conditions. By default, during the installation of CentOS 8, a hostname is automatically assigned based on the system’s IP address or the value provided by the user.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. If you are ready open up your terminal and follow through with this tutorial, and in less than 10 minutes you will have changed your hostname on a CentOS 8 server.

Prerequisites

  • A server running one of the following operating systems: CentOS 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Change Hostname on CentOS 8

Step 1. First I will check the current hostname by running “hostnamectl status” on the shell of my server:

hostnamectl status

Output:

 Static hostname: localhost.localdomain
       Icon name: computer-vm
         Chassis: vm
      Machine ID: d89865d34b5a4637a9a4ff0ce0f6da02
         Boot ID: 56d1685056d743b39e57a7b9cbfe467c
  Virtualization: oracle
Operating System: CentOS Linux 8 (Core)
     CPE OS Name: cpe:/o:centos:centos:8
          Kernel: Linux 4.18.0-80.el8.x86_64
    Architecture: x86-64

Step 2. Change and Set Hostname.

To change the hostname type the command:

[root@idroot ~]# hostnamectl set-hostname server.example.com

Recheck the hostname (Close the session and open a new session using the console):

[root@idroot ~]# hostnamectl status

Output:

   Static hostname: server.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d89865d34b5a4637a9a4ff0ce0f6da02
           Boot ID: 56d1685056d743b39e57a7b9cbfe467c
    Virtualization: oracle
  Operating System: CentOS Linux 8 (Core)
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-80.el8.x86_64
      Architecture: x86-64

In each of these configurations, you’ll need to be sure your hostname conforms to the standards for FQDNs (Fully Qualified Domain Names). The ASCII letters a – z, the digits 0 – 9, and the hyphen (‘-‘) are the only characters acceptable (the first character, however, cannot be a hyphen). You may also find it necessary (or useful) to include the domain name as well, in which case you would then also use periods (dots) to separate the hostname and the domain name (and top-level domain).

Congratulations! You have successfully changed the hostname. Thanks for using this tutorial on how to change and set the hostname on your CentOS 8 system. For additional help or useful information, we recommend you check the official CentOS website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button