You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让ntpd仅以本地时间为参考,并同步指定Linux服务器的自定义时间?

Got it, let's walk through exactly how to set up this isolated pseudo-time NTP setup—no external time sources, just your custom server acting as the single reference. We'll split this into server and client steps since both need specific configurations.

Server Side Configuration (1.2.3.4)

First, we need to make sure your server ignores all external NTP sources and uses its own local clock as the authoritative time reference.

  1. Edit the NTP config file /etc/ntp.conf:

    • Comment out all existing pool or server lines that point to external NTP servers (like pool 0.ubuntu.pool.ntp.org iburst).
    • Add these lines to enable the local clock as the only time source:
      server 127.127.1.0  # Local clock driver (pseudo-time reference)
      fudge 127.127.1.0 stratum 10  # Assign a stratum level so clients trust this source
      
    • Add a rule to allow your client device(s) to access this NTP server:
      restrict 192.168.x.y mask 255.255.255.255 nomodify notrap  # Replace with your client's actual IP
      # For a whole subnet, use: restrict 192.168.x.0 mask 255.255.255.0 nomodify notrap
      
    • Keep the default localhost restrictions (they're needed for the server's internal NTP operations):
      restrict 127.0.0.1
      restrict ::1
      
  2. Set and lock your custom pseudo-time:

    • First, set the desired time:
      date -s "2033-02-23 15:23:10"
      
    • Save this time to the hardware clock so it persists after a reboot:
      hwclock -w
      
  3. Restart the NTP service and enable it on boot:

    systemctl restart ntpd
    systemctl enable ntpd
    
Client Side Configuration

You already ran ntpdate 1.2.3.4 for a one-time sync—now let's set up automatic, ongoing synchronization to your custom server.

  1. Edit /etc/ntp.conf on the client:

    • Comment out all external pool or server lines.
    • Add your custom server as the only time source:
      server 1.2.3.4 iburst  # "iburst" speeds up the initial sync process
      
    • Keep the default localhost restrictions.
  2. Restart the client's NTP service and enable auto-start:

    systemctl restart ntpd
    systemctl enable ntpd
    
  3. Verify the sync is working:
    Run ntpq -p—you should see 1.2.3.4 listed as the only peer, with an asterisk (*) next to it once synchronization is complete.

If your client uses Chrony (common on RHEL 8+, Ubuntu 20.04+):

If you're using Chrony instead of ntpd, adjust these steps:

  1. Edit /etc/chrony.conf:
    • Comment out all pool lines.
    • Add:
      server 1.2.3.4 iburst
      
  2. Restart and enable Chrony:
    systemctl restart chronyd
    systemctl enable chronyd
    
  3. Verify with chronyc sources—your server will be marked with a * when synced.
Critical Notes
  • Firewall Rules: Ensure both server and client allow UDP port 123 (NTP's default port). For firewalld users:
    # Server side:
    firewall-cmd --add-service=ntp --permanent
    firewall-cmd --reload
    
    # Client side (if outbound NTP is blocked):
    firewall-cmd --add-service=ntp --permanent
    firewall-cmd --reload
    
  • Double-Check Configs: Make sure no external NTP sources are left uncommented in either server or client configs—this ensures your pseudo-time stays isolated.

内容的提问来源于stack exchange,提问作者Victor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:05:19