NTPを利用して時刻や日付を設定する「ntpdate」コマンドの概要と使い方を記載しています。
RHEL Fedora CentOS Vine Deblan Ubuntu Plamo
使用頻度:
概要・使用方法
書式
$ ntpdate [オプション] NTPサーバ名
NTP(Network Time Protocol)を引用し、引数に渡すNTPサーバから時刻を取得し、マシンの時刻や日付を設定します。設定するホストでは、rootユーザで実行する必要があります。ntpdateは、2つの方法で時刻の調整を行います。
- 関数settimeofdayを利用:0.5秒以上の差はすぐに調整
- 関数adjtimeを利用:0.5秒以内の差は少しずつ調整
起動時にntpdateを実行し、ntpdを起動しておくのがよいでしょう。
オプション
| -B | adjtimeを使って強制的に時間を変更する |
| -b | settimeofdayを使って強制的に時間を変更する |
| -d | デバックモードで起動する。時間の調子は行わない |
| -q | NTPサーバへの問い合わせのみで時刻の設定を行わない |
| -s | syslogに出力する。cronなどで利用される |
| -t 秒数 | タイムアウト時間を指定する(デフォルトは1秒) |
| -u | NTPサーバへ接続するのに特権ポート(: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)

