{"id":3859,"date":"2019-09-08T10:40:34","date_gmt":"2019-09-08T15:40:34","guid":{"rendered":"https:\/\/dev.iachieved.it\/iachievedit\/?p=3859"},"modified":"2019-09-08T10:40:34","modified_gmt":"2019-09-08T15:40:34","slug":"openwrt-snmp-interface-descriptions","status":"publish","type":"post","link":"https:\/\/dev.iachieved.it\/iachievedit\/openwrt-snmp-interface-descriptions\/","title":{"rendered":"OpenWrt SNMP Interface Descriptions"},"content":{"rendered":"<p>If you&#8217;re familiar with configuring network gear, you know that a <i>very<\/i> useful best practice is providing &#8220;plain English&#8221; descriptions of your device&#8217;s ports.  For example, on my <a href=\"https:\/\/www.cisco.com\/c\/en\/us\/support\/switches\/sf500-48mp-48-port-10-100-max-poe-plus-stackable-managed-switch\/model.html\">Cisco SF500-48MP switch<\/a> port 24 is the &#8220;uplink port&#8221; to the gateway router.  I make this clear in the port&#8217;s description:<\/p>\n<p>[code lang=text]<br \/>\nsw01#show interfaces description fa1\/2\/24<br \/>\nPort      Description<br \/>\n&#8212;&#8212;-   &#8212;&#8212;&#8212;&#8211;<br \/>\nfa1\/2\/24  Uplink to Internet Gateway<br \/>\n[\/code]<\/p>\n<p>By doing so, the <code>ifAlias<\/code> OID for this interface is set:<\/p>\n<p>[code lang=text]<br \/>\nsnmpget -c public -v2c sw01.iachieved.it IF-MIB::ifAlias.24<br \/>\nIF-MIB::ifAlias.24 = STRING: Uplink to Internet Gateway<br \/>\n[\/code]<\/p>\n<p>What is particularly nice about this is that a network monitoring tool such as <a href=\"\">Observium<\/a> will display the <code>ifAlias<\/code> string as a part of the description of the port.  Like I said, this becomes <i>very<\/i> useful, particularly when trying to track down where ports lead to.<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2019\/09\/uplink.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2019\/09\/uplink.png\" alt=\"\" width=\"643\" height=\"231\" class=\"aligncenter size-full wp-image-3867\" \/><\/a><\/p>\n<p>In the <a href=\"https:\/\/dev.iachieved.it\/iachievedit\/recognizing-openwrt-as-an-os-in-observium\/\"> previous post<\/a> we installed SNMP on an OpenWrt router and surfaced it in Observium.  By default the <a href=\"https:\/\/openwrt.org\/docs\/guide-user\/services\/snmp\/server\">snmpd<\/a> package doesn&#8217;t present any information for <code>ifAlias<\/code>, but we can fix that with <a href=\"http:\/\/net-snmp.sourceforge.net\/tutorial\/tutorial-5\/commands\/snmpset.html\"><code>snmpset<\/code><\/a>.<\/p>\n<h2>Permitting snmpset Access<\/h2>\n<p><code>snmpset<\/code> will make use of the SNMP <code>private<\/code> community on our OpenWrt (note:  if you were working in a production environment you might consider using SNMP v3 with authentication or at the very least changing your community strings).  By default the OpenWrt SNMP configuration only permits use of the <code>private<\/code> community from <code>localhost<\/code> (i.e., the router itself).  We&#8217;ll change that to permit access from our private subnet:<\/p>\n<p>Find this section in your <code>\/etc\/config\/snmpd<\/code> file<\/p>\n<p>[code lang=text]<br \/>\nconfig com2sec private<br \/>\n    option secname rw<br \/>\n    option source localhost<br \/>\n    option community private<br \/>\n[\/code]<\/p>\n<p>and change the <code>option source<\/code> like this:<\/p>\n<p>[code lang=text]<br \/>\n    option source 192.168.77.0\/24<br \/>\n[\/code]<\/p>\n<p>Obviously you&#8217;ll use the appropriate subnet in your configuration.<\/p>\n<p>Restart <code>snmpd<\/code> on the router with <code>\/etc\/init.d\/snmpd restart<\/code>.<\/p>\n<h2>Updating ifAlias<\/h2>\n<p>To update the appropriate <code>ifAlias<\/code> entries we need to see the <code>ifDescr<\/code> list.  This can be obtained by walking <code>ifDescr<\/code> with <code>snmpwalk<\/code>:<\/p>\n<p>[code lang=text]<br \/>\nsnmpwalk  -c public -v2c gw.gw01.chcgil01.iachieved.it ifDescr<br \/>\nIF-MIB::ifDescr.1 = STRING: lo<br \/>\nIF-MIB::ifDescr.2 = STRING: eth1<br \/>\nIF-MIB::ifDescr.3 = STRING: eth0<br \/>\nIF-MIB::ifDescr.5 = STRING: wlan0<br \/>\nIF-MIB::ifDescr.6 = STRING: wlan1<br \/>\nIF-MIB::ifDescr.7 = STRING: br-lan<br \/>\nIF-MIB::ifDescr.8 = STRING: eth0.1<br \/>\nIF-MIB::ifDescr.9 = STRING: eth1.2<br \/>\nIF-MIB::ifDescr.10 = STRING: eth0.100<br \/>\nIF-MIB::ifDescr.11 = STRING: eth1.3<br \/>\nIF-MIB::ifDescr.12 = STRING: eth1.4<br \/>\n[\/code]<\/p>\n<p>In our Chicago router example let&#8217;s label the three interfaces that are OSPF links to other routers:<\/p>\n<ul>\n<li><code>eth1.2<\/code> is a link to <code>gw01.dnvrco01<\/code><\/li>\n<li><code>eth1.3<\/code> is a link to <code>gw01.atlaga01<\/code><\/li>\n<li><code>eth1.4<\/code> is a link to <code>gw01.dllstx01<\/code><\/li>\n<\/ul>\n<p>From the output of <code>ifDescr<\/code> we can see that<\/p>\n<ul>\n<li><code>eth1.2<\/code> will map to <code>ifAlias.9<\/code><\/li>\n<li><code>eth1.3<\/code> will map to <code>ifAlias.11<\/code><\/li>\n<li><code>eth1.4<\/code> will map to <code>ifAlias.12<\/code><\/li>\n<\/ul>\n<p>So let&#8217;s set those <code>ifAlias<\/code> strings!<\/p>\n<p>[code lang=text]<br \/>\n# snmpset -c private -v2c gw.gw01.chcgil01.iachieved.it ifAlias.9 string &quot;OSPF Link to gw01.dnvrco01&quot;<br \/>\nIF-MIB::ifAlias.9 = STRING: OSPF Link to gw01.dnvrco01<br \/>\n# snmpset -c private -v2c gw.gw01.chcgil01.iachieved.it ifAlias.11 string &quot;OSPF Link to gw01.atlaga01&quot;<br \/>\nIF-MIB::ifAlias.11 = STRING: OSPF Link to gw01.atlaga01<br \/>\n# snmpset -c private -v2c gw.gw01.chcgil01.iachieved.it ifAlias.12 string &quot;OSPF Link to gw01.dllstx01&quot;<br \/>\nIF-MIB::ifAlias.12 = STRING: OSPF Link to gw01.dllstx01<br \/>\n[\/code]<\/p>\n<h2>The Catch<\/h2>\n<p>The problem with this approach is its persistence &#8211; reboot your router and watch those interface descriptions bite the dust.  But no worries, the fix is simple.<\/p>\n<p>Go back to <code>\/etc\/config\/snmpd<\/code> and change your <code>private<\/code> community to accept interaction from <code>localhost<\/code> (in other words, what it was originally!):<\/p>\n<p>[code lang=text]<br \/>\nconfig com2sec private<br \/>\n    option secname rw<br \/>\n    option source localhost<br \/>\n    option community private<br \/>\n[\/code]<\/p>\n<p>Restart <code>snmpd<\/code> with <code>\/etc\/init.d\/snmpd restart<\/code>.<\/p>\n<p>On the router we&#8217;re going to edit <code>\/etc\/rc.local<\/code> and before <code>exit 0<\/code> put:<\/p>\n<p>[code lang=text]<br \/>\n# Wait for snmpd to accept connections<br \/>\n\/bin\/sleep 5<\/p>\n<p>\/usr\/bin\/snmpset -c private -v2c localhost ifAlias.9 string &quot;OSPF Link to gw01.dnvrco01&quot; &gt; \/tmp\/snmpset.log<br \/>\n\/usr\/bin\/snmpset -c private -v2c localhost ifAlias.11 string &quot;OSPF Link to gw01.atlaga01&quot; &gt;&gt; \/tmp\/snmpset.log<br \/>\n\/usr\/bin\/snmpset -c private -v2c localhost ifAlias.12 string &quot;OSPF Link to gw01.dllstx01&quot; &gt;&gt; \/tmp\/snmpset.log<br \/>\n[\/code]<\/p>\n<p>I have not optimized the <code>\/bin\/sleep<\/code> at this point, but without it <code>snmpset<\/code> will be talking to an <code>snmpd<\/code> daemon that isn&#8217;t ready.  Trust me.<\/p>\n<p>You can now reboot the router and the custom interface descriptions will survive.<\/p>\n<h2>Wrapping Up<\/h2>\n<p>Why did we go to all the trouble of creating descriptions (aliases) for our OpenWrt interfaces?  Again, monitoring tools such as Observium will take those descriptions and apply them to your UI.<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2019\/09\/labeledInterfaces.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2019\/09\/labeledInterfaces.png\" alt=\"\" width=\"1082\" height=\"459\" class=\"aligncenter size-full wp-image-3864\" \/><\/a><\/p>\n<p>At a glance I can quickly see, for example, that <code>eth1.2<\/code> is the interface being used for OSPF with <code>gw01.dnvrco01<\/code>.  That information is incredibly useful when working with dozens (or more) links.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re familiar with configuring network gear, you know that a very useful best practice is providing &#8220;plain English&#8221; descriptions of your device&#8217;s ports. For example, on my Cisco SF500-48MP switch port 24 is the &#8220;uplink port&#8221; to the gateway router. I make this clear in the port&#8217;s description: [code lang=text] sw01#show interfaces description fa1\/2\/24 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3856,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92],"tags":[95],"class_list":["post-3859","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-networking","tag-openwrt-snmpd-configuration"],"_links":{"self":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/3859"}],"collection":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/comments?post=3859"}],"version-history":[{"count":8,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/3859\/revisions"}],"predecessor-version":[{"id":3869,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/3859\/revisions\/3869"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media\/3856"}],"wp:attachment":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media?parent=3859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/categories?post=3859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/tags?post=3859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}