Configuring NTP Client on Linux
Published:
How Can I configure a NTP Client?
Recently I had this problem, where a Linux Server was with the date out of date.
The Ntp or Network Time Protocol is a service that synchronized with Ntp Server get the right time.
Example
Installation
The NTP can be installed by using various package managers like BSD, Linux, Windows and MacOS.
I’m going to do a example with Linux because I prefer.
$ yum -y update && yum install -y ntp ntpdate
In this case I’m using the Centos version 7 running in Docker.
Ok, is it configurable?
Yes!!
Where Can I Configure?
$ vim /etc/ntp.conf
Search by line with server text, for example:
server 0.centos.pool.ntp.org iburst
So, Let’s change this information.
$ sed -i 's/.\.centos.pool.ntp.org/a.ntp.br/g' /etc/ntp.conf
Basically, this command replace centos ntp server per brazil ntp server because I'm from Brazil :).
Command Description:
- -i = Edit file in place.
- s/from/to/g = Replace texto into from to text after /.
Ok, Will We Apply the rules?
Applying
$ ntpdate a.ntp.br #Same server that is into ntp.conf..
The command ntpdate does a “brute force” for apply immediately the sinchronization with Brazil NTP Server.
$ systemctl start ntpd.service
This command start the ntp service.
Thanks :D