• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

RHEL 7 – RHCSA Notes : Configure a system to use time services

by admin

RHEL 7 – RHCSA Notes (Cheat Sheets)

RHEL 7 has 3 command-line utilities to configure the system date and time:
1. date
2. hwclock
3. timedatectl

date command

Use the date command to display or set the system date and time. Run the date command with no arguments to display the current date and time:

# date
Mon Sep 12 19:41:40 IST 2016

The date command provides a variety of output formatting options. You can also time and date in future or past. Few examples are given below.
1. Display day of the week :

# date +%A
Monday

2. Display date one year from now :

# date -d "1 year"
Mon Sep 12 19:47:49 IST 2017

3. Display 1 month past date :

# date -d "1 month ago"
Mon Aug 12 19:49:07 IST 2016

Use the following syntax to change the current date. Replace YYYY with a four-digit year, MM with a two-digit month, and DD with a two-digit day of the month.

# date +%D -s [YYYY-MM-DD]

Use the following syntax to change the current time. Replace HH with a two-digit hour, MM with a two-digit minute, and SS with a two-digit second. Include either AM or PM. Include the –u option if your system clock is set to use UTC.

# date +%T%p -s [HH:MM:SS]AM|PM –u

hwclock command

Use the hwclock command to query and set the hardware clock, also known as the RTC (real-time clock). This clock runs independently of any control program running in the CPU and even when the machine is powered off. The hwclock command allows you to:

  • Display the current time
  • Set the hardware clock to a specified time
  • Set the system time from the hardware clock (hwclock –s)
  • Set the hardware clock to the current system time (hwclock –w)

timedatectl command

– The timedatectl utility is part of the systemd system and service manager.
– To display local, universal, and RTC time and time zone, NTP configuration, and DST information:

# timedatectl
      Local time: Tue 2016-09-13 20:30:26 IST
  Universal time: Tue 2016-09-13 15:00:26 UTC
        RTC time: Tue 2016-09-13 15:00:26
       Time zone: Asia/Kolkata (IST, +0530)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

– Use the following syntax to change the date and time:

# timedatectl set-time [YYYY-MM-DD]
# timedatectl set-time [HH:MM:SS]

– Use the following syntax to change the time zone:

# timedatectl set-timezone [time_zone]

– To list available time zones :

# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa

– To enable clock synchronization over NTP:

# timedatectl set-ntp yes

Using NTP

NTP provides a method of verifying and correcting your computer’s time by synchronizing it with another system.
To install NTP :

# yum install ntp

By default, there are four public server entries in the NTP configuration file, /etc/ntp.conf, which are specified by the server directive.

# grep server /etc/ntp.conf 
server 0.rhel.pool.ntp.org 
server 1.rhel.pool.ntp.org 
server 2.rhel.pool.ntp.org 
server 3.rhel.pool.ntp.org

Instead of using a predefined public server, you can specify a local reference server in the /etc/ntpd.conf file. For example:

# vi /etc/ntpd.conf
server 192.0.2.1

Another directive in the configuration file is driftfile. The default setting is as follows:

driftfile /var/lib/ntp/drift

This drift file contains one value used to adjust the system clock frequency after every system or service start.

NTP daemon

The ntpd program is the user space daemon that synchronizes the system clock with remote NTP time servers or local reference clocks. The daemon reads the configuration file at system start or when the service is restarted. You also need to open UDP port 123 in the firewall for NTP packets. After editing the /etc/ntp.conf file, use the systemctl command to start the NTP daemon:

# systemctl start ntpd

Use the following command to ensure the NTP daemon starts at boot time:

# systemctl enable ntpd

Other NTP utilities

Use the ntpq command to query the NTP daemon operations and to determine performance. Use the –p option (or peers command) to display a list of peers known to the server as well as a summary of their state. For example:

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*10.10.0.2      192.168.2.11      2 u  911 1024  377    1.274    0.147   0.355
+10.10.0.3      192.168.2.11      2 u 1026 1024  377    1.161    0.073   0.852

The * indicates your system is synchronized with the 10.10.0.2 server. Use the ntpstat command to show network time synchronization status.

# ntpstat
synchronised to NTP server (10.10.0.2) at stratum 3
   time correct to within 31 ms
   polling server every 1024 s

Configuring NTP using chrony

Chrony is a suite of utilities that provides another implementation of NTP. Chrony is designed for mobile systems and virtual machines that are often powered down or disconnected from the network. Systems that are not permanently connected to a network take a relatively long time to adjust their system clocks with the NTP daemon, ntpd.

Chrony consists of chronyd, a daemon that runs in user space, and chronyc, a command- line program for making adjustments to chronyd. The chronyd daemon makes adjustments to the system clock that is running in the kernel. It uses NTP to synchronize with another system when network access is available. When network access is not available, chronyd uses the last calculated drift stored in the drift file to synchronize the system time.

For more information on chrony (installation, configuration, troubleshooting), refer the below posts :

CentOS / RHEL 7 : Configuring NTP using chrony
CentOS / RHEL 7 : Tips on Troubleshooting NTP / chrony Issues

Filed Under: CentOS/RHEL 7, RHCSA notes

Some more articles you might also be interested in …

  1. CentOS / RHEL 7 : Beginners guide to systemd targets (replacement of SysV init run levels)
  2. How to Recover Deleted rpm Package Files(libraries, configuration files) in CentOS/RHEL 7
  3. How to configure multicast on an IP address (interface)
  4. ASMLib-Managed Disks on Multipathed iSCSI Targets are not Discovered after Server Reboot in CentOS/RHEL 7
  5. How to Enable Verbose Logging for VSFTPD
  6. “WARNING: Failed to connect to lvmetad. Falling back to device scanning” – error while running LVM commands
  7. Apache HTTP server – most commonly used containers (special configuration directives)
  8. How to Update the hostname in Shell Prompt Once it is Changed in the Linux OS
  9. CIFS Share Filesystem Is Not Mounted after Reboot on CentOS/RHEL 7
  10. How to set “max_report_luns” and “max_luns” on CentOS/RHEL 7 to scan more than 16,383 LUNs

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright