Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

在區域網路中架設 Linux 時間伺服器

編輯:Linux 教學

架構概覽

本文說明如何讓一台 Linux 主機作為區域網路(LAN)時間伺服器,向網際網路一/二級時間源同步,再為 LAN 內其他 Linux/Windows 用戶端提供時間服務。

伺服器端:與網際網路時間源同步

方法一:使用 xntpd (NTP 精確同步)

  1. 編輯 /etc/ntp.conf,設定 server(公開 NTP 伺服器)與 driftfile:
server rackety.udel.edu
server umd1.umd.edu
server lilben.tn.cornell.edu
driftfile /etc/ntp/drift
  1. 啟動服務:/etc/rc.d/init.d/xntpd start

方法二:使用 getdate (簡易同步,精度較低)

  1. 下載 getdate_rfc868 並安裝。
  2. 建立腳本 /usr/local/sbin/get-date.sh:
#!/bin/sh
timehosts="otc2.psu.edu wwvb.erg.sri.com ntp.nasa.gov"
if /usr/local/bin/getdate -adjust 10 200 $timehosts /dev/null; then
    /sbin/clock --systohc
fi
  1. 加入 crontab 每小時同步:0 * * * * /usr/local/sbin/get-date.sh

用戶端:向 LAN 時間伺服器同步

用戶端類型伺服器模式同步工具/指令
WindowsSamba 伺服器net time \\timeserver /set /yes(放入啟動項)
WindowsNTP (xntpd)ntptime、Nettime(支援 NTP/time 協定)
LinuxNTP (xntpd)ntpdate <server> 加入 cron
Windows/Linuxgetdate + inetd time 服務Windows 用 Nettime;Linux 用 rdate -s <server> 加入 cron

啟用 inetd time 服務(供 getdate 模式用)

編輯 /etc/inetd.conf,取消註解:

time stream tcp nowait root internal
time dgram udp wait.200 root internal

重啟 inetd 即可。

常見驗證指令

  • 確認 net time 走 NetBIOS over TCP/IP:tcpdump host <client_IP>
  • 確認 NTP 客戶端同步:tcpdump udp port 123
Copyright © Windows教程網 All Rights Reserved