ubuntu安装ntp时间服务器

1、安装ntp软件
  sudo apt-get install ntp
2、修改配置文件
      sudo vim /etc/ntp.conf
    driftfile /var/lib/ntp/ntp.drift
    statistics loopstats peerstats clockstats
    filegen loopstats file loopstats type day enable
    filegen peerstats file peerstats type day enable
    filegen clockstats file clockstats type day enable
    server ntp.ubuntu.com
    restrict -4 default kod notrap nomodify nopeer noquery
    restrict -6 default kod notrap nomodify nopeer noquery
    restrict 192.168.10.0 mask 255.255.255.0 nomodify
    restrict 127.0.0.1
    restrict ::1
  主要是在配置文件中的:
  restrict -6 default kod notrap nomodify nopeer noquery
  语句后面加入:
  restrict 192.168.0.0 mask 255.255.255.0 nomodify
      主要是允许能同步的服务器所在的内部网段
3、权限设定
  权限设定主要以restrict这个参数来设定,主要的语法为:
  restrict IP mask netmask_IP parameter
  其中IP可以是软体位址,也可以是 default ,default 就类似0.0.0.0
  至于 paramter则有:
  ignore:关闭所有的NTP 连线服务
  nomodify:表示Client 端不能更改 Server 端的时间参数,不过Client端仍然可以透过Server 端來进行网络较时。
  notrust:该 Client 除非通过认证,否则该 Client 来源将被视为不信任网域
  noquery:不提供 Client 端的时间查询
  如果 paramter完全没有设定,那就表示该 IP (或网域) 『没有任何限制!』
4、上层主机设定
  上层主机选择ntp.ubuntu.com,要设定上层主机主要以server这个参数来设定,语法为:server [IP|FQDN] [prefer]
  Server 后面接的就是我们上层的Time Server !而如果 Server 参数后面加上perfer 的话,那表示我们的 NTP 主机主要以该部主机来作为时间较正的对应。另外,为了解决更新时间封包的传送延迟动作,可以使用driftfile 来规定我们的主机在与Time Server沟通时所花费的时间,可以记录在 driftfile 后面接的档案内
5、如果有设置防火墙必须取消对123端口的限制
  iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT
6、重启ntp服务
  sudo /etc/init.d/ntp restart
7、客户端同步(也就是要进行同步的内网服务器)
  sudo ntpdate 192.168.112.1
  可同时查看服务器的硬件时钟并进行更改:
  sudo hwclock
  sudo hwclock -w
8、查看ntp的端口,应该看到123端口
     netstat -unlnp
9、查看ntp服务器与上层间的联系
     ntptrace -n 127.0.0.1
10、查看ntp服务器与上层ntp服务器的状态
      ntpq -p
      其中,
      remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
      refid - 参考上一层ntp主机地址
      st - stratum阶层
      when - 多少秒前曾经同步过时间
      poll - 下次更新在多少秒后
      reach - 已经向上层ntp服务器要求更新的次数
      delay - 网络延迟
      offset - 时间补偿
      jitter - 系统时间与bios时间差

posted @ 2017-04-24 11:14  牛头人  阅读(2272)  评论(0编辑  收藏  举报