Capture LLDPand CDP packets using tcpdump

LLDP
tcpdump -vv -s1500 -c1 ‘ether proto 0x88cc’ -ni eth0

CDP
tcpdump -vv -s1500 -c1 ‘ether[20:2] == 0x2000’ -ni eth0

Advertisements

Collecting directly connected switch ports ID from multiple ESXi hosts

We are going to add vlan to a cluster. We need to know what are the switch ports for each Guest vmnic in each hosts so that we can ask the network team to trunk the new vlan.

This little script collects the switch ports information obtained using CDP. The list of hosts is stored in a text file list.

    for i in `cat list`
    do
    ssh -q -T root@$i <<EOF
    hostname
    vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnicX  | grep -E  'devId|portId'
    vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnicY  | grep -E  'devId|portId'
    echo
    EOF
    done

In this example, vmnicX and vmnicY are used for Guest network. If you don't have ssh keys setup, you can use sshpass.

    host1.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/2",
             devId = "SwitchB",
             portId = "Ethernet110/1/2",

    host2.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/4",
             devId = "SwitchB",
             portId = "Ethernet110/1/4",

    host3.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/6",
             devId = "SwitchB",
             portId = "Ethernet110/1/6",

    ... and so on

Which switch port is an ESXi vmnic connected to?

When I am given an ESXi host to build and configure, it is not always clear which vmnic is connected to which port on the physical switch nor which vmnic should be used for what purpose. When I am in this situation, I turn to CDP information. It does not always give a definite answer but it helps me ask the right question to the Network Admin. Continue reading