Ubuntu and windos LAN NTP configuration time synchronization setting method

Ubuntu host computer and windows system ntp configuration in LAN

NTP or Network Time Protocol is a protocol used to synchronize all system clocks in a network to use the same time. When we use the term NTP, we mean the protocol itself, but also the client and server programs running on network computers. NTP belongs to the traditional TCP/IP protocol suite and can easily be classified as one of its oldest parts.

When initially setting the clock, six swaps are required between 5 and 10 minutes before the clock is set. After the clocks in the network are synchronized, the client updates the clock with the server every 10 minutes. Typically, this is done with a single message exchange (transaction). These transactions use the system's port number 123.

In this article, we describe a step-by-step process of how to:

  • Install and configure an NTP server on an Ubuntu computer.
  • Configure the NTP client to synchronize with the server time.
  1. Configure ntp server under ubunutu

In order to install the latest available software versions from Internet repositories, your local repository index needs to be consistent with them. Run the following command as sudo to update your local repository index:

$ sudo apt-get update

 

  1. Install NTP server using apt-get

Please run the following command as sudo in order to install the NTP server installer from the APT repository:

$ sudo apt-get install ntp

  

Enter "Y" to continue the installation

  1. After the installation is complete, enter the command to verify the installation is successful and view the version number

$ sntp --version

  

  1. Open the file in the nano editor as sudo by running the following command:

$ sudo you /etc/ntp.conf

 

 

Modify it to the bytes shown below

 

The following bytes are the modified ntp.Conf file

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

drift file /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. Now, check the status of the NTP service by the following command:

$ sudo service ntp status or wach -n 1 ntpd -pn (add root )

 

 

 

The active state verifies that your NTP server is up and running.

  1. Configure the firewall so that clients can access the NTP server

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

  

Your Ubuntu host is now configured to act as an NTP server. Restart the NTP server

  1. Restart the NTP server

In order for the above changes to take effect, you need to restart the NTP service. To do this, run the following command as sudo:

$ sudo service ntp restart

  1. Configure the IP connected to the LAN

  

Configure NTP service under Windows and UBUNTU for time synchronization in LAN.

  1. Windows configures the NTP service, press win+R and enter regedit to modify the registry first and modify it according to the following path 

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

 

 

 

  1. Then win+R enter gpedit.msc to modify according to the figure

 

 

  1. The first configures the NTP client

 

 

  1. modify service

 

 

  1. turn off firewall

 

  1. Configure the client IP port to be on the same network segment as the server

 

  1. Open the control panel to set the time

 

The above is the NTP configuration for windows to synchronize time with the server in the local area network.

So far, Ubuntu, as the server, can automatically set the time when it can be connected to the external network. At the same time, the Windows system can be connected to a network port on the server to synchronize the time through the LAN NTP service (even if Ubuntu is not connected to the external network, it is wrong. Time Windows is also wrong time)

Guess you like

Origin blog.csdn.net/zzssllxiaobai/article/details/125594463