网络校时协议(NTP)的实现
时间服务器可以利用以下三种方式与其他服务器对时:
broadcast/multicast
client/server
symmetric
broadcast/multicast方式主要适用于局域网的环境,时间服务器周期性的以广播的方式,将时间信息传送给其他网路中的时间服务器,其时间仅会有少许的延迟,而且配置非常的简单。但是此方式的精确度并不高,对时间精确度要求不是很高的情况下可以采用。
symmetric的方式得一台服务器可以从远端时间服务器获取时钟,如果需要也可提供时间信息给远端的时间服务器。此一方式适用于配置冗余的时间服务器,可以提供更高的精确度给主机。
client/server方式与symmetric方式比较相似,只是不提供给其他时间服务器时间信息,此方式适用于一台时间服务器接收上层时间服务器的时间信息,并提供时间信息给下层的用户。
下面我们使用C/S模式来配置时间服务器
R1---S1/1------S1/0-----R2
R1:
Enable
config t
int s1/1
ip add 192.168.1.1 255.255.255.0
no shutdown
exit
exit
ntp master 1
clock set 11:11:22 28 feb 2025 定义时间服务器配置
R2:
Enable
Config t
Int s1/0
Ip add 192.168.1.2 255.255.255.0
No shutdown
exit
ntp server 192.168.1.1
测试:
R1:
R1#show ntp status
Clock is synchronized, stratum 1, reference is .LOCL.
nominal freq is 250.0000 Hz, actual freq is 250.0000 Hz, precision is 2**18
reference time is EB6C1875.916CE199 (11:11:49.568 UTC Fri Feb 28 2025)
clock offset is 0.0000 msec, root delay is 0.00 msec
root dispersion is 1875.02 msec, peer dispersion is 1875.02 msec
R1#show ntp ass
R1#show ntp associations
address ref clock st when poll reach delay offset disp
*~127.127.7.1 .LOCL. 0 0 64 37 0.0 0.00 875.0
* master (synced), # master (unsynced), + selected, - candidate, ~ configured
R1#show ntp ass
R1#show ntp associations
address ref clock st when poll reach delay offset disp
*~127.127.7.1 .LOCL. 0 33 64 377 0.0 0.00 0.0
* master (synced), # master (unsynced), + selected, - candidate, ~ configured
R1#
R2:测试
R2#show ntp status
Clock is unsynchronized, stratum 16, no reference clock
nominal freq is 250.0000 Hz, actual freq is 250.0000 Hz, precision is 2**18
reference time is CF2BD783.0E5FFAC2 (16:02:11.056 UTC Sun Feb 21 2010) 自己的时间
clock offset is 473972983432.2668 msec, root delay is 24.12 msec
root dispersion is 16647307.31 msec, peer dispersion is 16000.00 msec
R2#show ntp status
Clock is synchronized, stratum 2, reference is 192.168.1.1
nominal freq is 250.0000 Hz, actual freq is 250.0000 Hz, precision is 2**18
reference time is EB6C187E.7B036C35 (11:11:58.480 UTC Fri Feb 28 2025) 同步服务器时间
clock offset is -24.0640 msec, root delay is 8.13 msec
root dispersion is 1907.76 msec, peer dispersion is 1883.65 msec
R2#show ntp status
Clock is synchronized, stratum 2, reference is 192.168.1.1
nominal freq is 250.0000 Hz, actual freq is 250.0000 Hz, precision is 2**18
reference time is EB6C187F.7B031A89 (11:11:59.480 UTC Fri Feb 28 2025)
clock offset is -24.0640 msec, root delay is 8.13 msec
root dispersion is 910.51 msec, peer dispersion is 886.40 msec
R2#show ntp associations 显示NTP关联
address ref clock st when poll reach delay offset disp
*~192.168.1.1 .LOCL. 1 35 64 377 8.1 -68.09 6.3
* master (synced), # master (unsynced), + selected, - candidate, ~ configured
R2#
认证功能;
R1---S1/1------S1/0-----R2
R1:
Enable
config t
int s1/1
ip add 192.168.1.1 255.255.255.0
no shutdown
exit
exit
ntp master 1
clock set 11:11:22 28 feb 2025
ntp authenticate
ntp authentication-key 1 md5 cisco
ntp trusted-key 1
R2:
Enable
Config t
Int s1/0
Ip add 192.168.1.2 255.255.255.0
No shutdown
exit
ntp server 192.168.1.1
---------------------这个时候时间不同步。
clock set 11:11:22 28 feb 2025 R1---重新设置时间
R2上:
R2#show clock
11:14:04.032 UTC Fri Feb 28 2025
R2#show ntp status
Clock is synchronized, stratum 2, reference is 192.168.1.1
nominal freq is 250.0000 Hz, actual freq is 250.0003 Hz, precision is 2**18
reference time is EB6C18C9.774FEF65 (11:13:13.466 UTC Fri Feb 28 2025)
clock offset is -68.0938 msec, root delay is 8.13 msec
root dispersion is 110.03 msec, peer dispersion is 41.90 msec
然后在R2上做认证:
ntp authenticate
ntp authentication-key 1 md5 cisco
ntp trusted-key 1
再次测试:
R1#show clock
11:11:44.983 UTC Fri Feb 28 2025
R2#show clock
11:14:26.918 UTC Fri Feb 28 2025 时间服务器已经同步。(R1服务器,R2客户机)
转载于:https://blog.51cto.com/dnsdhcp/283744