-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathntp.sh
More file actions
48 lines (40 loc) · 1.05 KB
/
ntp.sh
File metadata and controls
48 lines (40 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
set -euo pipefail
# ---------- helpers ----------
log() { echo -e "\n==> $*"; }
if [[ "${EUID}" -ne 0 ]]; then
echo "Please run as root: sudo $0"
exit 1
fi
# ---------- install and configure systemd-timesyncd ----------
log "Configuring NTP time synchronization..."
# Enable NTP
timedatectl set-ntp true
# Configure timesyncd with multiple NTP servers
log "Configuring NTP servers..."
mkdir -p /etc/systemd/timesyncd.conf.d/
cat > /etc/systemd/timesyncd.conf.d/custom.conf <<'EOF'
[Time]
NTP=time.cloudflare.com time.google.com
FallbackNTP=pool.ntp.org ntp.ubuntu.com
EOF
# Restart timesyncd
log "Restarting timesyncd..."
systemctl restart systemd-timesyncd
# Wait for sync
sleep 2
log "Done."
echo ""
echo "=========================================="
echo " NTP Configuration Complete!"
echo "=========================================="
echo ""
timedatectl
echo ""
echo "NTP Servers:"
echo " - time.cloudflare.com"
echo " - time.google.com"
echo " - pool.ntp.org (fallback)"
echo ""
echo "Check sync status: timedatectl timesync-status"
echo ""