Install

The first thing to do is install the NTP server. Grab the package by running:

# emerge --sync
# emerge ntp

Start the service

To make sure the NTP service starts after installing it, run:

# /etc/init.d/ntpd start

The ntp.conf file

The NTP configuration file can be found at:

# nano -w /etc/ntp.conf

There are a few settings that can be changed in there, but for most people the only settings of interest would be any “server” entries. The default for Gentoo looks like:

server ntp.aegean.gr
# Pools for Gentoo users
server 0.gentoo.pool.ntp.org
server 1.gentoo.pool.ntp.org
server 2.gentoo.pool.ntp.org
server 3.gentoo.pool.ntp.org

# you should not need to modify the following paths
driftfile       /var/lib/ntp/ntp.drift

# To deny other machines from changing the
# configuration but allow localhost:
restrict default nomodify nopeer
restrict 127.0.0.1

Time zones

Occasionally, your timezone settings might be incorrect. For example it could be set to EST when it should be CST. There are a couple of ways to set the timezone:

tzselect

or

  • Copy the timezone info manually:
cp /usr/share/zoneinfo/Europe/Athens /etc/localtime

Testing with ntpdate

Before using an external NTP server to sync your time you should make sure you can actually connect to the server from your machine. Fortunately there’s a tool for that included with the NTP server named “ntpdate”.

The ntpdate command will sync your clock with an NTP server. It’s similar to what the NTP server does on a regular basis.

You usually shouldn’t use ntpdate for anything other than testing purposes unless you want to make sure your clock only syncs at particular times of day (by using cron to run ntpdate just at those times). Otherwise you’re better off running the NTP server because it will use less bandwidth and keep your time more accurate (by tracking your clock’s drift over time and adjusting accordingly).

The ntpdate command will not run when the NTP server is running. If you run ntpdate and get a response like “the NTP socket is in use”, that means your NTP server is running. Stop it with the command:

sudo /etc/init.d/ntpd stop

You can now run ntpdate with the server you want to sync against as an argument. For example, to tell ntpdate to try and sync with “pool.ntp.org”, run:

sudo ntpdate pool.ntp.org

When you’re finished testing remember to start NTP back up again:

sudo /etc/init.d/ntpd start

 

Finalize synchronization

To verify that your system time has changed correctly, run

date

Also, consider to synchronize your hardware time with your system time (for example, here, upon reboot, the time went again out of sync). To store the Linux date and time in CMOS, issue the following command

hwclock –systohc

Again, to check your work, run:

hwclock –show