The set_hostname Utility

Valid for versions 90 through the latest version

Version:

90

Last modified: July 28, 2022


Overview

The /usr/local/cpanel/bin/set_hostname utility updates the server’s hostname and performs all of the necessary actions to apply this change throughout the system. You can use this utility to change the server’s hostname during a process that requires you to call the binary (for example, automated cloning processes).

You can also use the following methods to change the server’s hostname:

  • Use WHM’s Change Hostname interface (WHM » Home » Networking Setup » Change Hostname).

  • Use WHM API 1’s sethostname function.

If you use either of these methods, you do not need to run this utility.

Important:
  • Do not select a hostname that begins with www or a number, or a hostname that ends with a hyphen (-).

  • You must use a fully-qualified domain name (FQDN) that uniquely identifies the server (for example, hostname.example.com or hostname.example.co.uk).

  • Do not choose a hostname that a cPanel account on your server will use.

  • Do not choose a potential service subdomain as a hostname (for example, cpanel.example.com or whm.example.com).

  • Do not select a socially-unacceptable hostname. The hostname will appear in mail headers.

  • Only use lowercase, Latin-script letters in hostnames.

Note:
If your server currently uses a subdomain of cprapid.com as a hostname, we strongly encourage you to replace it with an existing domain or purchase a new domain to generate a hostname. Using your own domain name and hostname will help establish your company’s brand. For more information, read our Automatically-Issued Hostnames documentation.

Run the script

To use the /usr/local/cpanel/bin/set_hostname utility, run the following command as the root user, where newhostname.example.com represents your new hostname:

/usr/local/cpanel/bin/set_hostname newhostname.example.com [option]

You can specify the following option for the /usr/local/cpanel/bin/set_hostname utility:

  • --help — View utility information on the command line.

When you run this command, the set_hostname utility performs the following actions:

  • It updates the hostname in the /etc/sysconfig/network file, and in the kernel.
  • It updates the domain.
  • It updates the server’s Apache® configuration.
  • It updates the cPanel license.
  • It updates cPHulk.
  • It restarts MySQL®.
  • It rebuilds cPanel & WHM’s global cache.
  • It updates the FTP, Exim, Dovecot, and cPanel SSL certificates.

Example

To change the server’s hostname to hostname.example.com, run the following command:

/usr/local/cpanel/bin/set_hostname hostname.example.com

If the update succeeds, the utility produces the following output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Changing hostname to hostname.example.com...Success!

Hostname set to: hostname.example.com
Output during rename:

Altered hostname in /etc/sysconfig/network
Stopping MySQL during hostname change
Changing hostname in kernel to hostname.example.com
Updating Apache configuration

Updating cPanel license...Done. Update succeeded.
Building global cache for cpanel...Done

Self Signed SSL Certificate for ftp does not match current hostname! ([oldhostname.example.com] != hostname.example.com).
Creating new Certificate and Key for ftp....Done
Self Signed SSL Certificate for exim does not match current hostname! ([oldhostname.example.com] != hostname.example.com).
Creating new Certificate and Key for exim....Done
Self Signed SSL Certificate for dovecot does not match current hostname! ([oldhostname.example.com] != hostname.example.com).
Creating new Certificate and Key for dovecot....Done
Self Signed SSL Certificate for cpanel does not match current hostname! ([oldhostname.example.com] != hostname.example.com).
Creating new Certificate and Key for cpanel....Done
Updating cPHulkd

hulkdsetup: database schema is up to date.
Waiting for "mysql" to start ......waiting for "mysql" to initialize ......
...finished.

Startup Log
    Starting MySQL...[  OK  ]

Log Messages
    150123  9:53:45 [Note] /usr/sbin/mysqld: ready for connections.
    150123 09:53:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    150122 22:36:53 mysqld_safe mysqld from pid file /var/lib/mysql/hostname.example.com.pid ended
    150122 22:36:53 [Note] /usr/sbin/mysqld: Shutdown complete
    150122 22:36:51 [Note] /usr/sbin/mysqld: Normal shutdown
    150122 22:29:00 [Note] /usr/sbin/mysqld: ready for connections.
    150122 22:28:59 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    150122 22:28:58 mysqld_safe mysqld from pid file /var/lib/mysql/hostname.example.com.pid ended
    150122 22:28:58 [Note] /usr/sbin/mysqld: Shutdown complete
    150122 22:28:57 [Note] /usr/sbin/mysqld: Normal shutdown
    150122 22:28:44 [Note] /usr/sbin/mysqld: ready for connections.
    150122 22:28:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    150122 22:28:42 mysqld_safe mysqld from pid file /var/lib/mysql/hostname.example.com.pid ended
    150122 22:28:42 [Note] /usr/sbin/mysqld: Shutdown complete
    150122 22:28:41 [Note] /usr/sbin/mysqld: Normal shutdown
    150122 22:27:38 [Note] /usr/sbin/mysqld: ready for connections.
    150122 22:27:37 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    150122 22:27:36 mysqld_safe mysqld from pid file /var/lib/mysql/hostname.example.com.pid ended
    150122 22:27:36 [Note] /usr/sbin/mysqld: Shutdown complete
    150122 22:27:34 [Note] /usr/sbin/mysqld: Normal shutdown
    150122 22:23:19 [Note] /usr/sbin/mysqld: ready for connections.
    150122 22:23:18 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    150122 22:23:17 mysqld_safe mysqld from pid file /var/lib/mysql/hostname.example.com.pid ended
    150122 22:23:17 [Note] /usr/sbin/mysqld: Shutdown complete

mysql started successfully.

Additional Documentation