Change a server's hostname in CentOS
By default, your server is started with the server’s given name as the hostname. Some software such as cPanel® requires a valid fully qualified domain name (FQDN) for the hostname to be used during their licensing verification system. This article describes how to change a server hostname in CentOS®.
Change a server’s hostname
Using a text editor, open the server’s /etc/sysconfig/network file. The following example shows how to open this file in the GNU nano text editor:
# sudo nano /etc/sysconfig/network
HOSTNAME=value to match your FQDN hostname, as shown in the following example:
Open the file at /etc/hosts. To update the information for internal networking, change the host that is associated with the main IP address for your server, as shown in the following example:
127.0.0.1 localhost localhost.localdomain 184.108.40.206 hostname.domain.com hostname ~ ~ ~ ~ -- INSERT -- 2,43-57 ALL
hostnamecommand. This command enables you to change the hostname on the server that the command line remembers, but it does not actively update all of the programs that are running under the old hostname. The following code provides an example:
[root@defiant ~]# hostnamectl set-hostname hostname.domain.com [root@defiant ~]# hostname hostname.domain.com [root@defiant ~]#
Use the following command to restart networking on your server to ensure that changes persist on restart:
# /etc/init.d/network restart
©2019 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License