快轉到主要內容

ntp-server

·319 字·1 分鐘·
PolloChang
作者
PolloChang
我是一隻雞

部屬 NTP Server
#

Oracle Linux 7
#

  • 安裝 ntp 服務
1
yum install ntp
  • /etc/ntp.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#  先拒絕IPv4 & IPv6的用戶存取服務
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

#  設定需要的時間伺服器進入
restrict 118.163.81.61
restrict 118.163.81.63
restrict 211.22.103.157

#  允許本機與相關網段
restrict 127.0.0.1 
restrict ::1
restrict 192.168.56.0 mask 255.255.255.0 nomodify


#  設定校時用的Server,perfer為最優先
server 118.163.81.61 prefer
server 118.163.81.63
server 211.22.103.157
1
2
systemctl enable --now ntpd
firewall-cmd --add-port=123/udp --permanent && systemctl restart firewalld
  • 檢查有設定成功
1
ntpq -p

以下為檢查結果

1
2
3
4
5
6
[root@common-server ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*118-163-81-61.h 133.243.238.243  2 u   36   64   17    6.196   21.164   3.700
 118-163-81-63.h .FREQ.           1 u   31   64   17    5.608    6.353   3.006
 211-22-103-157. 133.243.238.163  2 u   31   64   17    6.611   16.182   1.64

Oracle Linux 8
#

1
sudo yum install chrony -y
  • /etc/chrony.conf
1
2
3
4
5
# 編輯設定檔
sudo vi /etc/chrony.conf

# 找到並加入以下行(例如允許 192.168.1.0/24 網段)
allow 192.168.1.0/24
1
sudo systemctl enable --now chronyd
1
chronyc sources
1
2
3
# 開啟防火牆 UDP 123 埠並重新載入
sudo firewall-cmd --add-port=123/udp --permanent 
sudo firewall-cmd --reload
1
2
# 檢查連線到此伺服器的客戶端
chronyc clients