Friday, December 9, 2016

System Time V

Configuring NTP 


In order to use NTP to configure system time with an NTP time provider, you must first install 
the ntpd daemon on your Linux system. You can use the


rpm –q ntp 


command at the shell prompt to do this, like so:



openSUSE:~ # rpm -q ntp
ntp-4.2.6p5-15.5.1.i586




1) NTP is usually installed by default on most Linux systems. If it hasn’t been, you can use the
software package management utility of your choice to install it. Once this is done, you need to
next edit the

/etc/ntp.conf 

file in a text editor. The first thing you need to do is ensure that the
following entries exist for the local clock, which is used if the time server is not available:


server 127.127.1.0 # local clock (LCL) 
fudge 127.127.1.0 stratum 10 # LCL is unsynchronized 



These directives tell the ntpd daemon to get time from the local clock in the event it can’t reach 
any of the configured NTP time providers. 



2) Next, you need to add entries to the file for network time providers you want your system to
sync time with. Here is the syntax:



server time_server_IP_address_or_DNS_name 

You can specify the IP address or DNS name of any NTP time provider you want to use.



It could be any of the following:



• An NTP time provider on your network 

A public NTP time provider on the Internet 
You can visit http://support.ntp.org/bin/view/Servers/WebHome to view a list of publicly available
NTP time providers on the Internet. If you wish, you can use an NTP pool time server. The
pool.ntp.org domain uses DNS round robin to make a random selection from a pool of time providers who have volunteered to be in the pool. That way, no one public NTP server is overloaded with
time synchronization requests. To use this, simply add the following server directive in
addition to the local clock server directive just discussed:



server pool.ntp.org 



When you’re done, save your changes and then close the file. Before you actually start the
ntpd daemon, however, you need to do a quick, one-time synchronization with your NTP time
provider. The issue here is insane time. If your system time is already more than 17 minutes off
from the time on the NTP time provider, you must get the two systems within this time window
before NTP will work.



3) You can eliminate insane time issues by entering 


ntpdate address_of_time_provider


at the shell prompt. This will perform an initial synchronization to get time close before you start the daemon. You may actually need to run the command multiple times if the times are really far apart between your system and the NTP time provider. The ntpd daemon must be stopped 
before you run the ntpdate command!


Newer versions of NTP on newer Linux distributions also allow you to use the ntptimeset 
option with the ntpd daemon itself to accomplish the same thing. Instead of specifying start,
stop, or restart with the daemon init script, you enter (on an system that uses init)


/etc/init.d/ntp ntptimeset 


or


rcntp ntptimeset 


at the shell prompt. When you do, a quick time sync takes place
with the time provider, as in this example:



ws1:/ # rcntp ntptimeset
Time synchronized with pool.ntp.org



4) Once this is done, you can then start the ntpd daemon using its init script in the appropriate
init script directory used by your distribution. If your system uses rc scripts, you can simply enter



rcntp start 



at the shell prompt, like this:



ws1:/ # rcntp start
Time synchronized with pool.ntp.org
Starting network time protocol daemon (NTPD) done



5) You should configure the ntpd daemon to start every time the system boots using the



insserv ntp 



command. After starting the daemon, you can check the ntp log file with the tail command 
to verify that no errors occurred. 



If your distribution uses systemd, you start and stop ntpd using the systemctl command. For
example, to start the ntpd daemon, you would enter



systemctl start ntp 



at the shell prompt. You can verify that it started correctly by entering



systemctl status ntp 



at the shell prompt.



LX0-104 Exam Objectives (N)

No comments:

Post a Comment