ubuntu和windos 局域网NTP配置时间同步设置方法

Ubuntu上位机和局域网内windows系统ntp配置

NTP或网络时间协议是一种协议,用于将网络中的所有系统时钟同步以使用同一时间。当我们使用术语NTP时,我们指的是协议本身,也指网络计算机上运行的客户端和服务器程序。 NTP属于传统的TCP /IP协议套件,可以很容易地归类为它最古老的部分之一。

最初设置时钟时,需要在设置时钟之前的5到10分钟内进行六次交换。网络中的时钟同步后,客户端每10分钟更新一次与服务器的时钟。通常,这是通过单个消息交换(事务)完成的。这些事务使用系统的端口号123。

在本文中,我们将描述如何执行以下操作的step-by-step过程:

  • 在Ubuntu计算机上安装和配置NTP服务器。
  • 将NTP客户端配置为与服务器时间同步。
  1. ubunutu下配置ntp服务器端

为了从Internet信息库安装最新的可用软件版本,您的本地信息库索引需要与它们保持一致。以sudo身份运行以下命令,以更新您的本地存储库索引:

$ sudo apt-get update

  1. 使用apt-get安装NTP服务器

请以sudo身份运行以下命令,以便从APT存储库安装NTP服务器安装程序:

$ sudo apt-get install ntp

  

输入“Y”继续安装

  1. 安装完成后输入命令以验证安装成功和查看版本号

$ sntp --version

  

  1. 通过运行以下命令,以sudo的身份在nano编辑器中打开文件:

$ sudo vi /etc/ntp.conf

 

修改为下图示字节

 

以下字节为修改完成后的ntp.Conf文件

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Leap seconds definition provided by tzdata

leapfile /usr/share/zoneinfo/leap-seconds.list

# Enable this if you want statistics to be logged.

#statsdir /var/log/ntpstats/

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

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board

# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for

# more information.

server 0.us.pool.ntp.org

server 1.us.pool.ntp.org

server 2.us.pool.ntp.org

server 3.us.pool.ntp.org

# Use Ubuntu's ntp server as a fallback.

pool ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for

# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>

# might also be helpful.

#

# Note that "restrict" applies to both servers and clients, so a configuration

# that might be intended to block requests from certain clients could also end

# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.

restrict -4 default kod notrap nomodify nopeer noquery limited

restrict 10.10.10.0 mask 255.255.255.0 nomodify

restrict -6 default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.

restrict 127.0.0.1

restrict ::1

# Needed for adding pool entries

restrict source notrap nomodify noquery

# Clients from this (example!) subnet have unlimited access, but only if

# cryptographically authenticated.

#restrict 192.168.123.0 mask 255.255.255.0 notrust

# If you want to provide time to your local subnet, change the next line.

# (Again, the address is an example only.)

#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the

# next lines.  Please do this only if you trust everybody on the network!

#disable auth

#broadcastclient

#Changes recquired to use pps synchonisation as explained in documentation:

#http://www.ntp.org/ntpfaq/NTP-s-config-adv.htm#AEN3918

#server 127.127.8.1 mode 135 prefer    # Meinberg GPS167 with PPS

#fudge 127.127.8.1 time1 0.0042        # relative to PPS for my hardware

#server 127.127.22.1                   # ATOM(PPS)

#fudge 127.127.22.1 flag3 1            # enable PPS API

# GPS Serial data reference

server 127.127.28.0 minpoll 4 maxpoll 4

fudge  127.127.28.0 time1 0.1 refid PPS

# GPS PPS reference

server 127.127.28.1 minpoll 4 maxpoll 4

fudge  127.127.28.1 refid PPS

  1. 现在,通过以下命令检查NTP服务的状态:

$ sudo service ntp status或者wach -n 1 ntpd -pn(加root

 

 

活动状态验证您的NTP服务器已启动并正在运行。

  1. 配置防火墙,以便客户端可以访问NTP服务器

$ sudo ufw allow from any to any port 123 proto udp

  

您的Ubuntu主机现已配置为用作NTP服务器。重新启动NTP服务器

  1. 重新启动NTP服务器

为了使以上更改生效,您需要重新启动NTP服务。为此,以sudo身份运行以下命令:

$ sudo service ntp restart

  1. 配置与局域网连接的IP

  

Windows下配置NTP服务与UBUNTU进行局域网内时间同步。

  1. windows配置NTP服务,按下win+R 输入regedit先修改注册表  按照下面的路径修改 

\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\Ntpserver

 

 

  1. 然后win+R 输入gpedit.msc 按照图修改

 

  1. 第一个配置NTP客户端

 

  1. 修改服务

 

  1. 关闭防火墙

  1. 配置客户端IP端口与服务器在一个网段

  1. 打开控制面板设置时间

以上为windows在局域网内与服务器端的时间同步NTP配置。

至此Ubuntu作为服务器端,可连接外网的情况下可以自动设定时间,同时Windows系统连接服务器端的一个网口通过局域网NTP的服务可同步时间(即使Ubuntu在不连外网的情况下是错的时间Windows也是错的时间)

猜你喜欢

转载自blog.csdn.net/zzssllxiaobai/article/details/125594463