no about note

エンジニアのメモ書き

ESXi5.5でパケットキャプチャツール「pktcap-uw」を使ってみた

pktcap-uwとは

  • ESXi5.5から提供されたパケットキャプチャツール
  • 標準仮想スイッチ、分散仮想スイッチでも使用可能
  • 以前からあったtcpdump-uwツールの代わりに使用できる
  • tcpdump-uwはvmkernelだけだったが、pktcap-uwはハイパーバイザー内のすべてのポイントでトラフィックをキャプチャできる
  • pcapファイルでエクスポートできるので、Wiresharkなどでパケット解析ができる

使い方

  • ESXiにSSH接続する

ESXi5.5でsshを有効にする方法

できること

ポートごと

–switchport <port ID> (Specify the switch port by ID)
–lifID <lif ID> (Specify the logical interface id of VDR port)
–vmk <vmk NIC> (Specify the switch port by vmk NIC)
–uplink <vmnic> (Specify the switch port by vmnic)

キャプチャポイント一覧

# pktcap-uw -A
Supported capture points:
1: Dynamic — The dynamic inserted runtime capture point.
2: UplinkRcv — The function that receives packets from uplink dev
3: UplinkSnd — Function to Tx packets on uplink
4: Vmxnet3Tx — Function in vnic backend to Tx packets from guest
5: Vmxnet3Rx — Function in vnic backend to Rx packets to guest
6: PortInput — Port_Input function of any given port
7: IOChain — The virtual switch port iochain capture point.
8: EtherswitchDispath — Function that receives packets for switch
9: EtherswitchOutput — Function that sends out packets, from switch
10: PortOutput — Port_Output function of any given port
11: TcpipDispatch — Tcpip Dispatch function
12: PreDVFilter — The DVFIlter capture point
13: PostDVFilter — The DVFilter capture point
14: Drop — Dropped Packets capture point
15: VdrRxLeaf — The Leaf Rx IOChain for VDR
16: VdrTxLeaf — The Leaf Tx IOChain for VDR
17: VdrRxTerminal — Terminal Rx IOChain for VDR
18: VdrTxTerminal — Terminal Tx IOChain for VDR
19: PktFree — Packets freeing point

フィルターオプション

–srcmac <xx:xx:xx:xx:xx> (The Ethernet source MAC address)
–dstmac <xx:xx:xx:xx:xx> (The Ethernet destination MAC address)
–mac <xx:xx:xx:xx:xx> (The Ethernet MAC address(src or dst))
–ethtype 0x<ETHTYPE> (The Ethernet type. HEX format)
–vlan <VLANID> (The Ethernet VLAN ID)
–srcip <x.x.x.x[/<range>]> (The source IP address)
–dstip <x.x.x.x[/<range>]> (The destination IP address)
–ip <x.x.x.x> (The IP address(src or dst))
–proto 0x<IPPROTYPE> (The IP protocol)
–srcport <SRCPORT> (The TCP source port)
–dstport <DSTPORT> (The TCP destination port)
–tcpport <PORT> (The TCP port(src or dst))
–vxlan <vxlan id> (The vxlan id of flow)

キャプチャする仮想マシンの情報を取得する

## 有効なnic一覧
# esxcli network nic list

## 有効なインターフェイス一覧
# esxcli network ip interface list

## iポートのIP情報
# esxcli network ip interface ipv4 get

## ネットワークが有効な仮想マシン一覧
# esxcli network vm list

## PortIDがわかる
# esxtop  
 →  nを押下

ヘルプ

# pktcap-uw -h |more

vmkernel ポートのトラフィックのライブ キャプチャを表示する

# pktcap-uw --vmk vmkX
# pktcap-uw --vmk vmk0
The name of the vmk is vmk0
No server port specifed, select 48475 as the port
Output the packet info to console.
Local CID 2
Listen on port 48475
Accept...Vsock connection from port 1025 cid 2
04:55:36.998505[1] Captured at PortInput point, TSO not enabled, Checksum offloaded and not verified, length 154.
        Segment[0] ---- 54 bytes:
        0x0000:  0000 5e00 0102 0026 554a 6100 0800 4510
        0x0010:  008c dbf5 4000 4006 53d0 0ac8 3d35 c0a8
        0x0020:  01f1 0016 f512 9103 f13d fcb2 da71 5018
        0x0030:  0080 0b15 0000
        Segment[1] ---- 100 bytes:
        0x0030:                 e8bc 3e7d 8ccb ee66 7f60
        0x0040:  6776 2009 f8b4 f247 f07e e17b b53b e19b
        0x0050:  7759 cf68 00c9 2145 17b9 b95f f8bb 679c
        0x0060:  bfab b32c 79ef 60a5 7acb 38b2 e61f 1065
        0x0070:  7612 6bc1 06e5 0aef 9b33 10b5 dd26 81f3
        0x0080:  2327 1140 80d4 c590 5176 d587 62d2 09bf
        0x0090:  2c1c f9e7 4e91 b5e8 3e88
~~~~~~~~~~

ESXiホスト vmnic 上の特定の物理ネットワーク カードのライブ キャプチャを表示する

# pktcap-uw --uplink vmnic0

仮想マシンの特定の vSwitch ポートのライブ キャプチャを表示す

仮想マシンのvSwitch ポート番号を取得する
# net-stats -l
取得したポートをキャプチャする
# pktcap-uw --switchport switchportnumber
# pktcap-uw --switchport (PortID)

キャプチャしたデータをpcapファイルに保存する

# pktcap-uw --vmk vmk0 -o /tmp/test.pcap
The name of the vmk is vmk0
The output file is /tmp/test.pcap
No server port specifed, select 58077 as the port
Local CID 2
Listen on port 58077
Accept...Vsock connection from port 1030 cid 2
Dump: 171766, broken : 0, drop: 0, file err: 0Destroying session 6

Dumped 171766 packet to file /tmp/test.pcap, dropped 0 packets.
Done.

→ ctl+c で終了する

# ls -la /tmp/test.pcap
-r--r--r--    1 root     root      31830971 Jun  8 05:57 /tmp/test.pcap

参考