Linux NTP Server Setup: Install, Configure and Verify (Step by Step)

To run your own Linux NTP server, install the ntp package, point /etc/ntp.conf at upstream pool servers, allow your local subnet, and open UDP port 123. Then check it with ntpq -p. Below are the exact commands for Debian/Ubuntu and RHEL-style systems, plus chrony notes and fixes for when clients won’t sync.
Table of Contents
- Why NTP Matters
- Prerequisites
- Installing NTP
- Basic NTP Configuration
- Configuring Access Control
- Starting and Enabling NTP Service
- Verifying NTP Operation
- Troubleshooting Common Issues
- NTP Not Synchronizing
- Time Drift Issues
- Security Considerations
- Advanced Configuration
- Setting Up NTP Logging
- Configuring NTP Peers
- Monitoring NTP Performance
- Integration with System Services
- Best Practices
- Conclusion
Why NTP Matters
Accurate time synchronization is essential for:
- Log file accuracy and debugging
- Security protocol functioning
- Database transaction management
- Certificate validation
- Scheduled task execution
Prerequisites
Before we begin, ensure you have:
- Root or sudo access to your Linux system
- A stable internet connection
- Basic understanding of command line operations
Installing NTP
First, let’s install the NTP package. On Ubuntu/Debian systems:
sudo apt update
sudo apt install ntpFor RHEL/CentOS systems:
sudo yum install ntpBasic NTP Configuration
The main NTP configuration file is located at /etc/ntp.conf. Let’s configure it properly:
sudo nano /etc/ntp.confAdd these basic server entries:
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburstThe iburst option speeds up the initial synchronization process.
Configuring Access Control
To allow clients to sync with your NTP server, add these lines to /etc/ntp.conf:
# Local network access control
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrapReplace 192.168.1.0 with your network address.
Starting and Enabling NTP Service
Start the NTP service and enable it to run at boot:
sudo systemctl start ntp
sudo systemctl enable ntpFor systems using chronyd:
sudo systemctl start chronyd
sudo systemctl enable chronydVerifying NTP Operation
Check if NTP is synchronizing correctly:
ntpq -pThis command displays a list of NTP servers and their status. The output should show connected servers and their offset values.
Troubleshooting Common Issues
NTP Not Synchronizing
If you’re experiencing synchronization issues:
Check firewall settings:
sudo ufw allow 123/udpVerify NTP daemon status:
sudo systemctl status ntpForce a time sync:
sudo ntpd -gqTime Drift Issues
If you notice significant time drift:
Check system logs:
sudo journalctl -u ntpVerify hardware clock synchronization:
sudo hwclock --systohcSecurity Considerations
Restrict NTP Access
Add these lines to /etc/ntp.conf:
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noqueryUse NTP Pool Servers
Prefer pool.ntp.org servers over individual timeservers for better reliability and security.
Advanced Configuration
Setting Up NTP Logging
Add logging configuration to monitor NTP activity:
logfile /var/log/ntp.log
logconfig =allConfiguring NTP Peers
For redundancy in larger networks, configure peer relationships:
peer 192.168.1.100
peer 192.168.1.101Monitoring NTP Performance
Implement these monitoring practices:
Regular offset checks:
ntpstatLong-term drift monitoring:
grep "time offset" /var/log/ntp.logIntegration with System Services
For essential services requiring precise timing, consider adding NTP as a dependency in their systemd service files:
[Unit]
After=ntp.service
Requires=ntp.serviceBest Practices
- Use at least four time sources for reliability
- Implement proper access controls
- Regular monitoring of time synchronization
- Keep NTP software updated
- Document your NTP configuration
Conclusion
A properly configured NTP server is crucial for maintaining accurate time synchronization across your network. Regular monitoring and maintenance will ensure continued reliable operation.
For more Linux system administration topics, check out our guide on Understanding Linux Process Management, which complements your network infrastructure knowledge.
Remember to periodically review and update your NTP configuration as your network evolves and new security best practices emerge.
More posts
All Linux

