This script installs and configures the NTP service on Ubuntu.
It sets the system timezone to Asia/Dhaka (UTC+6) and restricts NTP access so that only private IP ranges (192.168.0.0/16, 10.0.0.0/8, and 103.135.132.0/23) can query the server. All other networks are denied.
- β
Installs NTP daemon (
ntppackage). - β Sets timezone to Bangladesh Standard Time (UTC+6).
- β Configures Asia pool NTP servers for synchronization.
- β
Restricts access to private subnets only:
192.168.0.0/1610.0.0.0/8103.135.132.0/23
- β Blocks all other external IPs by default.
Save the script as ntp-private-only.sh.
chmod +x ntp-private-only.sh./ntp-private-only.shAfter running, check:
timedatectl status # Verify timezone is Asia/Dhaka (UTC+6)
ntpq -p # Show NTP peers and sync statusrestrict default ignoreβ denies all clients by default.restrict 127.0.0.1andrestrict ::1β allow local queries.restrict <subnet> mask <netmask> nomodify notrapβ allows time queries from specified subnets.- Only LAN/private ranges and your custom subnet can access NTP.
restrict default ignore
restrict 127.0.0.1
restrict ::1
restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap
restrict 10.0.0.0 mask 255.0.0.0 nomodify notrap
restrict 103.135.132.0 mask 255.255.254.0 nomodify notrap