9
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IPが分からないオンプレミスをコマンドラインから調べる。(arp-scan)

Last updated at Posted at 2017-02-15

事の始まり

別記事でRaspberryPiをいじってた時(Raspberry Pi 2 Model BをUbuntuサーバーにするまで)にIPが分からないRaspiにどうやってアクセスするかについて調べたので書き記しておきます。

RaspberryPiがサーバとして稼働し始めている場合

  • IPは固定にしておきましょう。
    • 何かと都合が良いです。

上記の場合は問題無いです。

持ち運びやlanが定期的に変わる場合

  • NWが構築途中だったり、Raspiを色々持ち運んで使っている場合
    • 環境にも寄りますが、DHCPで自動取得した後に手持ちのMacからssh(もしくはvnc)した方が楽です。
      • IPをハードコーディングしてしまうと、サブネットやルーティングの設定如何で疎通出来ないことの方が多いです。

では、この例の時はどのようにしてDHCPで取得したIPを確認すればいいでしょうか?

この時に使えるのが、arp-scanコマンドです。

インストール方法

ここからが本題です。

  • Centosの場合
$ sudo yum install arp-scan --enablerepo=epel
  • Macの場合
$ brew install arp-scan
  • Ubuntuの場合
$ apt-get install arp-scan

コマンド等

  • 基本
cmd
$ sudo arp-scan -I ${スキャンしたいlanに繋がっているnic名} -l

Macでの例

  • まずは自分のIPと刺さっているlanのnicを調べる
cmd
$ ifconfig

~~割愛~~

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
    ether 10:dd:b1:a3:XX:YY 
    inet6 fe80::12dd:b1ff:fea3:e400%en0 prefixlen 64 scopeid 0x4 
    inet 192.168.10.91 netmask 0xffffff00 broadcast 192.168.10.255
    nd6 options=1<PERFORMNUD>
    media: autoselect (100baseTX <full-duplex,flow-control,energy-efficient-ethernet>)
    status: active
en1: flags=8823<UP,BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500
    ether ec:35:86:2c:XX:YY 
    nd6 options=1<PERFORMNUD>
    media: autoselect (<unknown type>)
    status: inactive
en4: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
    options=60<TSO4,TSO6>
    ether 32:00:18:ba:XX:YY 
    media: autoselect <full-duplex>
    status: inactive

~~割愛~~

上記から、en0 というnicに 192.168.10.91 というIPが付与されていて、そこから通信しているのが分かる

  • en0 と同じレイヤーのIPをスキャンする。
cmd
$ sudo arp-scan -I en0 -l
or
$ sudo arp-scan --interface en0 -l
=======================

$ sudo arp-scan --interface en0 -l
Password:
Interface: en0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.10.1    00:a0:de:3a:XX:YY   XXX
192.168.10.19   00:22:19:6a:XX:YY   Dell Inc
192.168.10.100  f0:4d:a2:f9:XX:YY   Dell Inc.
192.168.10.103  c0:ff:d4:d3:XX:YY   (Unknown)

~~割愛~~

以上で、IPとMACアドレスがコマンドラインから分かるようになりました。

RaspberryPiを探す!!

上述したRaspberryPiのを探してみます

事前にMACアドレスを調べておく(メモる)

  • こればかりはハード依存なので…(ちなみに私はテプラで筐体に貼ってます。

ここに写真

コマンドラインにて、MACアドレスからIPを探す。

  • 手元のMacから探してみます。
$ sudo arp-scan --interface en0 -l | grep b8:27:eb:7e:25:27
192.168.10.161  b8:27:eb:7e:25:27   Raspberry Pi Foundation
  • 本当に意図しているRaspberryPiか、SSHしてみます。
$ ssh  ubuntu@192.168.10.161
Warning: Permanently added '192.168.10.161' (ECDSA) to the list of known hosts.
ubuntu@192.168.10.161's password: 
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-1042-raspi2 armv7l)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

20 packages can be updated.
0 updates are security updates.


Last login: Fri Feb 10 00:07:14 2017 from 192.168.10.91
ubuntu@ubuntu:~$ 

---> 成功です。

9
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?