Lab 3b: Time & Date

Here we set the correct timezone and set the current time in Linux using an NTP server . And we set up an NTP daemon so that the correct time is always maintained.

Task 1: Set the timezone

We use the date command to identify the current UTC and local times (using the –u option for UTC, and no option for the local timezone).

If the local time zone is incorrectly identified, change /etc/localtime into a symbolic link to the correct file for our timezone under the directory /usr/share/zoneinfo/

For experience, try setting your system to a different timezone to verify that you can. When done, reset it to Australia/Sydney.

Check Local Date & Time - on Linux

#date

Check UTC Time Zone - on Linux

#date -u

Zoneinfo directory - check what's in Australia dir

#ls /usr/share/zoneinfo/Australia/

Change time zone to Perth

To change the time zone to Perth we need to direct the time zone to the location

#ln -s /usr/share/zoneinfo/Austraia/Perth /etc/localtime

Error: Change time zone to Perth

If error message displays that failed to create symbolic link means that the file already exist.

Solution:
To fix this problem remove the /etc/localtime file and then create the link again

  1. Move the file to /etc/localtime.bak

#mv /etc/localtime /etc/localtime.bak

  1. Now create the link

# ln -s /usr/share/zoneinfo/Australia/Perth /etc/localtime

Task 2: Maintain correct time with chrony

In the latest versions of Centos, chrony is the system that maintains network time. Older systems use ntpd.

Chrony consists of both a server (daemon) and a client, called chronyd and chronyc respectively.

This task is a matter of setting up the chronyd daemon to run when the machine boots, to maintain the correct system time.

First, see whether chronyd is already running using the ps command (ps –ef | grep chronyd).


Then see whether chronyd is known by systemctl (systemctl status chronyd).


Use systemctl to start chronyd running now. Also use systemctl to enable chronyd so that it will start when the machine boots.

To verify that chrony is working, use the client program (chronyc) as follows. Document these commands in your journal.

• chronyc sources

• chronyc tracking

• chronyc add server time.uts.edu.au (check the result with the “sources” command).

To test that it will synchronise, let’s change the system date. Let’s party like it’s New Years Eve 1999:

• date 123123591999.00 (look up the manual for the date command to understand this format)

Then just run date with no arguments to check the date. Does it reset to the current date/time? Why or why not? (Hint: use Google to learn more about how Chrony works)

Restart chronyd, using systemctl. After restarting the daemon, run the date command a few times.

What happens now? Why?

Make notes in your journal about what happens and why. Also look at the configuration file /etc/chrony.conf

How to Automatically Synchronise date and time?

From a Linux terminal

Step 1: Check if 'daemon' is running at the background.

# ps -ef | grep chronyd

Step 2: Start the daemon process and enable

(On step 1 we can see that daemon is not running at the background.)

2.1: before start the process ensure the machine is connected to the Internet. Verify by 'ping'
# ping 8.8.8.8

2.2: Enable chronyd
# systemctl enable chronyd

2.3: start chronyd
# systemctl start chronyd


Step 3: Verify chrony is working

To verify that chrony is working we use client program (called chronyc). These looks at the frontend command.

3.1: Sources to synchronise our date and time
# chronyc sources

3.2: Tracking
# chronyc tracking


Add Server Time Zone

Add UTS server time zone

# chronyc add server time.uts.edu.au


Check if the time is added.

To check the source time UTS is added run the following command -

# chronyc sources


Test if the Synchronisation is working or note

Change the date and time and then test it with "date" command.

Change date

# date 123123591999.00


Verify daemon is running at the background we can restart -

# systemctl restart chronyd


And then try "date" command again -

#date

Task 3: Windows NTP

Windows can also automatically update the time and date via NTP.

In Server Manager > Local Server,

click on the "Time zone" shown to open the Date and Time window (or find it through Control Panel).

Go to the Internet Time tab.

We can then change the settings to choose your internet time server. The default is time.microsoft.com –

try changing this to: 2.pool.ntp.org