How to configure Local NTP server and client and Set date and time in CentOS 7

The example discussed below is for a basic NTP server and client. NTP stands for Network Transport Protocol and it is used to keep the time on the servers synced with each other using a common reliable source to get the time.

NTP Server Configuration
1. Install the required ntp package on the server.

# yum install ntp

2. Ensure the following entries are in ntp configuration file /etc/ntp.conf.

[root@kvm01 ~]# cat /etc/ntp.conf | grep -v "#"
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
server 127.127.1.0
fudge 127.127.1.0 stratum 6
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
logfile /var/log/ntp.log
[root@kvm01 ~]#

3. Now you can start the ntpd service.

# systemctl start ntpd.service

NTP Client Configuration

1. For client NTP configuration, add the below configuration in the /etc/ntp.conf file.

# cat /etc/ntp.conf
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
server kvm01.darole.org
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

2. Start the ntpd service on the ntp client server.

# systemctl start ntpd.service

CentOS  7 : How to set date, time / NTP and timezone using timedatectl

This utility is part of the systemd system and service manager.

If you run timedatectl without any options, you would get an output similar to below :

# timedatectl
Local time: Sun 2017-09-24 13:16:39 IST
Universal time: Sun 2017-09-24 07:46:39 UTC
RTC time: Sun 2017-09-24 07:46:39
Time zone: Asia/Kolkata (IST, +0530)
NTP enabled: no
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

The above output shows – local time, universal time, RTC time, time zone, NTP configuration and Daylight Savings Time (DST)

To disable NTP server sync with internet 

# timedatectl set-ntp 0

Change the current date and time

1. To change the date, use the following syntax:

# timedatectl set-time [YYYY-MM-DD]

2. To change the current time, use the following syntax. Enter the hour by using a 24-hour clock.

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

Change Time Zone

Use the following command to list all available time zones:

# timedatectl list-timezones

Use the set-timezone argument to change the time zone. The following example changes the time zone to Asia/Kolkata:

# timedatectl set-timezone Asia/Kolkata

To Sync with NTP Server below is process.

systemctl stop ntpd

# ntpdate kvm01.darole.org

systemctl start ntpd



No comments:

Post a Comment