IOS 设备 NTP 配置示例
在日志和调试时加上时间戳
Router(config)#service timestamps log datetime localtime
Router(config)#service timestamps debug datetime localtime
设置时间
Router#clock set 15:30:00 January 1 2009
outer#calendar set 15:30:00 January 1 2009
Clock 和 Calendar 的区别:
Most Cisco routers have two clocks:a battery-powered hardware clock (referenced in CLI commands as the “calendar”) and a software clock (referenced in CLI commands as the “clock”). These two clocks are managed separately.
The primary source for time data on your system is the software clock. This clock runs from the moment the system starts up and keeps track of the current date and time. The software clock can be set from a number of sources and in turn can be used to distribute the current time through various mechanisms to other systems. When a router with a hardware clock is initialized or rebooted, the software clock is initially set based on the time in the hardware clock.
设置时区
Router(config)#clock timezone EST 5
缺省路由器使用 UTC 就是以前的 GMT
配置多个 NTP 服务器的方式来提供冗余
Router(config)#ntp server 10.10.10.254
Router(config)#ntp server 10.10.10.253
Router(config)#ntp peer 10.10.10.1(双向提供时间)
设置路由器为网络 NTP 服务器
Router(config)#ntp master 8(层次 8)
NTP 不允许手动修改同步频率,但是内置的算法可以自动调整此频率,开始为 64 秒一个周期,如果网络足够稳定此周期会逐渐增加,最长到 1024 秒。
NTP 更新
广播:
服务器端
Server(config)#clock timezone EST -5
Server(config)#ntp server 172.25.1.1
Server(config)#interface FastEthernet0/0
Server(config-if)#ntp broadcast
客户端
Client(config)#clock timezone EST -5
Client(config)#clock summer-time EDT recurring
Client(config)#ntp broadcastdelay 4
Client(config)#interface Ethernet0
Client(config-if)#ntp broadcast client
工作于广播模式时间数据包是单方向的,通过broadcastdelay来控制周期,广播模式不妨碍 客户端工作于服务器客户端模式组播:
服务器端
Router(config)#ntp server 10.10.10.254
Router(config)#ntp server 10.10.10.253
Router(config)#interface FastEthernet 0/0
Router(config-if)#ntp multicast 224.0.1.1 ttl 1
客户端
Client#configure terminal
Client(config)#interface FastEthernet 0/0
Client(config-if)#ntp multicast 224.0.1.1 ttl 1
组播相对于广播的好处不用多说了,并且在这个模式的初始客户端会先发送一些单播包来测量延迟,以使时间更准确,需要注意的是不是所有的设备都支持这种组播模式
禁止 NTP 服务
Router(config-if)#ntp disable
或者
Router(config)#access-list 100 deny udp any eq 123 any eq 123
Router(config)#access-list 100 permit ip any any
Router(config)#interface Serial0/1
Router(config-if)#ip access-group 100 in
控制列表的方式更严格,第一种只是阻止了相应的 associations,但阻止不了 NTP 数据包
NTP 认证
服务器端
Router(config)#ntp authentication-key 1 md5 cisco
Router(config)#ntp authenticate
Router(config)#ntp trusted-key 1
客户端
Router(config)#ntp authentication-key 1 md5 cisco
Router(config)#ntp authenticate
Router(config)#ntp trusted-key 1
Router(config)#ntp server 10.10.10.254 key 1
对于广播或者组播模式 key 配置为 ntp broadcast key 1 和 ntp multicast key 1
限制 NTP Peers
Router(config)#access-list 88 permit host 172.25.1.1
Router(config)#access-list 88 permit host 10.1.1.1
Router(config)#access-list 99 permit 172.25.0.0 0.0.255.255
Router(config)#access-list 99 permit 10.2.0.0 0.0.255.255
Router(config)#clock timezone EST -5
Router(config)#clock summer-time EDT recurring
Router(config)#ntp server 172.25.1.1 version 3
Router(config)#ntp server 10.1.1.1 version 3
Router(config)#ntp access-group peer 88
Router(config)#ntp access-group serve-only 99
路由器只允许内部时钟从 ACL 88 定义的两个服务器中获得同步,同时只有 ACL 99 定义的两个网段的客户端可以从本设备请求时间信息
NTP 日志
Router(config)#ntp logging
Related posts:
没有评论