LoginSignup
8
4

More than 3 years have passed since last update.

ESXiにてパケットキャプチャを取得する方法

Last updated at Posted at 2020-09-16

この記事の目的

  • VMware ESXi上の管理マネジメント通信やゲストOSにてネットワークトラブルが発生した際の調査に役立つパケットキャプチャをIPアドレスに紐づいた情報から取得する方法を紹介します。

  • VMware社Blog 新卒SE社員が贈る vSphereのキソおよび、VMware社Blog 仮想スイッチのお作法を参照させていただきました。VMware製品のネットワーク周りの情報を体系立てて説明してあるので、ぜひご一読ください。

テストした環境

  • vCenter
    VMware vSphere 6.5 U3f

  • ESXi
    VMware ESXi 6.5 P04

今回データを取得する対象範囲について

  • コマンドだけでは、どの部分のデータを取得しているのかわかりづらいので下記に今回の対象ポートについて記載しました。 以下の図を参照ください。出典(図3)

image.png

vmk0でデータを取得する手順

  • 該当ESXiにSSHログインし、VMkernelの管理アドレスが10.xxx.15.12であるため、念のためvmk0を利用していることを確認します。
  • [esxcli network ip interface ipv4 get] コマンドにて、紐づいているインターフェイス名が vmk0 であることが確認できます。(下記コマンド結果を参照)

[admin@vcs000:/tmp] esxcli network ip interface ipv4 get
Name  IPv4 Address    IPv4 Netmask     IPv4 Broadcast  Address Type  Gateway  DHCP DNS
----  --------------  ---------------  --------------  ------------  -------  --------
vmk0  10.xxx.15.12    255.255.255.192  10.xxx.15.63    STATIC        0.0.0.0     false
vmk2  10.xxx.30.67    255.255.255.192  10.xxx.30.127   STATIC        0.0.0.0     false
vmk3  10.xxx.22.131   255.255.255.192  10.xxx.22.191   STATIC        0.0.0.0     false
vmk1  10.xxx.105.195  255.255.255.192  10.xxx.105.255  STATIC        0.0.0.0     false
[admin@vcs000:/tmp]
  • キャプチャする際に指定が必要となる"PortNum"の番号を確認するため、"net-stats -l" コマンドを実行する 
[admin@vcs000:/tmp] net-stats -l
PortNum          Type SubType SwitchName       MACAddress         ClientName
50331650            4       0 DvsPortset-0     ac:1f:6b:c6:46:00  vmnic2
50331652            3       0 DvsPortset-0     00:50:56:6c:70:87  vmk0
50331653            3       0 DvsPortset-0     00:50:56:64:9d:d1  vmk1
50331654            3       0 DvsPortset-0     00:50:56:68:3c:c5  vmk2
50331655            3       0 DvsPortset-0     00:50:56:6a:22:1a  vmk3
50331656            4       0 DvsPortset-0     ac:1f:6b:c6:45:fe  vmnic0
50331658            5       9 DvsPortset-0     00:50:56:84:ee:80  nsxt25-nsxt-ctrlmgr1.eth0
50331663            5       9 DvsPortset-0     00:50:56:84:44:c6  service-edge01.eth2
50331664            5       9 DvsPortset-0     00:50:56:84:2e:a6  service-edge01.eth1
50331665            5       9 DvsPortset-0     00:50:56:84:29:72  service-edge01.eth0
67108866            4       0 DvsPortset-1     ac:1f:6b:c6:45:ff  vmnic1
67108868            4       0 DvsPortset-1     ac:1f:6b:c6:46:01  vmnic3
67108870            5       9 DvsPortset-1     00:50:56:84:e1:b0  service-edge01.eth3
[admin@vcs000:/tmp]

-> "50331652"がvmk0のPortNumとして紐づいていることを確認
 
* パケットキャプチャ開始( 受信パケットdir0側 )
* "pktcap-uw -o /tmp/edge-YYYYDDMM.dir0 --switchport 50331652 --dir 0"のコマンドを入力。

: Ctl+Cにてパケットキャプチャを停止
: ファイル世代管理できるようにYYYYDDMM(日付)を指定します


[admin@vcs000:~] pktcap-uw -o /tmp/edge-YYYYDDMM.dir0 --switchport 50331652 --dir 0
The output file is /tmp/edge-20200916.dir0.
The switch port id is 0x03000004.
No server port specifed, select 45432 as the port.
Local CID 2.
Listen on port 45432.
Accept...
Vsock connection from port 1034 cid 2.
Dump: 19, broken : 0, drop: 0, file err: 0.
Dump: 32, broken : 0, drop: 0, file err: 0.
Dump: 46, broken : 0, drop: 0, file err: 0.
Dump thread exiting...
Receive thread exiting...
Dumped 46 packet to file /tmp/edge-20200916.dir0, dropped 0 packets.
Done.
[admin@vcs000:~]

** パケットキャプチャ開始( 送信パケットdir1側 ) 
* "pktcap-uw -o /tmp/edge-YYYYDDMM.dir1 --switchport 50331652 --dir 1"のコマンドを入力。

: dir0とは別の新規SSHセッションを立ち上げる必要があります

[admin@vcs000:~] pktcap-uw -o /tmp/edge-YYYYDDMM.dir1 --switchport 50331652 --dir 1
The output file is /tmp/edge-20200916.dir1.
The switch port id is 0x03000004.
No server port specifed, select 45439 as the port.
Local CID 2.
Listen on port 45439.
Accept...
Vsock connection from port 1035 cid 2.
Dump: 20, broken : 0, drop: 0, file err: 0.
Dump: 32, broken : 0, drop: 0, file err: 0.
Dump thread exiting...
Receive thread exiting...
Dumped 32 packet to file /tmp/edge-20200916.dir1, dropped 0 packets.
Done.
[admin@vcs000:~]
  • ファイルが/tmp配下に作成されていることを確認する。
[admin@vcs000:/tmp] ls -l
total 100
-r--r--r--    1 root     root         12116 Sep 16 01:58 edge-20200916.dir0
-r--r--r--    1 root     root          5018 Sep 16 01:58 edge-20200916.dir1
[admin@vcs000:/tmp]
  • 以上で、データ取得は完了です。 上記作成されたファイルをscpなどで転送し、Wiresharkなどのパケットキャプチャツールに読み込ませることでデータ解析が可能です。

補足事項

今回はVMKernel(管理やvMotion)で利用されているvmk0のデータキャプチャを取得しましたが、ゲストOSの問題を取りたい場合は仮想スイッチにて複数のvNICがPortGroupでグルーピングされているため、物理側のNIC(以下図の例では、vmnic2,vmnic3)で取得すると良いと思います。(もし認識が間違っていたり、他に良い方法がある場合はコメントでお知らせいただけると幸いです)

image.png

その他参考文献

VMware Docs パケットのキャプチャ用 pktcap-uw コマンドの構文

8
4
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
8
4