How to find out which switch port linux host is connected to?

7:57 PM

We can use "tcpdump" command in linux shell/command line to find out network switch connected to the linux server. The command is (assuming you are checking for eth0)
tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'

Output would be something similar to:
[root@ashinfoapp06s ~]# /usr/sbin/tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 1500 bytes
02:33:58.252088 CDPv2, ttl: 180s, checksum: 692 (unverified), length 450
        Device-ID (0x01), length: 25 bytes: 'as1c503ag1od.opsource.net'
        Version String (0x05), length: 264 bytes:
          Cisco IOS Software, s72033_rp Software (s72033_rp-ADVENTERPRISEK9_WAN-M), Version 12.2(33)SXI4a, RELEASE SOFTWARE (fc2)
          Technical Support: http://www.cisco.com/techsupport
          Copyright (c) 1986-2010 by Cisco Systems, Inc.
          Compiled Fri 16-Jul-10 19:51 by prod_rel_team
        Platform (0x06), length: 16 bytes: 'cisco WS-C6509-E'
        Address (0x02), length: 13 bytes: IPv4 (1) 10.182.100.2
        Port-ID (0x03), length: 19 bytes: 'GigabitEthernet9/44'
        Capability (0x04), length: 4 bytes: (0x00000029): Router, L2 Switch, IGMP snooping
        Prefixes (0x07), length: 25 bytes:  IPv4 Prefixes (5): 10.182.140.0/23 127.0.0.0/8 127.0.0.0/8 10.182.100.0/23 10.182.244.176/29
        VTP Management Domain (0x09), length: 10 bytes: 'ag1odash01'
        Native VLAN ID (0x0a), length: 2 bytes: 2909
        Duplex (0x0b), length: 1 byte: full
        AVVID trust bitmap (0x12), length: 1 byte: 0x00
        AVVID untrusted ports CoS (0x13), length: 1 byte: 0x00
        Management Addresses (0x16), length: 13 bytes: IPv4 (1) 10.182.100.2

Using cdpr ( Alternative option for linux host connected to cisco switch )
You can also make use of cdpr utility if the switch is a cisco switch. Just install the cdpr rpm on linux host and run cdpr to make use of this utility. cdpr is used to decode a Cisco Disovery Protocol (CDP) packet, by default it will report the device ID, the IP Address (of the device), and the port number that the machine is connected to.

You Might Also Like

0 comments

Contact Form

Name

Email *

Message *

Translate

Wikipedia

Search results