RHEL 8でTelnetをお探しですか? ncを試す
公開: 2022-05-02Telnetは、コンピュータにリモートアクセスするために使用されるネットワークプロトコルであり、双方向のテキストベースの通信を提供します。 したがって、相互に通信するには、Telnetサーバーとクライアントが必要です。
Telnetは、長い間その目的を果たしてきた人気のあるLinux/Windowsユーティリティの1つです。
最新のシステムでのtelnetの主な問題は、安全ではないことです。 telnetでのすべての通信はプレーンテキストで行われ、すべてのネットワークトラフィックは暗号化されていません。 基本的に、適切なアクセスとツールを持っている人なら誰でも、ネットワークトラフィックをスヌープしてこのトラフィックを読み取ることができます。 そのため、最近のほとんどのLinuxオペレーティングシステムにはtelnetがプリインストールされておらず、他の人はそれを使用しないことを推奨しています。
telnetの暗号化された代替物以上のSSHまたはSecureShellプロトコルの出現により、意図された目的でのtelnetの使用は長い間時代遅れになっています。 しかし、多くのシステム管理者や技術愛好家が今でも使用しているtelnetの代替使用法があります。それは、リモートTCPポートの接続をチェックすることです。
telnetコマンドを使用して、リモートTCPポートがリッスンして適切に応答しているかどうかを簡単に確認できます。 以下のスニペットは、 HTTP/HTTPS
接続をチェックすることにより、 google.com
が稼働しているかどうかをチェックする方法を示しています。
$ telnet google.com 80 Trying 142.250.183.206... Connected to google.com. Escape character is '^]'. ^] telnet> quit Connection closed. $ $ telnet google.com 443 Trying 142.250.183.206... Connected to google.com. Escape character is '^]'. ^] telnet> quit Connection closed. $
開いていない、またはアクセスできないTCPポートは、 telnet
で確認すると次のように動作します。
$ telnet google.com 22 Trying 142.250.193.174... ^C $
これにより、 ping
、 traceroute
またはtracepath
、 netstat
などのコマンドと組み合わせて、単純なネットワーク接続の問題のトラブルシューティングを簡単に行うことができます。
RHEL 8(またはRHEL / CentOSの古いバージョン)を使用している場合は、多くのネットワーク診断関連オプションをサポートするnc(またはNcatまたはNetwork Connector)を使用するオプションがあります。 このツールをRHEL8および同様のシステムにインストールして使用する方法について説明します。
ncとは何ですか?
nc(またはNcat)は、ネットワーク全体でデータの読み取り、書き込み、リダイレクト、および暗号化を行うための一般的な汎用コマンドラインツールです。 元々はnmap
プロジェクト用に作成されていましたが、現在は複数のNetcat実装が利用可能です。 IPv4とIPv6の両方でTCPとUDPの両方で機能し、無限の潜在的なユースケースを提供します。
以下は、 nc
ユーティリティの主な機能の一部です。
-
ncats
をチェーンする機能 - TCP、UDP、およびSCTPポートのその他のサイトへのリダイレクト
- SSLサポートで通信を暗号化する
- SOCK4 / 5またはHTTPプロキシを介したプロキシサポート(認証を含む)
- Windows、Linux、macOSなどの複数のプラットフォームをサポートします
ncのインストール
nc
は、RHELシステムのデフォルトリポジトリの一部として利用できます。 RHEL 7システムにインストールするには、ターミナルで以下のコマンドを発行するだけです。
$ sudo yum install -y nc
RHEL 8システムの場合、 dnf
を次のように使用できます。
$ sudo dnf install -y nc
TCP接続を確認する
nc
は、アプリケーション全体で多くのユースケースをサポートする多くの機能を提供しますが、一般的なものの1つは、 telnet
の代わりにネットワークのトラブルシューティングを行う場合です。
nc
は、TCPポートに到達できるかどうかを表示できます。 構文は次のとおりです。
$ nc -vz <IP/DNS> <Port>
例として、 http
またはhttps
経由でGeekflareに到達できるかどうかを確認したい場合。 以下に示すように、 nc
を使用して確認できます(ポート80
はhttp
用で、 443
はhttps
用です)。
$ nc -vz geekflare.com 80 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 104.26.11.88:80. Ncat: 0 bytes sent, 0 bytes received in 0.02 seconds. $ $ nc -vz geekflare.com 443 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 104.26.10.88:443. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds. $
同様に、到達不能またはブロックされたポートは、次のような出力を表示します(Geekflare DNSが複数のIPを指しているため、複数のアドレスがチェックされます)。
$ nc -vz geekflare.com 22 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connection to 172.67.70.213 failed: Connection timed out. Ncat: Trying next address... Ncat: Connection to 104.26.11.88 failed: Connection timed out. Ncat: Trying next address... Ncat: Connection to 104.26.10.88 failed: Connection timed out. Ncat: Trying next address... Ncat: Connection to 2606:4700:20::681a:a58 failed: Network is unreachable. Ncat: Trying next address... Ncat: Connection to 2606:4700:20::681a:b58 failed: Network is unreachable. Ncat: Trying next address... Ncat: Network is unreachable. $ $ dig geekflare.com +short 104.26.10.88 172.67.70.213 104.26.11.88 $
UDP接続を確認してください
telnet
はリモートTCPポートとの通信のみをチェックできますが、 nc
ではTCPとUDP接続をチェックできます。
nc
は、以下を使用して、デフォルトのTCPパケットの代わりにUDPパケットを送信できます。
$ nc -vzu <IP/DNS> <Port>
ただし、UDPはTCPとは異なり、セッションレスプロトコルであるため、リモートエンドのリスニングプロセスが送信しない限り、一方の端でUDPパケットを送信するだけでは、考えられるすべてのシナリオでエンドツーエンドのUDP接続を確認できません。一部の応答では、 nc
は送信されたパケットが宛先に到達したかどうかを判断できません。 ただし、 nc
は、リモートサーバー上のCLIに適切にアクセスできることを前提として、UDPリスナーを起動することによってエンドツーエンドのUDP接続を決定するための代替手段を提供します。

