NTP协议以及ntpclinet使用 From Evernote: NTP协议以及ntpclinet使用 NTP全称是Network Time Protocol,是用来让计算机之间实现时间同步的协议


NTP全称是Network Time Protocol,是用来让计算机之间实现时间同步的协议。发布这种校对时间的服务器,就是NTP Server;而在Internet中的任何主机上都可以使用NTP客户端程序从NTP Server上读取时间,以实现网络时间同步的功能。


国内的NTP Server基本都属于科研教育机构所有,普通社会组织发布的NTP Server并不多,以下是搜集的一些国内可用的NTP Server: 

1.cn.pool.ntp.org 

2.cn.pool.ntp.org 

3.cn.pool.ntp.org

0.cn.pool.ntp.org

cn.pool.ntp.org

tw.pool.ntp.org

0.tw.pool.ntp.org

1.tw.pool.ntp.org

2.tw.pool.ntp.org

3.tw.pool.ntp.org


ntpclient是可在类Unix系统上运行的ntp客户端程序,用于从网络上的NTP服务器上读取时间并设置到本地主机上。源码的下载地址为:http://doolittle.icarus.com/ntpclient/。

ntpclient的使用方法:

pavel@pavel-desktop ~/test/ntpclient-2010 $ ./ntpclient
     Usage: ./ntpclient [-c count] [-d] [-f frequency] [-g goodness] -h hostname
             [-i interval] [-l] [-p port] [-q min_delay] [-r] [-s] [-t]

主要选项说明:

     -h hostname:NTP Server地址

     -c count:从NTP Server上读取时间的执行次数

     -i:执行多次校时操作的时间间隔,默认为600s

     -s:读取到时间后设置到本地主机中

     -g goodness:当读取时间与本地时间的差值精确度好于goodness(以ms为单位)时程序退出,否则一直执行。goodness默认为0,表示一直执行

     -p port:ntpclient访问ntp服务器时所使用的本地UDP端口,默认为任何可用的端口

     -d:打印调试信息,该特性可在编译时禁止掉


ntpclient应用程序的执行说明:

$ sudo ./ntpclient -h 114.80.81.1 -c 10 -i 10 -s

以上调用表示NTP服务器地址为114.80.81.1,连续执行10次,每次间隔时间为10s,从NTP服务器上读取到时间后设置到本地主机中。

pavel@pavel-desktop ~/test/ntpclient-2010 $ sudo ./ntpclient -h 114.80.81.1 -c 10 -i 10 -s

 day     second      elapsed     stall     skew   dispersion   freq

40678 20520.811   49937.0     31.5    7163.7  41885.4         0

其中:

day,second:表示当前时间距离1900年1月1日的时间,分别为天数和秒

elapsed:表示从发出读取时间命令到时间信息收到总共花费的时间,以us为单位

skew:表示服务器时间与本地主机时间的偏差,以us为单位

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值