How To Fix the Linux Time change After Reboot

In this article, we want to teach you How To Fix the Linux Time change After Reboot.

Many users on the Internet use Linux virtual servers and they often get into trouble with the time and date changing because of the time differences between servers and areas used by virtual servers.

First, you need to know that the problem of the server time change is because of the hardware clock of the system and the geographical area, and this problem can happen for any server.

On the other hand, the users that set up important services on Linux like web server, after the time change, their server is getting down.

To fix this problem, you can use the Cron tool.

So you need to have the Cron tool installed on your server. To do this, you can follow our article about Cron in Linux.

Now follow the steps below to fix the Linux Time change.

Fix the Linux Time change After Reboot

First, you need to install the ntpdate tool on your Linux server.

On Debian / Ubuntu, you can use the following command:

apt-get install -y ntpdate

On Centos / RHEL, you can run the following command:

yum install -y ntpdate

Then, enter the command once as shown below to ensure the correct date and performance of this tool:

ntpdate time.windows.com

Note: The time.windows.com is the name of an NTP server, you can choose another NTP server.

Next, run the following command to get into your Crontab settings to fix the Linux time change:

crontab -e

Note: If the VI or Nano editor does not open after entering this command, you will be shown the option to open the desired editor, which will be opened by entering the desired number of the editor.

Add the following command into your file:

@reboot ntpdate time.windows.com

When you are done, save and close the file.

After entering the above command, you ask Cron to update the time and date once after each reboot.

Now you can change the date of your Linux server and reboot the server once to test the correctness of the crown function.

Some important tips for cron performance after reboot:

  • You should enter the commands as the root user.
  • Make sure the Cron service is enabled on your startup server.
  • Enter commands accurately without deleting or adding spaces.

Conclusion

At this point, you learn to Fix the Linux Time change After Reboot.

Hope you enjoy it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!