したがって、 nc
を使用してDNSの2つのLinuxホスト間のUDP接続を確認する必要があると仮定すると、これを行う簡単な方法は、必要なポートでリッスンしているnc
サーバーを起動することです。
$ sudo nc -ul <Port>
DNSの場合、ポート53
をチェックする必要があります。これにより、上記のコマンドは次のようになります。
$ nc -ul 53
クライアント側では、UDPパケットをサーバーに送信する別のnc
プロセスを起動する必要があります。
$ nc -u <IP/DNS> <Port>
それは私たちの命令になります:
$ nc -u <IP/DNS> 53
これら2台のマシン間のポート53
のUDPトラフィックをブロックするものが何もないことを考慮すると、1台のマシンで入力して入力したものはすべて、双方向チャットのように他のホストで表示されるはずです。 そうでない場合、一部のファイアウォールがこれら2つのシステム間の接続をブロックしています。
nc
を使用するサーバーおよびクライアントモデルは、ホスト間のこの種の単純な接続チェックに対して問題なく機能します。 上記のUDPチェックと同様に、 nc
は特定のポートでTCPパケットをリッスンすることもできます。
$ sudo nc -l <Port>
クライアント側では、通常、TCPパケットを送信して接続を確認できます。
$ nc <IP/DNS> <Port>
上記のサーバー/クライアントnc
メソッドは、コネクション型プロトコルであり、確認応答で機能するため、TCP接続(UDPとは異なり)の場合は必要ありません。 TCPで動作するリスニングプロセスは、 nc
パケットに直接応答します。
概要
この記事では、ポートの接続性をチェックする限り、 nc
ユーティリティが最新のLinuxシステムでtelnet
の直接の代替としてどのように機能するかを要約し、ネットワークの問題の診断と解決においてエンドユーザーにより多くのパワーを提供します。
nc
ヘルプには、 nc -h
コマンドを使用してアクセスできます。
$ nc -h Ncat 7.70 ( https://nmap.org/ncat ) Usage: ncat [options] [hostname] [port] Options taking a time assume seconds. Append 'ms' for milliseconds, 's' for seconds, 'm' for minutes, or 'h' for hours (eg 500ms). -4 Use IPv4 only -6 Use IPv6 only -U, --unixsock Use Unix domain sockets only -C, --crlf Use CRLF for EOL sequence -c, --sh-exec <command> Executes the given command via /bin/sh -e, --exec <command> Executes the given command --lua-exec <filename> Executes the given Lua script -g hop1[,hop2,...] Loose source routing hop points (8 max) -G <n> Loose source routing hop pointer (4, 8, 12, ...) -m, --max-conns <n> Maximum <n> simultaneous connections -h, --help Display this help screen -d, --delay <time> Wait between read/writes -o, --output <filename> Dump session data to a file -x, --hex-dump <filename> Dump session data as hex to a file -i, --idle-timeout <time> Idle read/write timeout -p, --source-port port Specify source port to use -s, --source addr Specify source address to use (doesn't affect -l) -l, --listen Bind and listen for incoming connections -k, --keep-open Accept multiple connections in listen mode -n, --nodns Do not resolve hostnames via DNS -t, --telnet Answer Telnet negotiations -u, --udp Use UDP instead of default TCP --sctp Use SCTP instead of default TCP -v, --verbose Set verbosity level (can be used several times) -w, --wait <time> Connect timeout -z Zero-I/O mode, report connection status only --append-output Append rather than clobber specified output files --send-only Only send data, ignoring received; quit on EOF --recv-only Only receive data, never send anything --allow Allow only given hosts to connect to Ncat --allowfile A file of hosts allowed to connect to Ncat --deny Deny given hosts from connecting to Ncat --denyfile A file of hosts denied from connecting to Ncat --broker Enable Ncat's connection brokering mode --chat Start a simple Ncat chat server --proxy <addr[:port]> Specify address of host to proxy through --proxy-type <type> Specify proxy type ("http" or "socks4" or "socks5") --proxy-auth <auth> Authenticate with HTTP or SOCKS proxy server --ssl Connect or listen with SSL --ssl-cert Specify SSL certificate file (PEM) for listening --ssl-key Specify SSL private key (PEM) for listening --ssl-verify Verify trust and domain name of certificates --ssl-trustfile PEM file containing trusted SSL certificates --ssl-ciphers Cipherlist containing SSL ciphers to use --ssl-alpn ALPN protocol list to use. --version Display Ncat's version information and exit See the ncat(1) manpage for full options, descriptions and usage examples $
nc
コマンドの詳細については、マニュアルページを参照してください。
$ man nc