RHEL9 netstatとssコマンドでネットワークの状態確認

環境
RHEL9.2

操作例
1.curl ifconfig.ioグローバルIPの確認
下記コマンドを実行すると、ifconfig.io にアクセスして自サーバが利用するグローバルIPを確認できます。
# curl ifconfig.io
123.122.212.51

2.netstat接続状態や統計情報を確認
# netstat -anp

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1218/cupsd
tcp 0 0 127.0.0.1:4330 0.0.0.0:* LISTEN 2374/pmlogger
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1221/sshd: /usr/sbi
tcp 0 0 127.0.0.1:44321 0.0.0.0:* LISTEN 1792/pmcd
tcp 0 196 192.168.213.131:22 192.168.213.1:50482 ESTABLISHED 5957/sshd: arte [pr
Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1218/cupsd tcp 0 0 127.0.0.1:4330 0.0.0.0:* LISTEN 2374/pmlogger tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1221/sshd: /usr/sbi tcp 0 0 127.0.0.1:44321 0.0.0.0:* LISTEN 1792/pmcd tcp 0 196 192.168.213.131:22 192.168.213.1:50482 ESTABLISHED 5957/sshd: arte [pr
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1218/cupsd
tcp        0      0 127.0.0.1:4330          0.0.0.0:*               LISTEN      2374/pmlogger
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1221/sshd: /usr/sbi
tcp        0      0 127.0.0.1:44321         0.0.0.0:*               LISTEN      1792/pmcd
tcp        0    196 192.168.213.131:22      192.168.213.1:50482     ESTABLISHED 5957/sshd: arte [pr

オプションについて
-a すべての接続を表示(状態が待ち受け状態(LISTEN)のも表示)
-p 各ソケットが属している「PID/Program name」を表示
-n ホスト・ポート・ユーザーなどの名前を解決せずに、数字のアドレスで表示

-rオプション で、ルーティングテーブルを確認できます。ルーティングテーブルについては、 routeコマンド のほうで記述します。
# netstat -r

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default _gateway 0.0.0.0 UG 0 0 0 ens160
192.168.213.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160
Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default _gateway 0.0.0.0 UG 0 0 0 ens160 192.168.213.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         _gateway        0.0.0.0         UG        0 0          0 ens160
192.168.213.0   0.0.0.0         255.255.255.0   U         0 0          0 ens160

3.ss 接続状態や統計情報を確認
netstat と同様の情報を ss で確認できます。
( ssコマンドは iproute2 というパッケージに含まれています。)
# ss

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
u_dgr ESTAB 0 0 /run/systemd/notify 14220 * 0
u_dgr ESTAB 0 0 /run/systemd/journal/dev-log 14233 * 0
u_dgr ESTAB 0 0 /run/systemd/journal/socket 14235 * 0
u_dgr ESTAB 0 0 /run/chrony/chronyd.sock 25787 * 0
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process u_dgr ESTAB 0 0 /run/systemd/notify 14220 * 0 u_dgr ESTAB 0 0 /run/systemd/journal/dev-log 14233 * 0 u_dgr ESTAB 0 0 /run/systemd/journal/socket 14235 * 0 u_dgr ESTAB 0 0 /run/chrony/chronyd.sock 25787 * 0
Netid       State        Recv-Q       Send-Q                                     Local Address:Port                      Peer Address:Port         Process
u_dgr       ESTAB        0            0                                    /run/systemd/notify 14220                                * 0
u_dgr       ESTAB        0            0                           /run/systemd/journal/dev-log 14233                                * 0
u_dgr       ESTAB        0            0                            /run/systemd/journal/socket 14235                                * 0
u_dgr       ESTAB        0            0                               /run/chrony/chronyd.sock 25787                                * 0

# ss -s

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Total: 743
TCP: 9 (estab 1, closed 0, orphaned 0, timewait 0)
Transport Total IP IPv6
RAW 1 0 1
UDP 7 4 3
TCP 9 5 4
INET 17 9 8
FRAG 0 0 0
Total: 743 TCP: 9 (estab 1, closed 0, orphaned 0, timewait 0) Transport Total IP IPv6 RAW 1 0 1 UDP 7 4 3 TCP 9 5 4 INET 17 9 8 FRAG 0 0 0
Total: 743
TCP:   9 (estab 1, closed 0, orphaned 0, timewait 0)

Transport Total     IP        IPv6
RAW       1         0         1
UDP       7         4         3
TCP       9         5         4
INET      17        9         8
FRAG      0         0         0

 

IT

Posted by arkgame