Telenetでリモートホストに接続する「telnet」コマンドの概要と使い方を記載しています。
RHEL Fedora CentOS Vine Deblan Ubuntu Plamo
参考サイト:Man page of INSTALL
概要・使用方法
書式
$ telnet [オプション] [ホスト名] [サービス]
Telnetプロトコルを使ってtelnetdが稼働しているリモートホストに接続します。telnetを利用してリモートホストと通信すると、ユーザ名やパスワード、通信内容が暗号化されていない「平文」で流れてしまい、途中経路で盗聴される可能性があります。リモートアクセスはtelnetの代替ツールであるsshを利用します。telnetはリモートログインの用途よりも、リモートホストとポート番号(http(80)やsmtp(25)など)を指定してサーバのデバックなどでよく利用されます。また、pingコマンドはICMPプロトコルをセキュリティ上拒否しているケースがあるので、pingコマンドの代わりにサーバーの稼働状況やサービスの稼働状況を確認にもよく利用されます。
telnetコマンドは標準でインストールされていないことがあるので、「yum install telnet」でインストールする必要があります。
オプション
| -e 文字 | エスケープ文字を指定した文字にする |
| -E | エスケープ文字機能を無視する |
| -l ユーザ名 | ログインユーザを指定する |
Telnetプロトコルでリモートホストに接続する
$ telnet ホスト名
実行結果
[root@centos ~]# telnet kcfran.com
Trying 153.122.22.98...Code language: CSS (css)
TelnetでHTTPサーバにアクセスする
$ telnet ホスト名 ポート番号
実行結果
[root@centos ~]# telnet kcfran.com 443
Trying 153.122.22.98...
Connected to kcfran.com.
Escape character is '^]'.
GET / HTTP/1.0
HTTP/1.1 400 Bad Request
Date: Thu, 22 Dec 2022 00:05:09 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>
Connection closed by foreign host.
[root@centos ~]# Code language: HTML, XML (xml)
Telnetでメールを送信
実行結果
$ telnet mail.example.com 25 #<mail.example.comの25 220="" 250="" 354="" tcpに接続する="" trying="" 210.251.111.111="" connected="" to="" mail.example.com="" escape="" character="" is="" esmtp="" postfix="" (debian="" gnu)="" #メールサーバからの応答が来る="" helo="" mail="" from:="" sunarin@example.jp="" #メール差出人のfromを記述する="" ok="" rcpt="" to:="" sunarin@example.com="" #メールの宛先のtoを指定する="" data="" #「data」の後に本文を入力する="" end="" with="" <cr=""><lf>.<cr><lf>
hello!!
. #本文終了は「.」で知らせる
250 ok: queued as 0E8F975C017
quit #<終了
221 Bye
Connection closed by foreign host.</lf></cr></lf></mail.example.comの25>Code language: PHP (php)
