{"id":155,"date":"2010-05-20T12:23:19","date_gmt":"2010-05-20T18:23:19","guid":{"rendered":"http:\/\/benincosa.com\/blog\/?p=155"},"modified":"2014-11-19T11:26:26","modified_gmt":"2014-11-19T17:26:26","slug":"server-to-switch-port-mapping-with-snmp","status":"publish","type":"post","link":"https:\/\/benincosa.com\/?p=155","title":{"rendered":"Server to Switch Port mapping with SNMP"},"content":{"rendered":"<p>Let&#8217;s say you have a switch.\u00a0 And you are on a computer that is connected to the switch.\u00a0 You know the following:<\/p>\n<ul>\n<li>The name of the switch<\/li>\n<li>The SNMP community string and version the switch uses.<\/li>\n<\/ul>\n<p>But, you&#8217;re too lazy to walk over to the data center to figure out which port you&#8217;re connected on.<\/p>\n<p>Here&#8217;s what you do (assuming you&#8217;re running Red Hat or CentOS)<\/p>\n<pre>yum - y install net-snmp-utils<\/pre>\n<p>This gives you the snmpwalk command.<\/p>\n<p>Now:<\/p>\n<p>first, figure out your MAC address:<\/p>\n<pre>[root@n33 etc]# ifconfig eth0\r\neth0\u00a0\u00a0\u00a0\u00a0\u00a0 Link encap:Ethernet\u00a0 HWaddr 00:A0:D1:E9:3E:DC \u00a0\r\n inet addr:10.3.0.133\u00a0 Bcast:10.3.255.255\u00a0 Mask:255.255.0.0\r\n inet6 addr: fe80::2a0:d1ff:fee9:3edc\/64 Scope:Link\r\n UP BROADCAST RUNNING MULTICAST\u00a0 MTU:1500\u00a0 Metric:1\r\n RX packets:972965 errors:0 dropped:0 overruns:0 frame:0\r\n TX packets:637686 errors:0 dropped:0 overruns:0 carrier:0\r\n collisions:0 txqueuelen:1000\r\n RX bytes:587009797 (559.8 MiB)\u00a0 TX bytes:100870077 (96.1 MiB)\r\n Memory:fcde0000-fce00000<\/pre>\n<p>So my Mac is 00:A0:D1:E9:3E:DC<\/p>\n<p>Nice.<\/p>\n<p>Now lets look for this mac address on the switch.\u00a0 Assuming my community string is &#8216;foobar&#8217; and my switch is set up to do snmp version 1, and my switch name is switch1, I do:<\/p>\n<pre>snmpwalk\u00a0 -v 1 -c foobar switch1 SNMPv2-SMI::mib-2.17.4.3.1.1<\/pre>\n<p>When you do this, you&#8217;ll see a list of the nodes.\u00a0 Among them should be a Hex-STRING that matches your MAC address:<\/p>\n<pre>...\r\nSNMPv2-SMI::mib-2.17.4.3.1.1.0.160.209.233.62.220 = Hex-STRING: 00 A0 D1 E9 3E DC\r\n...<\/pre>\n<p>Notice that the string:<\/p>\n<pre>0.160.209.233.62.220<\/pre>\n<p>Is the decimal representation of the MAC address:<\/p>\n<pre>00:A0:D1:E9:3E:DC<\/pre>\n<p>So you have verified one important piece of information:\u00a0 You are in fact connected on this switch!<\/p>\n<p>Now figure out which port!<\/p>\n<p>We use the decimal representation of the MAC address from this point on to find the port.\u00a0 Usually for me this works:<\/p>\n<pre>snmpwalk -v 1 -c foobar switch1 SNMPv2-SMI::mib-2.17.7.1.2.2.1.2<\/pre>\n<p>Among the output I get:<\/p>\n<pre>SNMPv2-SMI::mib-2.17.7.1.2.2.1.2.413.0.160.209.233.62.220 = INTEGER: 5<\/pre>\n<p>This tells me that my node is connected to port 5 on the switch.<\/p>\n<p>Sometimes (on cisco switches and others) you may need to use a different approach for the mac-to-index values:<\/p>\n<pre>snmpwalk -v 1 -c foobar switch1 SNMPv2-SMI::mib-2.17.4.3.1.2<\/pre>\n<p>This is great, in that I never had to leave my chair to figure this out!\u00a0 The pounds pile up and my largeness increases.\u00a0 Anybody got a better\/easier way to do this?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say you have a switch.\u00a0 And you are on a computer that is connected to the switch.\u00a0 You know the following: The name of the switch The SNMP community string and version the switch uses. But, you&#8217;re too lazy to walk over to the data center to figure out which port you&#8217;re connected on&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[920],"tags":[62,63,61],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/155"}],"collection":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=155"}],"version-history":[{"count":4,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/155\/revisions"}],"predecessor-version":[{"id":2822,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/155\/revisions\/2822"}],"wp:attachment":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}