NTP(网络时间协议)虽然在网络设备的应用中不算起眼,但在特定的环境中,如SNMP为了同步事件的触发,往往需要多个设备保持精确的时间,这时NTP就能够派上用场了。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

多数路由器和交换机默认使用NTP客户端模式,这样它们可以由一台指定的NTP服务器来校准时间。NTP版本3RFC 1305)定义了客户端与服务器之间的消息格式以及客户端用来校准时间的算法。当然,路由器和交换机也可以配置为NTP服务器,甚至还可以使用NTP对称激活模式(symmetric active mode),在这种模式下,网络设备可以和另一台NTP主机互相同步。

 

NTP服务器也可以参考其他NTP服务器来获得更精确的时钟源。时钟源的高低可以由其stratum level(组织层次)来区分,例如,原子时钟和全球卫星定位时钟提供的是层次为1(最好级别)的时钟源。

 

NTP的配置

1)配置为NTP服务器

#conf t

(config)#int fa 0/0

(config-if)#ntp broadcast

(config-if)#^Z

(config)#ntp authentication-key 1 md5 12345690 5

(config)#ntp authenticate

(config)#ntp master 5

(注意该配置中ntp master 5表示该服务器的时钟源组织层次是5

2)配置为NTP静态客户端(手工配置为客户端)

#conf t

(config)#ntp authentication-key 1 md5 12345690 5

(config)#ntp authenticate

(config)#trusted-key 1

(config)#ntp clock-period 17208144

(config)#ntp server 192.168.0.1

3)配置为NTP广播客户端(自动学习为客户端)

#conf t

(config)#int fa 0/0

(config-if)#ntp broadcast client

4)配置为NTP对称激活模式

#conf t

(config)#ntp authentication-key 1 md5 12345690 5
(config)#ntp authenticate

(config)#ntp trusted-key 1

(config)#ntp clock-period 17208233

(config)#ntp peer 192.168.0.1

5)查看NTP配置信息及状态

使用show ntp associationsshow ntp status命令。