Unable to Access WHM After Changing Hostname - Error 521 and Connection Refused

Helposoft Staff

Administrator
Staff member
Points
178
The errors you're encountering suggest that there might be network issues preventing your server from connecting to external services, which could be causing the SSL certificate issue and the inability to connect to WHM.

Here are some steps to diagnose and potentially resolve the issue:

1. Check Network Connectivity

Ensure your server can reach external services:

Code:
ping google.com
curl -I https://acme-v02.api.letsencrypt.org/directory

If these commands fail, you have a network issue.

2. Check DNS Resolution

Ensure your DNS resolution is working properly:

Code:
cat /etc/resolv.conf

It should contain valid nameserver entries. You might want to use Google's public DNS for testing:

Code:
nameserver 8.8.8.8
nameserver 8.8.4.4

3. Check Firewall Settings

Ensure that your firewall is not blocking outbound connections:

Code:
firewall-cmd --list-all
iptables -L

If necessary, temporarily disable the firewall to test connectivity:

Code:
systemctl stop firewalld

4. Check Hostname Configuration

Ensure that your hostname and /etc/hosts entries are correctly configured. Your /etc/hosts file looks fine, but let's double-check the hostname:

hostnamectl set-hostname hostname.domain.com

5. Restart Network Services

Restart the network service to ensure all changes take effect:

Code:
systemctl restart network

6. Check cPanel and WHM Services

Make sure cPanel and WHM services are running correctly:

Code:
systemctl status cpanel
systemctl status cpsrvd

7. Check SSL Certificates

Since the SSL certificate renewal failed, you can try to manually install a self-signed certificate or use a valid one if you have it. Here’s how to generate a self-signed certificate:

Code:
mkdir -p /etc/ssl/private
openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout /etc/ssl/private/server.key -out /etc/ssl/private/server.crt

Configure cPanel to use this certificate:

Code:
/usr/local/cpanel/bin/checkallsslcerts --force

8. Rebuild cPanel/WHM Configuration

Force a rebuild of cPanel and WHM configuration:

Code:
/usr/local/cpanel/scripts/upcp --force

9. Reboot the Server

Finally, reboot your server to ensure all changes take effect:

Code:
reboot

10. Additional Diagnostic Commands

Here are a few more commands that can help diagnose the issue:

  • Check logs for any additional errors:

    Code:
    tail -f /var/log/messages
    tail -f /usr/local/cpanel/logs/error_log

  • Verify that sshd is running and accessible:

    Code:
    systemctl status sshd

 

Helposoft Staff

Administrator
Staff member
Points
178
Encountered issues after changing the hostname on my cPanel/WHM server. Below are the steps I followed and the solution that worked for me:

Issue:

  • Changed the hostname to server-host.5ium.com in WHM.
  • Cannot access WHM via IP: ERR_CONNECTION_REFUSED.
  • Cannot access WHM via hostname: Web server is down Error code 521.
Steps to Resolve:

  1. Update /etc/hosts File:Edit the /etc/hosts file to map the server's IP address to the new hostname directly:

    Code:
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    31.172.xx.xxx hostname.domain.com hostname

  2. Rebuild cPanel/WHM Configuration:Run the following commands to rebuild the cPanel/WHM configuration and restart necessary services:

    Code:
    /usr/local/cpanel/cpkeyclt
    /scripts/rebuildhttpdconf
    /scripts/updateuserdomains
    systemctl restart cpanel
    systemctl restart httpd
    systemctl restart exim
    systemctl restart dovecot

  3. Verify Firewall Configuration:Ensure that the firewall is not blocking the necessary ports for cPanel/WHM:

    Code:
    firewall-cmd --permanent --add-port=2086/tcp
    firewall-cmd --permanent --add-port=2087/tcp
    firewall-cmd --permanent --add-port=2082/tcp
    firewall-cmd --permanent --add-port=2083/tcp
    firewall-cmd --permanent --add-port=2095/tcp
    firewall-cmd --permanent --add-port=2096/tcp
    firewall-cmd --reload

  4. Check Network Configuration:
    • Verify IP address assignment: ip addr show
    • Verify DNS configuration: nslookup server-host.5ium.com
    • Verify routing table: ip route show
  5. Check cPanel Ports:Ensure that cPanel ports are open and listening:

    Code:
    netstat -tulnp | grep 2087
    netstat -tulnp | grep 2086

  6. Check cPanel Service Status:Ensure all necessary cPanel services are running:

    Code:
    systemctl status cpanel
    systemctl status httpd
    systemctl status exim
    systemctl status dovecot

  7. Verify SSL/TLS Configuration:
    • Check SSL certificate: openssl s_client -connect 31.172.80.124:2087 -showcerts
    • Rebuild SSL certificate:
      Code:
      /usr/local/cpanel/bin/checkallsslcerts
  8. Reconfigure cPanel:
    • Run initial setup script:
      Code:
      /usr/local/cpanel/scripts/upcp --force
    • Run cPanel check script:
      Code:
      /usr/local/cpanel/scripts/check_cpanel_rpms --fix
  9. Inspect cPanel Logs: Check the cPanel logs for detailed error messages:

    Code:
    tail -f /usr/local/cpanel/logs/error_log

  10. Reboot the Server:Reboot the server to ensure all changes take effect:

    Code:
    reboot
After following these steps, the issue was resolved and I could access WHM without any errors. If you encounter similar issues, these steps might help resolve them.
 
Top