本文說明如何讓一台 Linux 主機作為區域網路(LAN)時間伺服器,向網際網路一/二級時間源同步,再為 LAN 內其他 Linux/Windows 用戶端提供時間服務。
/etc/ntp.conf,設定 server(公開 NTP 伺服器)與 driftfile:server rackety.udel.edu server umd1.umd.edu server lilben.tn.cornell.edu driftfile /etc/ntp/drift
/etc/rc.d/init.d/xntpd startgetdate_rfc868 並安裝。/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
0 * * * * /usr/local/sbin/get-date.sh| 用戶端類型 | 伺服器模式 | 同步工具/指令 |
|---|---|---|
| Windows | Samba 伺服器 | net time \\timeserver /set /yes(放入啟動項) |
| Windows | NTP (xntpd) | ntptime、Nettime(支援 NTP/time 協定) |
| Linux | NTP (xntpd) | ntpdate <server> 加入 cron |
| Windows/Linux | getdate + inetd time 服務 | Windows 用 Nettime;Linux 用 rdate -s <server> 加入 cron |
編輯 /etc/inetd.conf,取消註解:
time stream tcp nowait root internal time dgram udp wait.200 root internal
重啟 inetd 即可。
tcpdump host <client_IP>tcpdump udp port 123