配置带验证的单播NTP服务器/客户端模式示例
组网需求
如图4-11所示的组网中,RouterB、RouterC和RouterD在同一个局域网中并且通过网络和RouterA相连。
用户由于业务需要,要求局域网中的所有工业路由交换一体机的系统时间同步到标准时钟。
配置思路
根据用户需求,采用NTP协议实现时钟同步,配置思路如下:
选择RouterA作为主时钟服务器。
RouterA和RouterB之间采用单播NTP服务器/客户端模实现时钟同步。RouterA作为服务器,RouterB作为客户端。
RouterB分别和RouterC、RouterD之间采用单播NTP服务器/客户端模实现时钟同步。其中RouterB作为服务器,RouterC和RouterD均为客户端。
考虑到RouterA和RouterB是通过网络相连,安全性较低,因此使能NTP认证功能。
在单播服务器/客户端模式下配置NTP认证时,必须首先在客户端使能NTP认证,然后再指定NTP服务器地址,并同时指定发给服务器的验证密钥。否则将不进行验证,直接同步。
客户端和服务器端都需要进行完整的配置,才能验证通过。
操作步骤
- 根据图4-11,配置IP地址,配置RouterA,RouterB,RouterC和RouterD路由可达
# 在RouterA上配置IP地址,RouterB、RouterC和RouterD的配置请参考配置文件。
<Huawei> system-view [Huawei] sysname RouterA [RouterA] interface gigabitethernet 1/0/0 [RouterA-GigabitEthernet1/0/0] undo portswitch [RouterA-GigabitEthernet1/0/0] ip address 10.2.2.2 24 [RouterA-GigabitEthernet1/0/0] quit [RouterA] ospf 1 [RouterA-ospf-1] area 0 [RouterA-ospf-1-area-0.0.0.0] network 10.2.2.0 0.0.0.255 [RouterA-ospf-1-area-0.0.0.0] quit [RouterA-ospf-1] quit
- 在RouterA上配置NTP主时钟并启动NTP认证功能
# 在RouterA上指定使用自己的本地时钟作为参考时钟,层数为2。
[RouterA] ntp-service refclock-master 2
# 使能NTP认证功能、配置验证密钥并声明该密钥可信。
[RouterA] ntp-service authentication enable [RouterA] ntp-service authentication-keyid 42 authentication-mode hmac-sha256 Hello [RouterA] ntp-service reliable authentication-keyid 42
注意服务器端与客户端必须配置相同的验证密钥。
- 在RouterB上启动NTP认证功能
# 在RouterB上使能NTP认证功能、配置验证密钥并声明该密钥可信。
<RouterB> system-view [RouterB] ntp-service authentication enable [RouterB] ntp-service authentication-keyid 42 authentication-mode hmac-sha256 Hello [RouterB] ntp-service reliable authentication-keyid 42
# 指定RouterA作为RouterB的NTP服务器,并使用已配置的验证密钥。
[RouterB] ntp-service unicast-server 10.2.2.2 authentication-keyid 42
- 在RouterC上指定RouterB作为RouterC的NTP服务器
<RouterC> system-view [RouterC] ntp-service authentication enable [RouterC] ntp-service authentication-keyid 42 authentication-mode hmac-sha256 Hello [RouterC] ntp-service reliable authentication-keyid 42 [RouterC] ntp-service unicast-server 10.0.0.1 authentication-keyid 42
- 在RouterD上指定RouterB作为RouterD的NTP服务器
<RouterD> system-view [RouterD] ntp-service authentication enable [RouterD] ntp-service authentication-keyid 42 authentication-mode hmac-sha256 Hello [RouterD] ntp-service reliable authentication-keyid 42 [RouterD] ntp-service unicast-server 10.0.0.1 authentication-keyid 42
- 验证配置结果
完成上述配置后,RouterB可以同步RouterA的时钟。
# 查看RouterB的NTP状态,可以看到时钟状态为“synchronized”,即,已经完成同步。时钟的层数为3,比服务器RouterA低1级。
[RouterB] display ntp-service status clock status: synchronized clock stratum: 3 reference clock ID: 10.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)
完成上述配置后,RouterC可以同步RouterB的时钟。
# 查看RouterC的NTP状态,可以看到时钟状态为“synchronized”,即,已经完成同步。时钟的层数为4,比服务器RouterB低1级。
[RouterC] 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 2012(C7B15BCC.D5604189)
# 查看RouterD的NTP状态,可以看到时钟状态为“synchronized”,即,已经完成同步。时钟的层数为4,比服务器RouterB低1级。
[RouterD] 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 2012(C7B15BCC.D5604189)
# 查看RouterA的NTP状态。
[RouterA] 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 2012(C7B15D2C.60A15981)
配置文件
RouterA的配置文件
# sysname RouterA # interface GigabitEthernet1/0/0 undo portswitch ip address 10.2.2.2 255.255.255.0 # ospf 1 area 0.0.0.0 network 10.2.2.0 0.0.0.255 # ntp-service authentication enable ntp-service authentication-keyid 42 authentication-mode hmac-sha256 cipher %@%@,1_MBtq@`IsY6$XkI|J<"6P(%@%@ ntp-service reliable authentication-keyid 42 ntp-service refclock-master 2 # return
RouterB的配置文件
# sysname RouterB # interface GigabitEthernet1/0/0 undo portswitch ip address 10.0.0.1 255.255.255.0 # interface GigabitEthernet2/0/0 undo portswitch ip address 10.0.1.1 255.255.255.0 # ospf 1 area 0.0.0.0 network 10.0.0.0 0.0.0.255 network 10.0.1.0 0.0.0.255 # ntp-service authentication enable ntp-service authentication-keyid 42 authentication-mode hmac-sha256 cipher %@%@,1_MBtq@`IsY6$XkI|J<"6P(%@%@ ntp-service reliable authentication-keyid 42 ntp-service unicast-server 10.2.2.2 authentication-keyid 42 # return
RouterC的配置文件
# sysname RouterC # interface GigabitEthernet1/0/0 undo portswitch ip address 10.0.0.2 255.255.255.0 # ntp-service authentication enable ntp-service authentication-keyid 42 authentication-mode hmac-sha256 cipher %@%@,1_MBtq@`IsY6$XkI|J<"6P(%@%@ ntp-service reliable authentication-keyid 42 ntp-service unicast-server 10.0.0.1 authentication-keyid 42 # return
RouterD的配置文件
# sysname RouterD # interface GigabitEthernet1/0/0 undo portswitch ip address 10.0.0.3 255.255.255.0 # ntp-service authentication enable ntp-service authentication-keyid 42 authentication-mode hmac-sha256 cipher %@%@,1_MBtq@`IsY6$XkI|J<"6P(%@%@ ntp-service reliable authentication-keyid 42 ntp-service unicast-server 10.0.0.1 authentication-keyid 42 # return