Linux Time

Show time on software clock:  date

Set time on software clock:  date -s "2 OCT 2006 18:00:00"

Sync software clock to hardware clock: hwclock --systohc

Sync software clock to hardware clock on shutdown:

  • Add CLOCK_SYSTOHC="yes" to /etc/conf.d/clock

 

Setup NTP:

  1. echo "net-misc/ntp caps" >> /etc/portage/package.use
  2. emerge -av ntp
  3. Manual time sync can be done with ntpdate:
    1. Run ntpdate [server]   #only works if ntpd isn't running.  If you are running ntpd, you don't need to run ntpdate.
    2. You can have it run on boot:
      1. Put NTPCLIENT_OPTS="-b -u firstserver secondserver thirdserver" in /etc/conf.d/ntp-client
      2. To have safe placement in the startup sequence, add a line of after net.eth0 after the line of "need net" in /etc/init.d/ntp-client
      3. To be extra safe, you can add the following to /etc/conf.d/net:

                         postup() {

                            if [[ "${IFACE}" == "eth0" ]] ; then
                                # Wait for connection to be ready to communicate
                                sleep 5
                            fi

                            return 0
                         }
      4. Then make it start on boot:
        1. /etc/init.d/ntp-client start
        2. rc-update add ntp-client default
  4. Continuous sync can be done with ntpd:
    1. Configure it by editing /etc/ntp.conf
    2. Start it: /etc/init.d/ntpd start
    3. Make it start on boot:  rc-update add ntpd default
    4. Checking it's sync status...    "It may take up to 4 hours of semi-continuous reachability to calibrate the clock before you achieve stratum 3 status. If the stratum status hasn't changed in a few hours, your synchronization is definitely failing. It should settle at 3, from synchronization with stratum 2 servers."
      1. ntpq -c readvar | grep stratum   # Using full name of option
      2. ntpq -c rv | grep stratum        # Using abbreviation
      3. ntpq -c pe   #check what peers you are connected to (and in turn what they are connected to
      4. ntpq -c rv   #For some more information

Powered by Linux