Configuring the hostname and DNS settings in cPanel is typically a task performed by server users with root access, often through WHM (Web Host Manager) rather than cPanel itself, as cPanel is primarily for end-users. Below are step-by-step instructions for setting up a hostname and configuring DNS settings, assuming you have access to WHM.
If you’re a cPanel user with root access you can configure as below:
The hostname is a fully qualified domain name (FQDN) used to identify your server:
Here’s how to set it up:
Using WHM (Root Access)
Log in to WHM:
Access WHM via
Log in with your root credentials.
Navigate to Change Hostname:
In the WHM search bar, type Change Hostname.
Select Change Hostname under the Networking Setup category.
Set the Hostname:
Enter the desired hostname (e.g., xyz.com).
Ensure it follows the FQDN format: subdomain.domain.com.
Avoid using www or reserved names like cpanel, mail, or webmail.
Save Changes:
Click Change.
WHM will update the hostname and configure necessary server files (e.g., /etc/hosts).
Verify the Hostname:
Open a terminal (via SSH) and run:
bash
Copy
hostname
It should return the new hostname (e.g., server.example.com).
Using Terminal (If No WHM Access)
Log in to the Server via SSH:
Use a tool like PuTTY or your terminal to connect as the root user.
Set the Hostname:
Run the following command, replacing xyz.com with your desired hostname:
bash
Copy
hostnamectl set-hostname server.example.com
Update /etc/hosts:
Edit the hosts file:
bash
Copy
nano /etc/hosts
Add or modify the entry to include:
bash
Copy
127.0.0.1 localhost
your-server-ip server.example.com
Save and exit (Ctrl+O, Enter, Ctrl+X).
Restart Networking (Optional):
On some systems, restart the network service:
bash
Copy
systemctl restart network
DNS settings ensure the hostname and domain resolve correctly. This involves setting up DNS records (A, MX, CNAME, etc.) and configuring nameservers.
Option 1: Using WHM to Manage DNS Zones
Log in to WHM:
Access WHM as described above.
Edit Zone for the Hostname’s Domain:
In the WHM search bar, type Edit Zone.
Select Edit Zone Templates or Edit DNS Zone.
Choose the domain associated with your hostname (e.g., example.com).
Add DNS Records:
Ensure the following records exist or add them:
A Record for the hostname:
text
Copy
server.example.com. 14400 IN A your-server-ip
NS Records (if running your own nameservers):
text
Copy
example.com. 86400 IN NS ns1.example.com.
example.com. 86400 IN NS ns2.example.com.
A Records for Nameservers (if applicable):
text
Copy
ns1.example.com. 14400 IN A your-server-ip
ns2.example.com. 14400 IN A your-secondary-ip
MX Record (for email):
text
Copy
example.com. 14400 IN MX 0 mail.example.com.
CNAME Records (for services like mail, ftp):
text
Copy
mail.example.com. 14400 IN CNAME server.example.com.
Save Changes:
Click Save or Save Changes.
Allow 24–48 hours for DNS propagation.
Verify DNS:
Use a tool like dig or an online DNS checker (e.g., MXToolbox):
bash
Copy
dig server.example.com
Option 2: Using cPanel (Limited DNS Access)
If you only have cPanel access (no WHM), you can manage DNS for domains you control, but notthe server’s hostname or nameservers.
Log in to cPanel:
Access cPanel via or through your hosting provider’s portal.
Navigate to Zone Editor:
In cPanel, search for Zone Editor or Advanced DNS Zone Editor (depending on the cPanelversion).
Add/Edit DNS Records:
Add or modify records for your domain (e.g., example.com):
A Record:
Name: server.example.com
Address: your-server-ip
MX Record:
Name: example.com
Priority: 0
Destination: mail.example.com
CNAME Record:
Name: mail
CNAME: server.example.com
Save Changes:
Click Add Record or Save.
DNS changes may take 24–48 hours to propagate.
Option 3: Configure Nameservers
If you’re using your own nameservers (e.g., ns1.example.com, ns2.example.com):
Register nameservers with your domain registrar:
Log in to your registrar (e.g., GoDaddy, Namecheap).
Set custom nameservers (e.g., ns1.example.com, ns2.example.com).
Map them to your server’s IP addresses.
Update the domain’s nameservers:
In the registrar’s DNS settings, point the domain to ns1.example.com and ns2.example.com.
If using third-party DNS (e.g., Cloudflare, Google DNS):
Log in to your DNS provider.
Add the necessary A, MX, and CNAME records as described above.
Update your domain’s nameservers to the third-party provider’s nameservers (e.g., ns1.cloudflare.com).
SSL for Hostname:
Install an SSL certificate for the hostname to secure services like cPanel/WHM.
In WHM, go to Manage Service SSL Certificates and install a certificate (e.g., via AutoSSL or a purchased certificate).
Restart Services:
After DNS changes, restart services like BIND (DNS) or cPanel:
bash
Copy
systemctl restart named
systemctl restart cpanel
Test Connectivity:
Verify the hostname resolves correctly:
bash
Copy
ping server.example.com
Check DNS records with:
bash
Copy
dig +short server.example.com
Notes
Root Access Requirement: Changing the server’s hostname or managing DNS for the server itself requires root access via WHM or SSH. cPanel users can only manage DNS for their own domains.
Propagation Time: DNS changes take 24–48 hours to propagate globally.
Hosting Provider: If you lack root access, contact your hosting provider to configure the hostname or nameservers.
Backups: Before making changes, back up your DNS zones or server configuration.
If you need help with a specific step or encounter errors, let me know, and I can provide more detailed guidance!
Read Related Blog Post: https://blog.vcclhosting.com/how-dns-works-a-comprehensive-guide/: Configure Hostname & DNS Settings in cPanel