Advertisement
efxtv

Fix Time in Alpine Linux

Mar 3rd, 2025 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | Cryptocurrency | 0 0
  1. # Fix time in alpine linux
  2.  
  3. ##################################################################
  4. Join our telegram channel for more : https://t.me/LinuxClassesEFXTv
  5. ##################################################################
  6.  
  7. apk add chrony
  8.  
  9. rc-service chronyd start
  10.  
  11. rc-update add chronyd
  12.  
  13. chronyc tracking
  14.  
  15. date
  16.  
  17. or
  18.  
  19.  
  20. Step 1: Install NTP client
  21. apk update
  22. apk add busybox-extras
  23.  
  24. Step 2: Sync Time via NTP
  25. ntpd -d -q -n -p pool.ntp.org
  26.  
  27. Optional: Set Time at Boot
  28. Since time resets every time you start the QEMU VM, you can add this sync command in your Alpine's startup script (/etc/local.d/ntp.start) if you want automatic time sync:
  29.  
  30. #!/bin/sh
  31. ntpd -q -n -p pool.ntp.org
  32.  
  33. If Manual Time Set is Needed (Fallback)
  34.  
  35. If NTP fails for some reason (e.g., network issues), manually set it:
  36.  
  37. date -s "2025-04-09 15:45:00"
  38. docker restart containerid # to get container (docker ps)
  39.  
  40.  
  41. # If you already followed above use command to sync
  42. ntpd -d -q -n -p pool.ntp.org
  43.  
  44. or
  45. # Update repository
  46. nano /etc/apk/repositories
  47. or
  48. sed -i 's/https/http/' /etc/apk/repositories
  49. change https with http
  50.  
  51. apk update;
  52. apk upgrade
  53.  
  54. apk add ntp
  55. ntpd -qg
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement