配置带验证的单播NTP服务器/客户端模式示例
客户端必须先使能NTP验证,然后再指定NTP服务器地址,并同时指定发给服务器的验证密钥。如果认证失败,将不会同步。客户端和服务器端都需要进行完整的配置,才能验证通过。
组网需求
如图5-3所示。
DeviceA作为NTP单播服务器,其本地时钟作为NTP主时钟,层数为2。
DeviceB作为NTP客户端,同步远端服务器DeviceA的时钟。
DeviceC和DeviceD作为NTP客户端,把DeviceB作为自己的NTP服务器。
在所有路由器启用NTP验证。
本例中interface1和interface2分别代表GE0/1/0和GE0/2/0。
配置注意事项
- 客户端必须先使能NTP验证,然后再指定NTP服务器地址,并同时指定发给服务器的验证密钥。否则将不进行验证,直接同步。
- 客户端与服务器端必须配置相同的验证密钥,并声明该密钥可信,否则无法通过验证。
- 客户端和服务器端都需要进行完整的配置,才能验证通过。
- 在所有路由器启用NTP验证。
配置思路
采用如下思路进行此案例的配置:
配置DeviceA作为服务器,提供主时钟。
配置DeviceB作为NTP客户端,同步DeviceA的时钟。
配置DeviceC、DeviceD作为NTP客户端,同步DeviceB的时钟。
在DeviceA、DeviceB、DeviceC和DeviceD上配置NTP验证。
操作步骤
- 配置各设备间路由可达(略)。
- 配置各路由器的IP地址并路由可达。具体配置过程略。
- 在DeviceA配置NTP主时钟并启动验证功能
# 在DeviceA上指定使用自己的本地时钟作为参考时钟,层数为2。
<DeviceA> system-view [~DeviceA] ntp-service refclock-master 2
# 在DeviceA上使能NTP验证功能、配置验证密钥并声明该密钥可信。
[*DeviceA] ntp-service authentication enable [*DeviceA] ntp-service authentication-keyid 42 authentication-mode md5 Hello123 [*DeviceA] commit
说明:
注意服务器端与客户端必须配置相同的验证密钥。
- 在DeviceB指定NTP服务器并启动验证功能
# 在DeviceB上使能NTP验证功能、配置验证密钥并声明该密钥可信。
<DeviceB> system-view [~DeviceB] ntp-service authentication enable [*DeviceB] ntp-service authentication-keyid 42 authentication-mode md5 Hello123 [*DeviceB] ntp-service reliable authentication-keyid 42
# DeviceB指定DeviceA为NTP服务器,并使用已配置的验证密钥。
[*DeviceB] ntp-service unicast-server 2.2.2.2 authentication-keyid 42 [*DeviceB] commit
- 在DeviceC指定NTP服务器并启动验证功能
# DeviceC指定DeviceB作为自己的NTP服务器。
<DeviceC> system-view [~DeviceC] ntp-service authentication enable [*DeviceC] ntp-service authentication-keyid 42 authentication-mode md5 Hello123 [*DeviceC] ntp-service reliable authentication-keyid 42 [*DeviceC] ntp-service unicast-server 10.0.0.1 authentication-keyid 42 [*DeviceC] commit
- 在DeviceD指定NTP服务器并启动验证功能
# DeviceD指定DeviceB作为自己的NTP服务器。
<DeviceD> system-view [~DeviceD] ntp-service authentication enable [*DeviceD] ntp-service authentication-keyid 42 authentication-mode md5 Hello123 [*DeviceD] ntp-service reliable authentication-keyid 42 [*DeviceD] ntp-service unicast-server 10.0.0.1 authentication-keyid 42 [*DeviceD] commit
- 验证配置结果
完成上述配置后,DeviceB可以同步到DeviceA的时间。
查看DeviceB的NTP状态,可以看到时钟状态为“synchronized”,即,已经完成同步。时钟的层数为3,比服务器DeviceA低1级。
[~DeviceB] display ntp-service status clock status: synchronized clock stratum: 3 reference clock ID: 2.2.2.2 nominal frequency: 60.0002 Hz actual frequency: 60.0002 Hz clock precision: 2^18 clock offset: 3.8128 ms root delay: 31.26 ms root dispersion: 74.20 ms peer dispersion: 34.30 ms reference time: 11:55:56.833 UTC Mar 2 2006(C7B15BCC.D5604189) synchronization state: clock synchronized
完成上述配置后,DeviceC可以同步到DeviceB的时间。
查看DeviceC的NTP状态,可以看到时钟状态为“synchronized”,即,已经完成同步。时钟的层数为4,比服务器DeviceB低1级。
[~DeviceC] display ntp-service status clock status: synchronized clock stratum: 4 reference clock ID: 10.0.0.1 nominal frequency: 60.0002 Hz actual frequency: 60.0002 Hz clock precision: 2^18 clock offset: 3.8128 ms root delay: 31.26 ms root dispersion: 74.20 ms peer dispersion: 34.30 ms reference time: 11:55:56.833 UTC Mar 2 2006(C7B15BCC.D5604189) synchronization state: clock synchronized
查看DeviceD的NTP状态,可以看到时钟状态为“synchronized”,即,已经完成同步。时钟的层数为4,比服务器DeviceB低1级。
[~DeviceD] display ntp-service status clock status: synchronized clock stratum: 4 reference clock ID: 10.0.0.1 nominal frequency: 60.0002 Hz actual frequency: 60.0002 Hz clock precision: 2^18 clock offset: 3.8128 ms root delay: 31.26 ms root dispersion: 74.20 ms peer dispersion: 34.30 ms reference time: 11:55:56.833 UTC Mar 2 2006(C7B15BCC.D5604189) synchronization state: clock synchronized
查看DeviceA的NTP状态。
[~DeviceA] display ntp-service status clock status: synchronized clock stratum: 2 reference clock ID: LOCAL(0) nominal frequency: 60.0002 Hz actual frequency: 60.0002 Hz clock precision: 2^18 clock offset: 0.0000 ms root delay: 0.00 ms root dispersion: 26.50 ms peer dispersion: 10.00 ms reference time: 12:01:48.377 UTC Mar 2 2006(C7B15D2C.60A15981) synchronization state: clock synchronized
配置文件
DeviceA的配置文件
# sysname DeviceA # ntp-service authentication-keyid 42 authentication-mode md5 cipher %#%#JA!v6M22=Gg\{>U.lx%#)c%yY}0*"/`5mi><QS)L%#%# ntp-service refclock-master 2 ntp-service authentication enable # interface GigabitEthernet0/1/0 undo shutdown ip address 2.2.2.2 255.255.255.0 # ospf 1 area 0.0.0.0 network 2.2.2.0 0.0.0.255 # return
DeviceB的配置文件
# sysname DeviceB # ntp-service authentication-keyid 42 authentication-mode md5 cipher %#%#>hD8))_H-XZVut2u3!_0lq3,+Ph=:OE}pX;T2M'9%#%# ntp-service reliable authentication-keyid 42 ntp-service unicast-server 2.2.2.2 authentication-keyid 42 ntp-service authentication enable # interface GigabitEthernet0/1/0 undo shutdown ip address 10.0.0.1 255.255.255.0 interface GigabitEthernet0/2/0 undo shutdown ip address 1.0.1.11 255.255.255.0 # ospf 1 area 0.0.0.0 network 1.0.1.0 0.0.0.255 network 10.0.0.0 0.0.0.255 # return
DeviceC的配置文件
# sysname DeviceC # ntp-service authentication-keyid 42 authentication-mode md5 cipher %#%#m:fVJfk*r&3x"1J`21^K`Y;LH;B+g(t2<ZX^}Q_~%#%# ntp-service reliable authentication-keyid 42 ntp-service unicast-server 10.0.0.1 authentication-keyid 42 ntp-service authentication enable # interface GigabitEthernet0/1/0 undo shutdown ip address 10.0.0.2 255.255.255.0 # return
DeviceD的配置文件
# sysname DeviceD # ntp-service authentication-keyid 42 authentication-mode md5 cipher %#%#$\`_6BKWy1]kdR@=c;O@UX!)Vor5iYi|zIYEG_v5%#%# ntp-service reliable authentication-keyid 42 ntp-service unicast-server 10.0.0.1 authentication-keyid 42 ntp-service authentication enable # interface GigabitEthernet0/1/0 undo shutdown ip address 10.0.0.3 255.255.255.0 # return