Raspberry Set NTP Server Time

قبل از هرچیزی timezone خودتون رو با دستور sudo dpkg-reconfigure tzdata رو تهران بزارید .

بعدش با دستور فوق ntp رو enable میکنید :

timedatectl set-ntp true

برای خوندن تایم رسپبری های از رو ntp سرور دلخواه باید آی پی و یا اسم ntp سرور داخل فایل /etc/systemd/timesyncd.conf قرار بدیم به این شکل :

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
#NTP=
#FallbackNTP=172.16.0.2 172.16.0.3 172.16.0.4 172.16.100.254 0.debian.pool.ntp.org
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

میتونید توی قسمت =NTP هر آی پی و اسمی رو بزارید با فاصله هم میشه چندتا گذاشت، البته باید uncomment اش کنید همون # رو بردارید یعنی

حالا بعد این فایل رو سیو میکنیم و بعد. با دستورات sudo systemctl daemon-reload و sudo systemctl restart systemd-timesyncd سرویس رو ریستارت میکنیم و بعد با یه ریبوت دیگه حله.

برای راحتی کار و ادیت کردن اون فایل میتونید از دستور sed به شکل زیر استفاده کنید.

sudo sed -i 's/#NTP=/NTP=172.16.0.2 172.16.0.3/g' /etc/systemd/timesyncd.conf

دستور بالا میاد و اون بخش کامنت شده رو عوض میکنه و آی پی های بالا توش جایگزین میکنه .

در نهایت کار میشه این چند دستور :

sudo sed -i 's/#NTP=/NTP=172.16.0.2 172.16.0.3/g' /etc/systemd/timesyncd.conf

sudo timedatectl set-ntp true

sudo systemctl daemon-reload

sudo systemctl restart systemd-timesyncd

Last updated