FreeBSD Configure system time

Source: Internet
Author: User
Tags current time time zones local time set time

For the network operating system, because to provide services to multiple customers, you must have a precise system time. You can use the date command to display the current time:

$ date
1999年 4月10日 星期六 18时51分39秒 CST

The date command is exported in Chinese if the specified environment variable lc_all is ZH_CN. EUC, this is a standard way to localize.

Because customers that use the network operating system on the Internet may come from different parts of the world, the time system must be able to identify different time zones. The CMOS time in the computer can be set to two different times, one is to set the CMOS time to Greenwich Mean time, use time zone corrections to give the correct time for the local time zone, the other is to set the CMOS time to the local time zone, and then use the local time zone correction to get Greenwich Mean time. This allows the system to use standard time when communicating with other computers, avoiding differences in time between computers in different time zones.

System Setup will ask the user to use that time setting when setting up the locale, or you can use the Tzsetup command to set the time zone information directly after the system installation is complete. All time zone information is saved in the/usr/share/zoneinfo directory, and the local time zone settings information is stored in the/etc/localtime file. In addition, each user can use the environment variable TZ to set a different time zone to the system, which overrides the system settings.

The root user can change the system time with the parameter date, for example, the following command sets the time to March 1, 1999, 1:54 P.M..

# date 9903011354
1999年 3月 1日 星期一 13时54分00秒 CST

You can see that the time format is year, month, day, time, minute, each account for two numbers, its form is yymmddhhmm, most of the time is a small adjustment, you can omit the front of the month and the day part, and only use four digits to express the time, points, such as HHMM.

Synchronizing time over the Internet

Manually set the time on the one hand inconvenient, on the other hand also depends on the correctness of the local administrator's clock, then the network of different administrators to manage the computer time must be biased, the time deviation of different computers will be some requirements of time synchronization of the service has an impact. The solution to this problem is simple, connected to a time synchronization on a server that can provide precise time.

When your computer is connected to the Internet, you can communicate with many time servers that exist on the Internet for accurate time. In the TCP/IP protocol, the protocol for synchronization time is the NTP protocol, and the sites that provide NTP services on the Internet are clepsydra.dec.com, ben.cs.wisc.edu, truechimer.waikato.ac.nz, etc. Although the NTP protocol itself considers network latency, network latency can, after all, affect the accuracy of time, so you should choose a time server that is closest to the local computer.

The use of/stand/sysinstall can also set time synchronization, can be based on the region to select the appropriate time server, however, because the network connection is not necessarily consistent with the region, it can not be entirely based on the geographical proximity to select the time server.

A simple application that uses the NTP protocol to update the time on its own computer is ntpdate, and also needs to be executed with root permissions:

# ntpdate clepsydra.dec.com
10 Apr 19:26:49 ntpdate: step time server 204.123.2.5 offset 517.837146

Ntpdate run after the exit, in order to maintain the correctness of time, it is necessary to automatically synchronize time at intervals, you can put ntpdate into cron, every once in a while. However, the system provides another daemon, XNTPD, to automate the cycle of time synchronization, which is more appropriate for computers that have a permanent connection to the Internet. In order to run the XNTPD daemon, first create the/etc/ntp.conf file, which should include the name of the time server and a temporary file name.

server    clepsydra.dec.com
driftfile  /etc/ntp.drift

Then you need to run this daemon and do time synchronization.

# xntpd -c /etc/ntp.conf -p /var/run/xntpd.pid

Where the-c parameter specifies the ntp.conf as the configuration file, and the process identification number of the XNTPD is recorded with Xntpd.pid. Both Ntpdate and XNTPD can be automatically executed at startup by changing the options in rc.conf.

xntpd_enable="YES"   # Run xntpd Network Time Protocol (or NO).
xntpd_program="xntpd"  # path to xntpd, if you want a different one.
xntpd_flags="-c /etc/ntp.conf -p /var/run/xntpd.pid" # Flags to xntpd (if enabled).

If you want multiple computers on your local network to have time synchronization, it is not a good idea to connect each computer to an external time server. The better idea is to use a computer to synchronize with an external time server, and then it's time to be a standard time to be used as a local time server, while other computers are synchronized with this local time server. XNTPD is designed for this purpose and can be used as an NTP server to provide time. The configuration file for the xntpd used as the time server should be:

server    clepsydra.dec.com
driftfile  /etc/ntp.drift
broadcast  192.168.1.255

This adds a broadcast address: 192.168.1.255, periodically broadcasting the correct time to other computers on the LAN. The broadcast address is modified according to its own network, or a Class D multicast (multicast) URL corresponding to the NTP protocol is used 224.0.1.1, but the user's network must support multicast capabilities. Because of the use of broadcast or multicast, so that other computers within the network can not configure ntp.conf, the direct start of the XNTPD,XNTPD can be listened to the server broadcast information to get accurate time. Of course, you can configure the ntp.conf file on each computer without setting a broadcast address, specifying that all computers access this time server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.