Changing your server's hostname is a routine but important system administration task. Your hostname is used to identify the server on a network, and in hosting environments like cPanel, it must be set correctly for licensing and email services to work properly.
Step 1: Change the Hostname (Temporarily)
Run the following command as root or with sudo
:
hostname servername.yourdomain.com
To verify the change:
hostname
hostnamectl status
Looking for a reliable service provider? Bacloud offers high-performance VPS and Bare Metal servers in multiple locations worldwide. Whether you need scalable virtual environments or dedicated hardware, Bacloud ensures flexibility, speed, and quick support to meet your hosting needs.
Get a VPS
Step 2: Set the Hostname Permanently
For Systemd-based Systems (CentOS 7+, RHEL 7+, Ubuntu 16.04+):
hostnamectl set-hostname servername.yourdomain.com
For CentOS 6 or older:
vi /etc/sysconfig/network
Set or modify:
HOSTNAME=servername.yourdomain.com
Also update /etc/hosts
:
127.0.0.1 servername.yourdomain.com servername
For Debian/Ubuntu:
sudo nano /etc/hostname
Replace with:
servername.yourdomain.com
sudo nano /etc/hosts
127.0.1.1 servername.yourdomain.com servername
Step 3: Resync cPanel License
If you’re running cPanel/WHM, run:
/usr/local/cpanel/cpkeyclt
Optional: Update Hostname in WHM
Go to: WHM → Networking Setup → Change Hostname
Additional Recommendations
- Ensure Reverse DNS (PTR) record matches your new hostname.
- Regenerate SSL certificates if hostname is used in services like mail/WHM.
- Update hostname in your monitoring/logging systems.
Summary
Task | Command |
---|---|
Temporary change | hostname servername.yourdomain.com |
Permanent change (systemd) | hostnamectl set-hostname servername.yourdomain.com |
Resync cPanel license | /usr/local/cpanel/cpkeyclt |
Update hosts file | Edit /etc/hosts , /etc/hostname or /etc/sysconfig/network |