How to Determine the Switch a Linux Server is Connected to

To determine what switch you are connected to (this is only known to work on Cisco switches as it replies on CDP (Cisco Discovery Protocol) but may also work on others), run the following command under Linux.

tcpdump -nn -v -i <INTERFACE> -s 1500 -c 1 ‘ether[20:2] == 0x2000′

This may take 30 seconds or so to come back but will give you switch information including the IP address.

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 1500 bytes
17:17:12.805388 CDPv2, ttl: 180s, checksum: 692 (unverified), length 448
        Device-ID (0x01), length: 24 bytes: ''
        Version String (0x05), length: 247 bytes:
          Cisco IOS Software, C3560 Software (C3560-IPSERVICESK9-M), Version 12.2(53)SE1, RELEASE SOFTWARE (fc2)
          Technical Support:
          Copyright (c) 1986-2010 by Cisco Systems, Inc.
          Compiled Fri 12-Mar-10 16:54 by prod_rel_team
        Platform (0x06), length: 20 bytes: 'cisco WS-C3560G-24TS'
        Address (0x02), length: 13 bytes: IPv4 (1)
        Port-ID (0x03), length: 18 bytes: 'GigabitEthernet0/6'
        Capability (0x04), length: 4 bytes: (0x00000028): L2 Switch, IGMP snooping
        Protocol-Hello option (0x08), length: 32 bytes:
        VTP Management Domain (0x09), length: 0 byte: ''
1 packets captured
1 packets received by filter
0 packets dropped by kernel

We hope you find this article informative. Please share it with your friends, colleagues, and on all your favorite social sites. Let us know what interests you, and we will write it. Don’t forget to leave a comment.

Leave a Reply