How to Set Up an NTP Server on Windows and Configure Linux with Chrony (NTP Server)
In this post, I'll show you how to configure a Windows machine as an NTP time server (master) and set up Linux machines as slaves. It's pretty simple, and we'll be using the command line for this tutorial, it's quicker and easier than using the GUI.
What is NTP?
Before we dive in, let's quickly answer the question: NTP stands for Network Time Protocol. It's a protocol that allows computers to sync their clocks over a network. The NTP server provides the correct time to other devices, ensuring they're all on the same clock. This helps prevent problems caused by computers running on different times, which can affect things like logging, file timestamps, and even security.
Step 1: Set Up the NTP Master on Windows
1. Open Command Prompt as Administrator
2. Enable the Windows Time Service: Windows uses a service called W32Time for time synchronization. To enable it, type this in your Command Prompt: (This makes sure the time service starts automatically when your PC boots up)
sc config w32time start= auto
3. Start the Time Service: Now, start the time service by entering:
net start w32time
4. Configure the NTP Server: Next, set up your Windows PC to act as an NTP server. Use the following command: (Here i used pool.ntp.org as the time source, but you can replace it with any other NTP)
w32tm /config /manualpeerlist:"pool.ntp.org" /syncfromflags:manual /reliable:YES /update
5. Enable the NTP Server on Windows: This command ensures that the Windows machine will function as an NTP server by modifying the Windows registry:
reg add HKLM\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer /v Enabled /t REG_DWORD /d 1 /f
6. Update the Configuration: After making changes, update the time configuration with the following command:
w32tm /config /update
7. Restart the Time Service: For the changes to take effect, restart the time service with these commands:
net stop w32time net start w32time
8. Verify the Configuration: To check if everything is working, run:
w32tm /query /status
This should show you the current time synchronization status(refer the below image).
Step 2: Set Up Chrony on Linux to Sync with the Windows NTP Server
Now that your Windows machine is ready as an NTP server, let's configure your Linux machine to sync with it using Chrony. Chrony is a more modern alternative to NTPD and works great for most Linux systems.
1. Install Chrony: First, make sure Chrony is installed on your Linux machine. Depending on your Linux distribution, you can use one of the following commands:
For Ubuntu/Debian:
sudo apt-get install chrony
For CentOS/RHEL:
sudo yum install chrony
2. Configure Chrony to Use Your Windows NTP Server: After installing Chrony, you need to tell it to sync with your Windows server. Open the Chrony configuration file by running:
sudo nano /etc/chrony/chrony.conf
At the top of the file, add your Windows NTP server's IP address: and comment out the default servers (refer the image)
server <Windows_IP_Address> iburst
Replace <Windows_IP_Address> with the actual IP address of your Windows machine.
3. Start the Chrony Service: Once the configuration is updated, start the Chrony service with the following command:
sudo systemctl start chronyd
4. Enable Chrony to Start on Boot: To ensure Chrony starts automatically when the system reboots, use:
sudo systemctl enable chronyd
5. Verify Time Sync: To check if your Linux machine is syncing correctly with the Windows NTP server, use
chronyc tracking
This command will show you the synchronization status. If everything is working, you’ll see information about how well your system is synced with the Windows NTP server. (refer the image. you can see the windows ip here)
Conclusion: That's all ! You've now set up a Windows NTP server and configured your Linux machines to sync their time using Chrony. This setup ensures all your devices are using the same accurate time, which is critical for proper operation.
If you found this guide helpful, please share it! If you have any questions or run into any issues, feel free to leave a comment below.
Continue Reading on ReadSide
Join thousands of writers who use ReadSide to write better and stay consistent.
Read Full Article →Free to read • Comment your doubts