Technology Encyclopedia Home >Why does the NTP service configuration report an error of localhost.localdomain timeout? How to fix it?

Why does the NTP service configuration report an error of localhost.localdomain timeout? How to fix it?

The NTP service configuration may report a "localhost.localdomain timeout" error due to several reasons, such as incorrect NTP server settings, network connectivity issues, or misconfigured hostname resolution.

Possible Causes and Fixes:

  1. Incorrect NTP Server Configuration

    • If the NTP service is configured to use localhost.localdomain as the server, it may fail because localhost typically refers to the local machine, which is not an NTP server unless the NTP daemon (ntpd or chronyd) is running locally.
    • Fix: Replace localhost.localdomain with a valid NTP server address (e.g., pool.ntp.org or a public NTP server like time.google.com).

    Example (for ntpd):
    Edit /etc/ntp.conf and replace:

    server localhost.localdomain
    

    With:

    server pool.ntp.org
    

    Example (for chronyd):
    Edit /etc/chrony.conf and replace:

    server localhost.localdomain
    

    With:

    server pool.ntp.org
    
  2. Network or DNS Resolution Issues

    • If the system cannot resolve localhost.localdomain or connect to the NTP server due to network restrictions, the timeout occurs.
    • Fix:
      • Ensure the system has proper DNS resolution (check /etc/resolv.conf).
      • Test connectivity using ping or telnet to the NTP server (e.g., telnet pool.ntp.org 123).
      • If behind a firewall, ensure UDP port 123 is open.
  3. Local NTP Service Not Running

    • If localhost.localdomain was mistakenly used as a placeholder for a local NTP server, but ntpd or chronyd is not running, the timeout occurs.
    • Fix: Start the NTP service:
      systemctl start ntpd      # For ntpd
      systemctl start chronyd   # For chronyd
      
  4. Using Tencent Cloud NTP Service (Recommended for Cloud Environments)

    • If deploying in Tencent Cloud, it's recommended to use Tencent Cloud’s NTP service (time.tencent.com) for better synchronization and reliability.
    • Fix: Configure NTP to use Tencent Cloud’s NTP servers:
      Example (for ntpd):
    server time.tencent.com
    

    Example (for chronyd):

    server time.tencent.com
    

After making changes, restart the NTP service:

systemctl restart ntpd      # For ntpd
systemctl restart chronyd   # For chronyd

Verify synchronization with:

ntpq -p      # For ntpd
chronyc sources -v  # For chronyd