Thursday, December 8, 2011

NTP and Timestamps

So the first thing to do is to set the switch to update its internal clock with a network time server. Let’s assume we’ve added a server to our network that among other things is a network time server and its IP address is 192.168.10.10. In addition to the network time server IP address, we need to know what timezone the switch lives in and whether or not daylight savings time is observed. The switch we are working on is in the US Central Time Zone and daylight savings time occurs every summer. Log in to the switch and enter global config mode. From there we type three commands, ntp server 192.168.10.10, clock timezone CST -6, and clock summer-time CDT recurring:

Switch(config)#ntp server 192.168.10.10
Switch(config)#clock timezone CST -6
Switch(config)#clock summer-time CDT recurring
Switch(config)#

In the above example, the timezones CST and CDT are for display purposes only. I could have used the word ‘time’ in both instances or the word ‘elephant’ for that matter. It is there simply to show you which timezone offset that is referenced by the number following the name of the time zone. The important part of the clock timezone command is the ‘hours offset from GMT’ number, in this case -6. Internal time is kept in GMT time and timestamps are logged using the offset number of hours.

Now that our clock is set to sync with our network time server, let’s make sure the switch is using the current time when it makes a log entry. By default the switch makes log entries not with the time of day that the log entry occurred but rather the time elapsed since the switch booted. Here’s what the log entries currently look like:

Switch#show log
Syslog logging: enabled (0 messages dropped, 1 messages rate-limited, 0 flushes, 0 overruns, xml disabled, filtering disabled)
Console logging: level debugging, 17 messages logged, xml disabled,
filtering disabled
Monitor logging: level debugging, 0 messages logged, xml disabled,
filtering disabled
Buffer logging: level debugging, 17 messages logged, xml disabled,
filtering disabled
Exception Logging: size (4096 bytes)
Count and timestamp logging messages: disabled
File logging: disabled
Trap logging: level informational, 20 message lines logged

Log Buffer (4096 bytes):

00:00:43: %STACKMGR-4-SWITCH_ADDED: Switch 1 has been ADDED to the stack
00:00:45: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to down
00:00:45: %SPANTREE-5-EXTENDED_SYSID: Extended SysId enabled for type vlan
00:00:47: %SYS-5-CONFIG_I: Configured from memory by console
00:00:47: %STACKMGR-5-SWITCH_READY: Switch 1 is READY
00:00:47: %STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 1 has changed to state DOWN
00:00:47: %STACKMGR-4-STACK_LINK_CHANGE: Stack Port 2 Switch 1 has changed to state DOWN
00:00:47: %STACKMGR-5-MASTER_READY: Master Switch 1 is READY
00:00:48: %SYS-5-RESTART: System restarted --
Cisco IOS Software, C3750 Software (C3750-IPBASE-M), Version 12.2(25)SEE1, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2006 by Cisco Systems, Inc.
Compiled Mon 22-May-06 04:34 by yenanh
00:00:49: %LINK-3-UPDOWN: Interface FastEthernet1/0/11, changed state to up
00:00:49: %LINK-3-UPDOWN: Interface FastEthernet1/0/23, changed state to up
00:00:50: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0/11, changed state to up
00:00:50: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0/23, changed state to up
00:01:20: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up
00:01:55: %SYS-6-CLOCKUPDATE: System clock has been updated from 19:29:32 UTC Fri Jan 4 2008 to 13:29:32 CST Fri Jan 4 2008, configured from console by console.
00:02:43: %SYS-6-CLOCKUPDATE: System clock has been updated from 13:30:20 CST Fri Jan 4 2008 to 13:30:20 CST Fri Jan 4 2008, configured from console by console.
00:03:15: %SYS-5-CONFIG_I: Configured from console by console
Switch#


The last log entry was made 3 minutes, 15 seconds after the switch booted. Lets correct the time used for the log entries so that it shows the time of day the entry was made. While still at the global config prompt, enter the following:

Switch(config)#service timestamps debug datetime localtime
Switch(config)#service timestamps log datetime localtime


Exit out to EXEC mode and type show log. You’ll see the last entry has the time of day instead of elapsed time since boot up:

Switch#show log
Syslog logging: enabled (0 messages dropped, 1 messages rate-limited, 0 flushes, 0 overruns, xml disabled, filtering disabled)
Console logging: level debugging, 18 messages logged, xml disabled,
filtering disabled
Monitor logging: level debugging, 0 messages logged, xml disabled,
filtering disabled
Buffer logging: level debugging, 18 messages logged, xml disabled,
filtering disabled
Exception Logging: size (4096 bytes)
Count and timestamp logging messages: disabled
File logging: disabled
Trap logging: level informational, 21 message lines logged

Log Buffer (4096 bytes):

00:00:43: %STACKMGR-4-SWITCH_ADDED: Switch 1 has been ADDED to the stack
00:00:45: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to down
00:00:45: %SPANTREE-5-EXTENDED_SYSID: Extended SysId enabled for type vlan
00:00:47: %SYS-5-CONFIG_I: Configured from memory by console
00:00:47: %STACKMGR-5-SWITCH_READY: Switch 1 is READY
00:00:47: %STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 1 has changed to state DOWN
00:00:47: %STACKMGR-4-STACK_LINK_CHANGE: Stack Port 2 Switch 1 has changed to state DOWN
00:00:47: %STACKMGR-5-MASTER_READY: Master Switch 1 is READY
00:00:48: %SYS-5-RESTART: System restarted --
Cisco IOS Software, C3750 Software (C3750-IPBASE-M), Version 12.2(25)SEE1, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2006 by Cisco Systems, Inc.
Compiled Mon 22-May-06 04:34 by yenanh
00:00:49: %LINK-3-UPDOWN: Interface FastEthernet1/0/11, changed state to up
00:00:49: %LINK-3-UPDOWN: Interface FastEthernet1/0/23, changed state to up
00:00:50: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0/11, changed state to up
00:00:50: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0/23, changed state to up
00:01:20: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up
00:01:55: %SYS-6-CLOCKUPDATE: System clock has been updated from 19:29:32 UTC Fri Jan 4 2008 to 13:29:32 CST Fri Jan 4 2008, configured from console by console.
00:02:43: %SYS-6-CLOCKUPDATE: System clock has been updated from 13:30:20 CST Fri Jan 4 2008 to 13:30:20 CST Fri Jan 4 2008, configured from console by console.
00:03:15: %SYS-5-CONFIG_I: Configured from console by console
Jan 4 13:37:03: %SYS-5-CONFIG_I: Configured from console by console
Switch#


From now on all log entries will have the time of day the entry occurred.

No comments:

Post a Comment