NTP—network time protocol,是用来使网络设备时间同步的一个协议。在配置了NTP的网络中,通常都会有一个比较权威的时间源,例如原子钟。NTP就是将从时间源那里获取的时间信息再分发到网络中的其他设备上来使整个网络的时间同步。
NTP使用一个层次(stratum)的概念来描述设备离权威时间源的远近,如层次1时间服务器就是典型的最权威的时间源,如原子钟,GPS时间源。层次2的时间服务器就是通过NTP从层次1那里接受时间信息。
NTP使用两种方法来避免跟时间不准确的设备同步时间。第一,NTP不会去跟自己都还没有同步的设备同步。第二,NTP会比较收到的几个时间信息,并且不会去跟一个与其他的时间信息差别很大的信息同步,哪怕这个信息是从一个层次比较底的设备来的。
在Cisco设备上是不支持层次1的服务器的,因为Cisco认为网络中的设备不太可能连接到原子钟这样的设备上(在特殊的平台上我们还是可以连接到GPS时间服务器上的)。通常都会认为网络中的时间服务器是来自与Internet上的公共服务器。
在不能连上Internet的内网中,我们可以把一台设备配置成NTP服务器使其他的设备来跟这个服务器同步。
二.NTP的两种模式
        1.轮询服务模式(polling host servers):
        在轮询服务模式下分为:客户模式(Client mode)和对称主动模式(Symmetric active mode)
        当NTP需要高的时间准确性和可用性时推荐使用轮询模式。
        在客户模式中网络设备查询时间服务器,该模式适用不提供时钟的设备,如文件服务器和客户端
        在主动对称模式中时双方互相查询,互相同步,适用与时钟服务器与时钟服务器之间同步。
        2.侦听NTP广播模式(listening to NTP broadcasts)
        在对时钟的准确性和可用性要求不高或者有大量的NTP客户端(往往多余20)的情况下,推荐使用NTP的广播模式
        在带宽有限或者内存和CPU的资源有限的情况下也推荐使用NTP广播模式
        在广播模式下网络设备不参与任何的轮询
三.NTP的配置
        1.轮询模式的配置
        配置NTP客户模式:
Router(config)# ntp server ip-address [version number] [key keyid] [source interface] [prefer]
        配置NTP对称主动模式:
Router(config)# ntp peer ip-address [normal-sync] [version number] [key keyid] [source interface] [prefer]
        2.NTP广播模式的配置
        配置接口发送NTP广播
Router(config-if)# ntp broadcast [version number]
        配置接口为NTP广播模式的客户端
Router(config-if)# ntp broadcast client
        调整回程时间
Router(config)# ntp broadcastdelay microseconds
        3.NTP的其他的配置
        配置NTP的访问限制
Router(config)# ntp access-group {query-only | serve-only | serve | peer} access-list-number
        配置NTP的验证
Router(config)# ntp authenticate
Router(config)# ntp authentication-key number md5 value
Router(config)# ntp trusted-key key-number
        在指定端口上关闭NTP
Router(config-if)# ntp disable
        配置NTP数据包发送的源地址
Router(config)# ntp source interface
        配置NTP的阶层
Router(config)# ntp master [stratum]
        4.配置实例
                A# clock set 11:22:20 jul 14 2006
A(config)# clock timezone BJ 8 
A(config)# ntp master 2
A(config)# ntp source loopback 0
A(config)# ntp authenticate
A(config)# ntp authentication-key 1  md5 cisco
A(config)# ntp trusted-key 1 


B(config)# ntp server 1.1.1.1 key 1 source loopback 0
B(config)# ntp authenticate
B(config)# ntp authentication-key 1  md5 cisco
B(config)# ntp trusted-key 1