Linuxコマンド辞典 ntpdateコマンド(ネットワーク)

この記事は約3分で読めます。

NTPを利用して時刻や日付を設定する「ntpdate」コマンドの概要と使い方を記載しています。

RHEL Fedora CentOS Vine Deblan Ubuntu Plamo

使用頻度:2.0

概要・使用方法

書式

$ ntpdate [オプション] NTPサーバ名

NTP(Network Time Protocol)を引用し、引数に渡すNTPサーバから時刻を取得し、マシンの時刻や日付を設定します。設定するホストでは、rootユーザで実行する必要があります。ntpdateは、2つの方法で時刻の調整を行います。

  • 関数settimeofdayを利用:0.5秒以上の差はすぐに調整
  • 関数adjtimeを利用:0.5秒以内の差は少しずつ調整

起動時にntpdateを実行し、ntpdを起動しておくのがよいでしょう。

オプション

-Badjtimeを使って強制的に時間を変更する
-bsettimeofdayを使って強制的に時間を変更する
-dデバックモードで起動する。時間の調子は行わない
-qNTPサーバへの問い合わせのみで時刻の設定を行わない
-ssyslogに出力する。cronなどで利用される
-t 秒数タイムアウト時間を指定する(デフォルトは1秒)
-uNTPサーバへ接続するのに特権ポート(:1024)を利用しない

NTPサーバを指定して時刻を設定する

$ nc IPアドレス or URL

実行結果

[rin@centos ~]$ nc kcfran.com 443
GET / HTTP/1.1
HTTP/1.1 400 Bad Request
Date: Wed, 25 Jan 2023 02:19:55 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.14
Content-Length: 362
Connection: close
Content-Type: text/html; charset=iso-8859-1



<title>400 Bad Request</title>

<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.

Reason: You're speaking plain HTTP to an SSL-enabled server port.

 Instead use the HTTPS scheme to access this URL, please.

</p>
Code language: HTML, XML (xml)

ポートスキャンして結果を出力する

$ 

実行結果

[rin@centos ~]$ nc kcfran.com 443
GET / HTTP/1.1
HTTP/1.1 400 Bad Request
Date: Wed, 25 Jan 2023 02:19:55 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.14
Content-Length: 362
Connection: close
Content-Type: text/html; charset=iso-8859-1



<title>400 Bad Request</title>

<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.

Reason: You're speaking plain HTTP to an SSL-enabled server port.

 Instead use the HTTPS scheme to access this URL, please.

</p>
Code language: HTML, XML (xml)
タイトルとURLをコピーしました