WOLF-LAB沃尔夫网络实验室中国网络精英的发源地!
24小时咨询热线:173-1636-2402

技术文档

Technical documentation

您当前位置: 首页 > 技术文档 > 详情

思科认证EI CCNA培训企业基础架构-NTP协议的原理、配置、总结

发布日期:2023-09-26 浏览次数:715 来源:WOLF-LAB杨广成

思科认证EI CCNA培训企业基础架构-NTP协议的原理、配置、总结


WOLFLAB网络技术实验室1.jpg

思科认证EI CCNA培训企业基础架构课程咨询联系WOLF-LAB网络技术实验室,课程循环开班!

<NTP(Network Time Protocol)>

·在设备的监控和排错过程中,准确的时钟设置是必要的。

 NTP主要用来同步系统时钟。是基于UDP的协议。


时钟与时区设置:

clock set hh:mm:ss day month year

例:

clock set 12:30:00 May 1 2009


clock timezone zone hours-offset [minutes-offset]

例:

clock timezone GMT +8


show clock   //查看时钟


1)设定NTP时钟服务器


SW:

ntp master     //本命令用来设置NTP服务器


查看状态:

show ntp status 

....Clock is synchronized, stratum 1, reference is .LOCL.


2)设定NTP客户端

NTP客户端会跟着NTP服务器同步

SW:

ntp server 12.1.1.1


...Clock is synchronized, stratum 2, reference is 12.1.1.1


show ntp associations 


3)跟次级时钟源同步:

该全局命令使路由器的系统时钟与其对等体的时钟同步(或对对等体的时钟进行同步)。 

SW:

 ntp peer 13.1.1.1


Clock is synchronized, stratum 3, reference is 13.1.1.1


4)NTP认证:


R2:(NTP Master)

ntp authentication-key 1 md5 wolf

ntp authenticate

ntp trusted-key 1

ntp master 6


R1:

ntp authentication-key 1 md5 wolf

ntp authenticate

ntp trusted-key 1

ntp server 12.1.1.2 key 1


5)NTP Source

NTP更新源地址


SW:

ntp source loopback 0


客户端:

SW:

ntp server 2.2.2.2 key 1 


实际工程案例:

image.png

全网NTP同步设置需求:

使用轮巡模式,将SW1设为主NTP服务器。两台核心交换机的管理地址为10.10.10.x/24

SW1-primary:VLAN1 地址为10.10.10.1

SW2-secondary: VLAN1 地址为10.10.10.2

 

SW1配置:

 

clock timezone BJ 8

ntp master 2

ntp source vlan1

ntp authenticate

ntp authentication-key 1 md5 holly

ntp trusted-key 1

ntp peer 10.10.10.2 source vlan1

ntp update-calendar

!!!Periodically update calendar with NTP time

 

注意主NTP服务器不能加载clock calendar-valid 命令,否则自身无法同步。

图片1(53).png

 1695719201917982.png

SW2配置:

首先使用clock set 设好时间,再配置NTP。

clock timezone BJ 8

clock calendar-valid

ntp source vlan1

ntp authenticate

ntp authentication-key 1 md5 holly

ntp trusted-key 1

ntp server 10.10.10.1 source vlan1

ntp update-calendar

!!!Periodically update calendar with NTP time

 

客户端设置:(接入层交换机以及所有安全服务模块,例如:SW3)

 

clock timezone BJ 8

ntp server 10.10.10.1 key 1 source vlan1

ntp server 10.10.10.2 key 2 source vlan1

ntp source vlan1

ntp authenticate

ntp authentication-key 1 md5 holly

ntp trusted-key 1

 

 

注意:

NTP的时钟源在一般的情况下也可以使用路由器上的时钟。高档的路由器/交换机上提供了硬件时钟,称为calendar,与clock相互独立,在系统重启时clock使用calendar的值。可以用命令calendar set设置硬件时钟的值,用命令clock read-calendar将系统时钟设置为calendar的值,也可以用命令clock update-calendar将当前系统时钟值写入calendar中。在客户端,用ntp master x.x.x.x 指定NTP服务器地址(CatOS:set ntp server x.x.x.x),用命令ntp update update-calendar 可以让NTP协议定时更新calendar的值。如果更改了时钟源的时间,需要数分钟才能同步到客户端,更新calendar需要更长的时间。常用的调试命令有:show ntp status 和 show ntp associations等。

