LoginSignup
4
3

More than 5 years have passed since last update.

rdateコマンドに応答するtime serviceをUbuntuで有効にする方法

Last updated at Posted at 2018-10-18

シングルボードコンピュータをインターネットにつながらない環境で使っているとき、ntpdateで時刻合わせをする先がないので、時刻が1970年1月1日になってしまいます。これはあんまりなので、手元のUbuntu 18.04 でtime serviceを動かして、rdateコマンドで時刻合わせをできるようにしました。
ただしこの方法だと精度は1秒です。

time serviceを有効にする

sudo apt install xinetd
cd /etc/xinetd.d/
sudo cp time time.org
sudo vi time

以下のようにtcpのところのdisableをnoに変更します。

$ diff -u time.org time
--- time.org    2018-10-18 13:04:20.401692370 +0900
+++ time    2018-10-18 13:04:50.721767045 +0900
@@ -6,7 +6,7 @@
 # This is the tcp version.
 service time
 {
-   disable     = yes
+   disable     = no
    type        = INTERNAL
    id      = time-stream
    socket_type = stream

xinetdを再起動。

sudo /etc/init.d/xinetd restart

telnetでport 37をつついてみる

$ telnet localhost 37
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
�r�Connection closed by foreign host.

このように何か32bitのバイナリデータが読めたらOK。

組み込みLinux側でrdateの実行

time service を動かしているサーバのIPアドレスが 192.168.20.1 として

~ # date
Sat Jan  3 01:31:44 UTC 1970
~ # rdate -s 192.168.20.1
~ # date
Thu Oct 18 04:23:10 UTC 2018
~ # 

現在時刻を設定できました。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3