There are a few ways that the hostname can be modified from the command line. The first method is using cPanel's API:
whmapi1 sethostname hostname=hostname.domain.tld
Please remember that the hostname (here hostname.domain.tld) needs to be an FQDN.
Alternatively, there are other methods that the hostname can be changed using Linux's native utilities like the hostname command, the hostnamectl command, or by modifying the content of network-related files. However, we do not recommend these OS-level update methods because they will not change all the configuration files required by cPanel and WHM that contain the hostname.
Instead of the above API call, you can also use the WHM web interface to change the hostname. To see how to modify the hostname from the WHM interface you can visit this link:
https://support.cpanel.net/hc/en-us/articles/360044460594-Effective-Hostname-Usage-With-cPanel-WHM