ある IP アドレスを忘れた時にコマンド一発で ping を順繰りに打ってその IP をさくっと見つける方法

fping というコマンドをインストールして実行すれば良い

僕は以下のようにして CentOS 7 にインストールしました。

$ yum search fping
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.riken.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
=========================================================== N/S matched: fping ===========================================================
nagios-plugins-fping.x86_64 : Nagios Plugin - check_fping
fping.x86_64 : Scriptable, parallelized ping-like utility

  Name and summary matches only, use "search all" for everything.
$ sudo yum install fping.x86_64
[sudo] password for oreore: 
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.riken.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ fping.x86_64 0:3.10-4.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

====================================================================================================================================
 Package                       アーキテクチャー               バージョン                         リポジトリー                  容量
====================================================================================================================================
インストール中:
 fping                         x86_64                         3.10-4.el7                         epel                          46 k

トランザクションの要約
====================================================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 46 k
インストール容量: 104 k
Is this ok [y/d/N]: y
Downloading packages:
fping-3.10-4.el7.x86_64.rpm                                                                                  |  46 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : fping-3.10-4.el7.x86_64                                                                             1/1 
  検証中                  : fping-3.10-4.el7.x86_64                                                                             1/1 

インストール:
  fping.x86_64 0:3.10-4.el7                                                                                                         

完了しました!
$ which fping
/usr/sbin/fping
$

fping の使い方

例えば、192.168.10.0/24 のセグメントに対して ping を連射してそこにある IP を見つけるのは以下の要領で fping を実行します。

$ fping -g 192.168.10.0/24

今回僕は自宅で使用している

10.1.0.0/24

172.16.1.0/24

の2つのセグメントで使用している IP を洗い出しました。

以下の用に、起点となる IP と終点となる IP を引数に指定してやることもできます。

$ fping -g 10.1.0.1 10.1.0.254
10.1.0.1 is alive
10.1.0.2 is alive
10.1.0.6 is alive
10.1.0.8 is alive
10.1.0.3 is alive
10.1.0.4 is alive
ICMP Host Unreachable from 172.16.1.1 for ICMP Echo sent to 10.1.0.5
10.1.0.201 is alive
10.1.0.202 is alive
ICMP Host Unreachable from 172.16.1.1 for ICMP Echo sent to 10.1.0.9
ICMP Host Unreachable from 172.16.1.1 for ICMP Echo sent to 10.1.0.10
ICMP Host Unreachable from 172.16.1.1 for ICMP Echo sent to 10.1.0.11
ICMP Host Unreachable from 172.16.1.1 for ICMP Echo sent to 10.1.0.12
ICMP Host Unreachable from 172.16.1.1 for ICMP Echo sent to 10.1.0.13

(以下、略)

上記の例で行くと、10.1.0.201 あたりの IP を探していたわけです。これが見つかってよかったです。

ブロードキャストアドレス宛てに ping を打つって手もあるんでしょうけど、それだとなんか上手く行かなかったんですよね〜。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください