複数のマシンやセグメントにpingをしたい!
以下のような場面で、fpingを使うと簡単に複数台に対してping発行し疎通、死活監視ができます。
fpingはデフォルトでインストールされていない場合が多いです。
以下のコマンドでインストールしてください。
Debian, Ubuntu系
sudo apt install fping
CentOS系
yum install fping dnf install fping
以下の例では、192.168.1.0/24に対してpingを発行します。
fping -a -g 192.168.1.0/24 2> /dev/null
実行結果 以下のよう疎通確認できたIPはIPのみ出力、疎通確認できなかったIPはICMP Host Unrea ...と表示されます。
$ fping -a -g 192.168.1.0/24 192.168.1.1 192.168.1.2 192.168.1.6 192.168.1.41 192.168.1.46 192.168.1.81 192.168.1.84 192.168.1.123 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.4 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.4 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.10
疎通できなかったIPを出力したくない場合は、以下のようにSTDERRを/dev/nullに出力すればよいでしょう。
$ fping -a -g 192.168.1.0/24 2>/dev/null 192.168.1.2 192.168.1.1 192.168.1.6 192.168.1.41 192.168.1.46 192.168.1.81 192.168.1.84 192.168.1.123
IPを複数指定して疎通確認したい場合は、fpingの後ろにIPアドレスを複数指定し実行します。
以下の例では、応答が返却されるIPを2つと応答が返却されないIPを一つ指定し実行したときの出力です。
$ fping 192.168.1.81 192.168.1.84 192.168.1.100 192.168.1.81 is alive 192.168.1.84 is alive ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.100 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.100 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.100 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.100 192.168.1.100 is unreachable
これもICMP Host unreachableが邪魔なので、STDERRの出力します。
$ fping 192.168.1.81 192.168.1.84 192.168.1.100 2>/dev/null 192.168.1.81 is alive 192.168.1.84 is alive 192.168.1.100 is unreachable
IPアドレスを範囲指定し疎通確認する場合は以下のようになります。
fping -s -g <スタートIPアドレス> <エンドIPアドレス>
実行すると、以下のように疎通確認結果が表示されます。
$ fping -s -g 192.168.1.1 192.168.1.10 192.168.1.1 is alive 192.168.1.2 is alive 192.168.1.6 is alive ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.4 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.4 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.4 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.4 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.10 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.10 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.10 ICMP Host Unreachable from 192.168.1.84 for ICMP Echo sent to 192.168.1.10 192.168.1.3 is unreachable 192.168.1.4 is unreachable 192.168.1.5 is unreachable 192.168.1.7 is unreachable 192.168.1.8 is unreachable 192.168.1.9 is unreachable 192.168.1.10 is unreachable 10 targets 3 alive 7 unreachable 0 unknown addresses 7 timeouts (waiting for response) 31 ICMP Echos sent 3 ICMP Echo Replies received 8 other ICMP received 3.34 ms (min round trip time) 4.92 ms (avg round trip time) 7.87 ms (max round trip time) 4.170 sec (elapsed real time)
以下のような疎通確認したいファイルを作成しました。
192.168.1.84 192.168.1.100
ファイルを指定して実行する場合は、以下の構文になります。
fping < ファイル名
または、上記で説明した複数のIPを後ろに書くと同等な以下のコマンド構文でもよいでしょう。
cat ファイル名 | fping
以上、高機能な疎通確認コマンド・fpingの紹介記事でした。