ウェブサイト検索

Linux で開いているすべてのポートのリストを確認する方法


この記事では、コンピューター ネットワークのポートについて簡単に説明し、Linux で開いているすべてのポートを一覧表示する方法に移ります。

コンピュータ ネットワーキング、そしてより明確にソフトウェアの用語では、ポートは、Linux オペレーティング システム上の特定のアプリケーションまたはプロセスを識別するための通信のエンドポイントとして機能する論理エンティティです。これは、エンド システム上でアプリケーションを区別する 16 ビットの数値 (065535) です。

最も一般的な 2 つのインターネット トランスポート プロトコル、伝送制御プロトコル (TCP) とユーザー データグラム プロトコル (UDP)およびその他のあまり知られていないプロトコルは、通信セッションにポート番号を使用します (送信元および宛先の IP アドレスと組み合わせた送信元および宛先のポート番号)。

さらに、IP アドレス、ポート、TCP/UDP などのプロトコルの組み合わせはソケットと呼ばれ、すべてのサービスには一意のソケットが必要です。

以下にポートのさまざまなカテゴリを示します。

  1. 0-1023 – ウェルノウン ポート。システム ポートとも呼ばれます。
  2. 1024-49151 – 登録済みポート。ユーザー ポートとも呼ばれます。
  3. 49152-65535 – 動的ポート。プライベート ポートとも呼ばれます。

Linux では cat コマンドを使用して、さまざまなアプリケーションとポート/プロトコルの組み合わせのリストを /etc/services ファイルで表示できます。

cat /etc/services 
OR
cat /etc/services | less
/etc/services:
$Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $
#
Network services, Internet style
IANA services version: last updated 2009-11-10
#
Note that it is presently the policy of IANA to assign a single well-known
port number for both TCP and UDP; hence, most entries here have two entries
even if the protocol doesn't support UDP operations.
Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
are included, only the more common ones.
#
The latest IANA port assignments can be gotten from
      http://www.iana.org/assignments/port-numbers
The Well Known Ports are those from 0 through 1023.
The Registered Ports are those from 1024 through 49151
The Dynamic and/or Private Ports are those from 49152 through 65535
#
Each line describes one service, and is of the form:
#
service-name  port/protocol  [aliases ...]   [# comment]

tcpmux          1/tcp                           # TCP port service multiplexer
tcpmux          1/udp                           # TCP port service multiplexer
rje             5/tcp                           # Remote Job Entry
rje             5/udp                           # Remote Job Entry
echo            7/tcp
echo            7/udp
discard         9/tcp           sink null
discard         9/udp           sink null
systat          11/tcp          users
systat          11/udp          users
daytime         13/tcp
daytime         13/udp
qotd            17/tcp          quote
qotd            17/udp          quote
msp             18/tcp                          # message send protocol
msp             18/udp                          # message send protocol
chargen         19/tcp          ttytst source
chargen         19/udp          ttytst source
ftp-data        20/tcp
ftp-data        20/udp
21 is registered to ftp, but also used by fsp
ftp             21/tcp
ftp             21/udp          fsp fspd
ssh             22/tcp                          # The Secure Shell (SSH) Protocol
ssh             22/udp                          # The Secure Shell (SSH) Protocol
telnet          23/tcp
telnet          23/udp

Linux でTCPUDPを含むすべての開いているポートまたは現在実行中のポートを一覧表示するには、ネットワーク接続と統計を監視するための強力なツールである netstat を使用します。

$ netstat -lntu

Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 :::80                       :::*                        LISTEN      
tcp        0      0 :::25                       :::*                        LISTEN      
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               

どこ、

  1. -l – リッスンしているソケットのみを出力します。
  2. -n – ポート番号を表示します
  3. -t – TCP ポートのリストを有効にします
  4. -u – UDP ポートのリストを有効にします。

Linux システムのソケットを調べるためのよく知られた便利なユーティリティである ss コマンドを使用することもできます。以下のコマンドを実行して、開いているすべての TCP ポートと UCP ポートを一覧表示します。

$ ss -lntu

Netid State      Recv-Q Send-Q               Local Address:Port       Peer Address:Port 
udp   UNCONN     0      0                    *:68                     *:*     
tcp   LISTEN     0      128                  :::22                    :::*     
tcp   LISTEN     0      128                  *:22                     *:*     
tcp   LISTEN     0      50                   *:3306                   *:*     
tcp   LISTEN     0      128                  :::80                    ::*     
tcp   LISTEN     0      100                  :::25                    :::*     
tcp   LISTEN     0      100                  *:25  

詳しい使用方法については、上記のコマンドのマニュアル ページを必ず読んでください。

要約すると、システム管理者およびネットワーク管理者にとって、コンピュータ ネットワークにおけるポートの概念を理解することは非常に重要です。シンプルで正確、よく説明された例を含むこの netstat ガイドを参照することもできます。

最後になりましたが、Linux で開いているポートをリストする他の方法を共有するか、以下の応答フォームから質問して、私たちにご連絡ください。