Linux便利コマンド : telnet

うめだ
2025-09-22
2025-09-22
目次

はじめに

みなさま、telnetコマンドを活用されていますでしょうか?

私がエンジニアをはじめたころは、telnetでリモートホストにログインして、作業をしていました。

ご存じのように、telnetプロトコルは認証情報等平文でやりとりされるため、セキュリティの観点から、いまではsshでのリモートホストへのログインがあたりまえになっています。

そんなtelnetコマンドも特定のリモートホストに対して、指定したポートへ接続できるかを確認したいといった時にまだまだ現役で利用しています。

環境

OS : AlmaLinux 8
telnetバージョン : 0.17

使い方

まずは、Webサービスの80番ポートへ接続できるか確認してみましょう。
弊社コーポレートサイトのWebサーバーに、http(80)で接続してみます。

$ telnet www.future-s.com 80
Trying 219.99.160.36...
Connected to www.future-s.com.
Escape character is '^]'.

この表示になれば、80ポートがLISTENされていて、正常に接続できているということになります。

もし、LISTENしていない、またはFWでアクセス制限がかかっている場合は、Connection refused や Connection timeoutになります。

つづいて、GETリクエスト「GET / HTTP/1.0」を入力すると、ちゃんと「200 OK」を返してくれます。

$ telnet www.future-s.com 80
Trying 219.99.160.36...
Connected to www.future-s.com.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Date: Sun, 21 Sep 2025 08:39:48 GMT
Server: Apache
Last-Modified: Wed, 18 Jun 2025 02:37:43 GMT
Accept-Ranges: bytes
Content-Length: 0
X-Powered-By: PleskLin
Connection: close
Content-Type: text/html

Connection closed by foreign host.
$

つぎに、SMTPサービスの25番ポートへ接続できるか確認してみましょう。

便宜的にlocalhostを指定させてもらいます。

$ telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 localhost.fsi.ne.jp ESMTP Postfix

便宜的にlocalhostを指定させてもらいます。

$ telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 localhost.fsi.ne.jp ESMTP Postfix

この表示になれば、25番ポートへ問題なく接続できている状態になります。

つづいて、下記のSMTPコマンドを順番に入力していくことで、メールの送信も可能です。


HELO future-s.com

MAIL FROM: <hogehome@future-s.com>

RCPT TO: <fugafuga@future-s.com>

DATA
From: <hogehome@future-s.com>
To:  <r.umeda@future-s.com>
Subject: FutureSprits TestMail
testmail
.

quit

実際には以下のような表示になります。

$ telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 localhost.fsi.ne.jp ESMTP Postfix

HELO future-s.com
250 localhost.fsi.ne.jp
MAIL FROM: <hogehome@future-s.com>
250 2.1.0 Ok
RCPT TO: <fugafuga@future-s.com>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
From: <hogehome@future-s.com>
To:  <fugafuga@future-s.com>
Subject: FutureSprits TestMail
testmail
.
250 2.0.0 Ok: queued as 45954C0BC72C
quit
221 2.0.0 Bye
Connection closed by foreign host.
$

正常にメールも送信することができました。

まとめ

いかがでしたか?

telnetコマンドで、リモートホストへのポート指定での接続確認と、簡易的な動作確認をすることができます。

是非とも活用してみてください。