2.2.2. Network Time Protocol Setup
As opposed to the manual setup described above, you can also synchronize the system clock with a remote server over the Network Time Protocol (NTP). For the one-time synchronization only, use the ntpdate command:
- Firstly, check whether the selected NTP server is accessible:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# ntpdate -q server_address
~]# ntpdate -q server_address
For example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# ntpdate -q 0.rhel.pool.ntp.org
~]# ntpdate -q 0.rhel.pool.ntp.org
- When you find a satisfactory server, run the ntpdate command followed by one or more server addresses:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# ntpdate server_address...
~]# ntpdate server_address...
For instance:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# ntpdate 0.rhel.pool.ntp.org 1.rhel.pool.ntp.org
~]# ntpdate 0.rhel.pool.ntp.org 1.rhel.pool.ntp.org
Unless an error message is displayed, the system time should now be set. You can check the current by setting typingdate
without any additional arguments as shown in Section 2.2.1, “Date and Time Setup”. - In most cases, these steps are sufficient. Only if you really need one or more system services to always use the correct time, enable running the ntpdate at boot time:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# chkconfig ntpdate on
~]# chkconfig ntpdate on
For more information about system services and their setup, see Chapter 12, Services and Daemons.Note
If the synchronization with the time server at boot time keeps failing, i.e., you find a relevant error message in the/var/log/boot.log
system log, try to add the following line to/etc/sysconfig/network
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NETWORKWAIT=1
NETWORKWAIT=1
However, the more convenient way is to set the ntpd daemon to synchronize the time at boot time automatically:
- Open the NTP configuration file
/etc/ntp.conf
in a text editor such as vi or nano, or create a new one if it does not already exist:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# nano /etc/ntp.conf
~]# nano /etc/ntp.conf
- Now add or edit the list of public NTP servers. If you are using Red Hat Enterprise Linux 6, the file should already contain the following lines, but feel free to change or expand these according to your needs:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow server 0.rhel.pool.ntp.org iburst server 1.rhel.pool.ntp.org iburst server 2.rhel.pool.ntp.org iburst server 3.rhel.pool.ntp.org iburst
server 0.rhel.pool.ntp.org iburst server 1.rhel.pool.ntp.org iburst server 2.rhel.pool.ntp.org iburst server 3.rhel.pool.ntp.org iburst
Theiburst
directive at the end of each line is to speed up the initial synchronization. As of Red Hat Enterprise Linux 6.5 it is added by default. If upgrading from a previous minor release, and your/etc/ntp.conf
file has been modified, then the upgrade to Red Hat Enterprise Linux 6.5 will create a new file/etc/ntp.conf.rpmnew
and will not alter the existing/etc/ntp.conf
file. - Once you have the list of servers complete, in the same file, set the proper permissions, giving the unrestricted access to localhost only:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 restrict -6 ::1
restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 restrict -6 ::1
- Save all changes, exit the editor, and restart the NTP daemon:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# service ntpd restart
~]# service ntpd restart
- Make sure that
ntpd
is started at boot time:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# chkconfig ntpd on
~]# chkconfig ntpd on