N T P的会聚( c o n v e rg e n c e )可能需要长达半个小时,这意味着在修改N T P主系统时钟之后,再过半个小时其它的时钟才进行同步。这是因为N T P将时钟的改变视为时钟系统的不稳定。NTP需在等待系统稳定后才会进行同步和传递时钟的改变

 

在Cisco网络系统中的NTP配置需要用到的命令及定义:

ntp access-group: 该全局命令用于路由器N T P服务的访问控制。

ntp authenticate: 是一个全局命令,它启用N T P身份验证。

ntp authentication-key: 该全局命令用于定义N T P身份验证的键值。

ntp broadcast: 是一个接口命令,用于指定一特定接口来发送N T P广播包。

ntp broadcast client: 是一个接口命令,使路由器通过特定接口来接收N T P广播包。

ntp broadcast delay: 是一个全局命令,它用于设定数据包在路由器和N T P服务器之间一个回程所需时间的估计值。

ntp clock-period: 这条全局命令不必输入,当使用N T P进行系统时钟同步时,路由器将自动产生这条命令。

ntp disable: 这条接口命令使特定接口不接收N T P包。

ntp master: 这条全局命令用来配置路由器为N T P主时钟,只有当没有可用的外部N T P源或者为测试用途才使用该命令。

ntp peer: 该全局命令使路由器的系统时钟与其对等体的时钟同步(或对对等体的时钟进行同步)。

ntp server: 该全局命令使路由器的系统时钟由时间服务器进行同步。

ntp source: 该全局命令强制路由器在其N T P包中使用特定的源地址。

ntp trusted-key: 该全局命令用于确认路由器的特定身份验证键值。

ntp update-calendar: 该全局命令使N T P周期性地更新Cisco 7XXX 系列路由器的日历。

show ntp status: 是一执行模式命令,用于显示路由器的N T P信息,它可以表明该路由器是通过N T P对等体进行时钟同步还是通过N T P服务器进行同步。

show ntp association[detail]: 这条执行模式命令显示与N T P有关的信息,如轮询周期等。

 

简要配置示例:

EXAMPLE 1

路由器A和路由器B通过串口连接,路由器A被设为N T P主时钟,路由器B都被配置成根据路由器A来同步时钟。

RouterA#clock set xx:xx:xx:xx

RouterA(config)# int s0

RouterA(config-if)#ip add 172.23.1.1 255.255.255.0

RouterA# ntp master 1

RouterB#ntp server 172.23.1.1   

...

EXAMPLE 2

路由器A被设置为N T P主时钟,路由器B被配置成通过N T P服务器与路由器A进行时钟同步,路由器C则被配置成路由器B的对等体,与B的时钟同步。三台路由器通过串口进行连接,路由器A和B之间、路由器B和C之间的连接都使用交叉电缆。

...

RouterA#clock set xx:xx:xx:xx

RouterA(config)# int s0

RouterA(config-if)#ip add 172.23.1.1 255.255.255.0

RouterA# ntp master 1

RouterB#ntp server 172.23.1.1 

RouterB(config-if) ip add 172.16.1.2 255.255.255.0

RouterC#ntp peer 172.16.1.2

...

EXAMPLE 3

使用局域网广播的CISCO NTP

3台路由器通过以太网接入同一个网段,路由器a作为NTP服务器通过e0接口向以太网发送NTP广播。

...

RouterA#clock set xx:xx:xx:xx

routerA(config0#int e0

RouterA(config-if)#ip add 172.23.1.1 255.255.255.0

RouterA(config-if)#ntp broadcast

RouterA# ntp master

RouterB(config)#int e0

RouterB(config-if) # ip add 172.23.1.2 255.255.255.0

RouterB(config-if) #ntp broadcast client

RouterC(config)#int e0

RouterC(config-if) # ip add 172.23.1.3 255.255.255.0

RouterC(config-if) #ntp broadcast client


https://www.wolf-lab.com/

WOLFLAB官方微信:17316362402

WOLFLAB官方QQ:2569790740

思科认证EI CCNA培训企业基础架构课程培训联系WOLF-LAB实验室

返回目录
在线咨询