Changing the hostname of your server may be necessary for several reasons. For example, if you are utilizing your server as a Mail Server for your domain(s) hosted, then changing the hostname can prevent your emails from going to Spam/Junk. In this article, you can learn how to change your server's hostname from the command line.
Before You Begin
Review the warnings and notes below, to ensure a smooth transition from one hostname to another.
NOTE: Your hostname will be viewable in every email header, so choose wisely.
NOTE: Your hostname must be in the format of a subdomain (server.example.com).
NOTE: Avoid choosing a subdomain that you are currently (or plan on) hosting in a cPanel account.
NOTE: Changing your hostname will require an update of the SSL Certificate for services (such as cPanel/Webmail, FTP, Dovecot (SMTP/IMAP), etc.).
NOTE: Changing your hostname will require an update to all references of the previous hostname in your connection(s) to the server (such as IMAP/SMTP/POP, FTP, and remote MySQL clients) with the new hostname.
The new hostname will remain as assigned until your server is restarted. In order for this change to persist through restarts, our Systems Administrator will need to update your hostname. Once you have changed the hostname in WHM, you can contact our Live Support
to request an update to your hostname.
Our Systems Administrator will need to update the IP address Pointer (PTR) record
on your behalf. Once you have changed the hostname in WHM, you can submit a ticket
to request an update to your PTR.
SSH into your server using the root user.
Run the following command:
The prompt should appear, without any output being displayed. You can run the following command to confirm the hostname has been changed:
The output should display similarly to the example below:
firstname.lastname@example.org ~ $ hostname
Congratulations! Now you know how you can change the hostname of your server from the command line.