LoginSignup
3
3

More than 5 years have passed since last update.

ファイアウォール下での時計あわせ

Last updated at Posted at 2017-06-22

企業などのネットワークでは、セキュリティの事情でUDP123が閉じられているために, ntpdateが使えないことがある. httpsが接続できるなら(これができないということはほとんどないはず...), nict.go.jpのデータを利用する方法がある.

w3mを使ったやり方
date -s "`w3m -dump https://ntp-a1.nict.go.jp/cgi-bin/time`"
hwclock -w

上の w3m -dump ...というのは, nict.go.jp の時刻データを https で拾ってきて, 標準出力で出力させるコマンドであり、この標準出力をdateコマンドに渡している。最後のhwclock -wはハードウェア時計をソフトウェア時計に合わせる設定である.

ちなみに, リンク先についてはnictの技術情報から選んだものである. 自分で都合のよいものを選べば良い.

追記

w3m 以外に curl や wget を使ってもできる(指摘いただいた @kazinoue 様, ありがとうございます)

curlを使ったやり方
date -s "`curl -s https://ntp-a1.nict.go.jp/cgi-bin/time`"
hwclock -w

curl のコマンド中の -s はなくてもいけるかもしれません. 要は標準出力に日付データが出せればよいだけ.

wgetを使ったやり方
date -s "`wget https://ntp-a1.nict.go.jp/cgi-bin/time -q -O -`"
hwclock -w

ダウンロード情報等も出さないように -q を加える. "-O -" は標準出力に表示するコマンドである(-O /dev/stdout でもよい).

3
3
2

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
3
3