- Documentation
Elastic Compute Service
Elastic Compute Service
Best Practices
ECS instance local time synchronization
Configuring NTP service for Linux instances (Ubuntu 18)
ECS instance local time synchronization
Configuring NTP service for Linux instances (Ubuntu 18)
Configuring NTP service for Linux instances (Ubuntu 18)
This topic describes how to modify the time zone of a Linux instance, as well as how to enable and configure the Linux NTP service to ensure accurate local time synchronization of the instance. In the example provided in this topic, Ubuntu 18.04 is used.
What is NTP?
Network Time Protocol (NTP) is an application-layer protocol in the TCP/IP protocol suite, designed for clock synchronization between clients and servers and providing highly accurate time calibration.
Prerequisites
- If NTP is not installed, execute the following command to install it.
sudo apt-get install ntp
- The NTP service uses the User Datagram Protocol (UDP) to send and receive timestamps over port 123. Make sure that an inbound rule is added to the security group of the instance to allow inbound traffic on UDP port 123. For more information, see Creating security groups.
Procedure
Modify the time zone of a Linux instance
You need to modify the time zone as the root account. Therefore, use the sudo command.
- Execute the timedatectl list-timezones command to view the list of available time zones.
You can also quickly view the list of available time zones in a continent. For example, you can execute the timedatectl list-timezones | egrep -o "Asia/*.*" command to quickly find available time zones in Asia.
- Execute the following command to modify the time zone. In the example provided in this topic, the time zone is changed to Shanghai.
timedatectl set-timezone "Asia/Shanghai"
- Execute the following command to view the current time zone and check whether the modification is successful.
timedatectl status | grep Time
-
Start the standard NTP service
- Execute the sudo systemctl restart ntp command to start the NTP service.
- Execute the systemctl enable ntp command to specify that the NTP service automatically starts upon instance startup.
- Execute the sudo systemctl status ntp command to view the running status of the NTP service.
-
- Execute the ntpq -p command to view the list of NTP service peers (optional).
Configure custom NTP service
- Execute the sudo vim /etc/ntp.conf command to open and edit the NTP service configuration file.
- Enter i to start editing the file, and add # to the beginning of the NTP server lines that you currently do not need to comment them out.
- Add the NTP server information in the following format: server <NTP_server_address> iburst. After you complete the editing, press the Esc key to exit the edit mode, enter :wq, and then press Enter to save the changes and exit the file.
- Execute the sudo systemctl restart ntp command to start the custom NTP service.
- Execute the sudo systemctl status ntp command to view the running status of the NTP service.
- (Optional) Execute the ntpq -p command to view the list of NTP service peers.
Last updated: 2026.06.17 19:32:52