NTP网络时间协议简介及命令配置

NTP简介:
定义:网络时间协议NTP(Network Time Protocol)是TCP/IP协议簇里面的一个应用层协议,
NTP用于在一系列分布式时间服务器之间同步时钟,NTP的实现基于IP和UDP,NTP的报文通过UDP传输,
端口号是UDP123。
目的:随着网络拓扑的日益复杂,整个网络内设备的时钟同步变得十分重要,如果依靠管理员手动修改系统时钟,
不仅工作量大,而且无法保证时间的准确性,NTP的出现就是为了解决网络内设备系统时钟的同步问题。

》NTP主要应用在与网络中所有设备时钟需要保持一致的场合,比如:
网络管理:对从不同路由器采集来的日志信息、调试信息进行分析时,需要以时间作为参考依据。
计费系统:要求所有设备的时钟必须保持一致。
多个系统协同处理一个复杂事件:为了保证正确的执行顺序,多个系统必须参考同一时钟。
备份服务器和客户机之间进行增量备份:要求备份服务器和所有客户机之间的时钟同步。
系统时间:某些应用程序需要知道用户登录系统的时间以及文件修改的时间。

》系统时钟的同步流程如下:

1.NTP客户端在T1时刻发送一个NTP请求报文给NTP服务区,该请求报文中携带离开客户端的时间戳为T1。
2.NTP请求报文到达NTP服务器,此时NTP服务器的时刻为T2。
3.NTP服务器处理之后,与T3时刻发送出NTP应答报文,该应答报文中携带离开NTP客户端的时间戳为T1,
到达NTP服务器时的时间戳T2,离开NTP服务器的时间戳为T3。
4.NTP客户端在T4时刻受到应答报文。
我们可以通过以下公式算出NTP客户端与NTP服务器之间的时间差,也就是NTP客户端需要调整的时间。
1.计算NTP报文从NTP客服端发送到NTP服务器所需的时间Delay。
Delay =[(T4-T1)-(T3-T2)]/2

2. 计算NTP客户端与NTP服务器之间的时间差Offset。

以T4时刻为例,在这个时刻点,NTP服务器发送过来的报文被NTP客户端接收时,服务器的时刻已经为T3+delay。

那么时间差Offset可由以下公式进行计算:
T4 + Offset = T3+ Delay

公式整理之后,Offset = T3 + Delay - T4 =T3+[(T4-T1)-(T3-T2)]/2 -T4=[(T2-T1)+(T3-T4)]/2

NTP 客户端根据计算得到的Offset 来调整自己的时钟,实现与NTP服务器的时钟同步。

配置命令:

》配置带验证的单播NTP服务器

SWA:ntp-service refclock-master 2 //在SWA上指定使用自己的本地时钟作为主时钟,层数为2
SWA:ntp-service authentication enable //使能NTP认证功能
SWA:ntp-service authentication-keyid 42 authentication-mode hmac-sha256 cipher 123456
//配置验证秘钥
SWA:ntp-service reliable authentication-keyid 42 //声明该秘钥可信
SWA:undo ntp-service server disable //服务器需要使能NTP服务器功能

SWB:ntp-service authentication enable
SWB: ntp-service suthentication-keyid 42 authentication-mode hmac-sha256 cipher 123456
SWB: ntp-service reliable authentication-keyid 42
SWB: ntp -service unicast-server 10.1.1.1 authentication-keyid 42 //指向SWA为NTP服务器

验证命令:
display ntp-service status //查看NTP状态,synchronized既完成同步

》配置带验证的广播NTP服务器

SWA: ntp-service refclock-master 3 //使用本地时钟为NTP的主时钟,层数3
SWA: ntp-service suthentication enable //启用NTP 认证
SWA: ntp-service authentication-keyid 16 authentication-mode hmac-sha256 cipher 123456
//配置验证秘钥
SWA:ntp-service reliable authentication-keyid 16 //声明该ID可信
SWA:interface vlanif 10
ntp-service broadcast-server authentication-keyid 16 //从VLAN10发送NTP广播报文并指定秘钥16加密
SWA:undo ntp-service server disable // 使能NTP服务器功能

SWB:ntp-service authentication enable
SWB:ntp-service authentication-keyid 16 authentication-mode hmac-sha256 cipher 123456
SWB: ntp-service reliable authentication-keyid 16
SWB: interface vlanif 10
ntp-service broadcast-client //从VLAN10 侦听NTP广播报文

》配置NTP组播模式

SWA:ntp-service refclock-master 2
SWA: interface vlanif 10
ntp-service multicast-server //从VLAN10发送NTP组播报文
SWA:undo ntp-service server disable

SWB: interface vlanif 10
ntp-server multicast-client //从VLAN10侦听NTP组播报文

发布了5 篇原创文章 · 获赞 7 · 访问量 498

猜你喜欢

转载自blog.csdn.net/qq_45811376/article/details/105717677