にほんブログ村
Windows には「Exping」という便利なツールがあるのですが、ExpingはLinuxでは使えません。でも、Linuxには「fping」があります。今回は、「fping」の使い方をまとめてみました。
fping のインストール
「apt install」でインストールできます。
$ sudo apt update
$ sudo apt install fping
ping の使い方
基本的な使い方は、1つの宛先に対して ICMP Echo Request を送ります。通常の ping と同じです。
ICMP Echo Reply が返ってこれば「xxxx is alive」、返ってこなければ「xxx is unreachable」と表示されます。
KKIntt@jackson:~$ fping 172.16.26.1
172.16.26.1 is alive
KKInt@jackson:~$ fping 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
172.16.26.5 is unreachable
もちろん、IPアドレスだけでなく、ホスト名を指定することもできます。
KKInt@jackson:~$ fping www.yahoo.co.jp
www.yahoo.co.jp is alive
宛先の複数指定
単純に、ICMP Echo Request を送信したい宛先を並べて指定します。
KKInt@jackson:~$ fping 172.16.26.1 172.16.26.2 172.16.26.4
172.16.26.1 is alive
172.16.26.2 is alive
172.16.26.4 is alive
範囲を指定しての宛先指定
-g オプションを使うことで、指定した範囲の IPアドレスに対して ICMP Echo Request を送信することが出来ます。
以下の例では、172.16.26.1から172.16.26.5までを範囲として指定しています。そのうち、4オクテッド目が3と5のIPアドレスからはICMP Echo Reply が返ってていません。
KKInt@jackson:~$ fping -g 172.16.26.1 172.16.26.5
172.16.26.1 is alive
172.16.26.2 is alive
172.16.26.4 is alive
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.3
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.3
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.3
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.3
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
172.16.26.3 is unreachable
172.16.26.5 is unreachable
サブネットマスクを指定しての宛先指定
-g オプションを使用すると、サブネットマスク単位で ICMP Echo Request を送信する範囲を指定することも出来ます。
「172.16.26.0/29」を指定する場合は、以下のように指定します。
最初の 172.16.26.0 はネットワークアドレス、最後の172.16.26.7 はブロードキャストアドレスになるため、「172.16.26.0/29」の場合、172.16.26.1 – 172.16.26.6 がPing の対象となります。
KKInt@jackson:~$ fping -g 172.16.26.0/29
172.16.26.1 is alive
172.16.26.2 is alive
172.16.26.4 is alive
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.6
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.6
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.6
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.6
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.5
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.3
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.3
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.3
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.3
172.16.26.3 is unreachable
172.16.26.5 is unreachable
172.16.26.6 is unreachable
kanta@jackson:~$
ファイルから読み込んで範囲指定
-f オプションを使用すると、ファイル読み込んでfpingを実行することが出来ます。
まず、ping-list というファイルを作成し、 以下のように宛先IPアドレスを記述しました。
KKInt@jackson:~$ cat ping-list
172.16.26.1
172.16.26.2
172.16.26.4
172.16.26.7
172.16.26.8
-f オプションで対象のファイルを読み込んで fping を実行することで、ファイルに記載されている宛先 IPアドレスに対して ICMP Echo Request を送信することが出来ます。
KKInt@jackson:~$ fping -f ping-list
172.16.26.1 is alive
172.16.26.2 is alive
172.16.26.4 is alive
172.16.26.7 is alive
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.8
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.8
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.8
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.8
172.16.26.8 is unreachable
結局はLinux上での操作ですので、ファイルの読み込ませ方は、いろいろできます。
「<」でファイルを fping に渡せますし、
$ fping < ping_list.txt
cat で表示させたファイルの内容を fping に渡すことも可能です。
$ cat ping_list.txt | fping
送信回数指定
-c オプションを使用すると、ICMP Echo Request を送信する回数を指定することが出来ます。
3回送信したい場合は、以下のように実行します。
KKInt@jackson:~$ fping -c3 172.16.26.1
172.16.26.1 : [0], 64 bytes, 0.203 ms (0.203 avg, 0% loss)
172.16.26.1 : [1], 64 bytes, 0.234 ms (0.218 avg, 0% loss)
172.16.26.1 : [2], 64 bytes, 0.150 ms (0.195 avg, 0% loss)
172.16.26.1 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 0.150/0.195/0.234
送信し続ける
ICMP Echo Request を送信し続けたい場合は -l オプションを使用します。
「Ctrl + C」で、Echo Request の送信を停止することができます。
KKInt@jackson:~$ fping -l 172.16.26.1
172.16.26.1 : [0], 64 bytes, 0.226 ms (0.226 avg, 0% loss)
172.16.26.1 : [1], 64 bytes, 0.132 ms (0.179 avg, 0% loss)
172.16.26.1 : [2], 64 bytes, 0.125 ms (0.161 avg, 0% loss)
172.16.26.1 : [3], 64 bytes, 0.195 ms (0.169 avg, 0% loss)
172.16.26.1 : [4], 64 bytes, 0.205 ms (0.176 avg, 0% loss)
172.16.26.1 : [5], 64 bytes, 0.223 ms (0.184 avg, 0% loss)
^C <<< Ctl + c で終了
172.16.26.1 : xmt/rcv/%loss = 6/6/0%, min/avg/max = 0.125/0.184/0.226
送信間隔(ミリ秒)
-i オプションを使用すると、ICMP Echo Request を送信する間隔を指定することが出来ます。
指定する時間の単位はミリ秒なので、3秒間隔ならば「3000」と指定します。
KKInt@jackson:~$ fping -c3 -i 3000 172.16.26.1
172.16.26.1 : [0], 64 bytes, 0.185 ms (0.185 avg, 0% loss)
172.16.26.1 : [1], 64 bytes, 0.138 ms (0.162 avg, 0% loss)
172.16.26.1 : [2], 64 bytes, 0.186 ms (0.170 avg, 0% loss)
172.16.26.1 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 0.138/0.170/0.186
ICMP Host Unreachableを表示させたくない
ICMP Echo Request が失敗した際に表示される「ICMP Host Unreachable 〜」というメッセージを表示させたくない場合の方法です。
「ICMP Host Unreachable 〜」は標準エラー出力なので、「2>」を指定してエラー出力を /dev/null に送ることで、メッセージの表示を抑えることができます。
KKInt@jackson:~$ fping -f ping-list 2> /dev/null
172.16.26.1 is alive
172.16.26.2 is alive
172.16.26.4 is alive
172.16.26.7 is alive
172.16.26.8 is unreachable
alive なホストのみ表示
-a オプションを使用すると、ICMP Echo Replyを返す(Alive)ホストのみを表示することができます。
以下の例では「ICMP Host Unreachable 〜」のメッセージを/dev/null に送って表示させないようにしています。
KKInt@jackson:~$ fping -a -f ping-list 2> /dev/null
172.16.26.1
172.16.26.2
172.16.26.4
172.16.26.7
-a オプションを使わなくても、以下のように grep で抽出することもできます。
KKInt@jackson:~$ fping -f ping-list 2> /dev/null | grep alive
172.16.26.1 is alive
172.16.26.2 is alive
172.16.26.4 is alive
172.16.26.7 is alive
unreachable だけ表示
-u オプションを使用すると、ICMP Echo Reply を返さないホスト(unreachable)のみを表示することができます。
KKInt@jackson:~$ fping -u -f ping-list 2> /dev/null
172.16.26.8
unreachable のメッセージも合わせて表示させたい場合は、fping の結果を grepに渡すことで unreachable のみ表示させることもできますね。
KKInt@jackson:~$ fping -f ping-list 2> /dev/null | grep unreachable
172.16.26.8 is unreachable
統計情報表示
-s オプションを使用すると、実行結果の統計情報を表示します。
KKInt@jackson:~$ fping -f ping-list -s
172.16.26.1 is alive
172.16.26.2 is alive
172.16.26.4 is alive
172.16.26.7 is alive
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.8
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.8
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.8
ICMP Host Unreachable from 172.16.26.11 for ICMP Echo sent to 172.16.26.8
172.16.26.8 is unreachable
5 targets
4 alive
1 unreachable
0 unknown addresses
4 timeouts (waiting for response)
8 ICMP Echos sent
4 ICMP Echo Replies received
4 other ICMP received
0.207 ms (min round trip time)
0.229 ms (avg round trip time)
0.249 ms (max round trip time)
4.107 sec (elapsed real time)
関連するブログ:
- Linux の基本コマンドが変更されて困った
- Raspberry Pi で SNMP エージェントを動かす
- モバイル PC で SaaS の快適アクセス
- LPIC を学ぶ(1) lsof コマンドについて
- Server Name Indication (SNI) とは
- Linux の Cron の基本的な使い方と設定方法
- UbuntuとQNAPのiSCSI統合方法
- Raspberry PiでのPi-Hole設定ガイド
- 複数の宛先に ping を打つことができる「fping」
最近の人気ブログ TOP 10:
- 夢の国で起きた悲劇 ~ディズニーリゾートで心中した一家~
- 新潟六日町のトンネル事件:恋愛に狂った暴力団員の極限の嫉妬
- 知られざる女子高生コンクリ詰め殺人発覚当時の報道(後編)
- 仙台アルバイト女性集団暴行殺人
- 犬鳴峠リンチ焼殺事件 ~超凶悪少年犯罪~
- 浜田省吾ファン必見の聖地巡礼訪問地リスト
- 広島の魅力: 浜田省吾ファン必見のスポット
- 未成年に踏みにじられた25歳の純情 ―実録・おやじ狩り被害―
- R40、テルの今:城東工業高校の伝説のその後
- 高崎山の王・ベンツ ~ミスターニホンザルの生涯~
最近の記事:
- 複数の宛先に ping を打つことができる「fping」
- ネイティブの英語 7 “A cup of joe”
- 死刑確定囚・野比のび太 – 第二十三話・昇華するのび太の鬱屈
- 死刑確定囚・野比のび太 – 第二十二話・静の怒りと武の苛立ち
- 死刑確定囚・野比のび太 – 第二十一話・夫婦間の亀裂とのび太の影響
- 死刑確定囚・野比のび太 – 第二十話・のび太の初出勤: 恐れと葛藤
- 死刑確定囚・野比のび太 – 第十九話・ジャイアンとのび太の絆
- 死刑確定囚・野比のび太 – 第十八話・引きこもりの息子と家族のジレンマ
- 死刑確定囚・野比のび太 – 第十七話・ドラえもんと30歳ののび太の葛藤
- 死刑確定囚・野比のび太 – 第十六話・剛田商店の成長と静香の貢献