- Purpose. SNMP is a protocol for getting the status (e.g., CPU load, free memory, network load) of computing devices such as routers, switches and even servers.
- Object descriptor, managed object. The client can provide a globally unique names such as cpmCPUTotal5secRev (the average CPU load of a Cisco device for the past 5 seconds) to indicate the information that it wants, then the server should return such information. Such a textual name is called the “object descriptor”. The word “object” or “managed object” refers to the concept of CPU load. The actual CPU load in the device is called the “object instance”.
- Object identifier (OID). To make sure that each object descriptor is unique, actually it is defined using a list of integers such as 184.108.40.206.220.127.116.11.18.104.22.168.1.6. Each integer is like a package in Java. For example, the integers in 22.214.171.124.4.1.9 represents iso (1), org (3), dod, i.e., department of defense (6), internet (1), private (4), enterprises (1), cisco (9) respectively. This allows the Internet authority to delegate the management of the namespace hierarchically: to private enterprises and then to Cisco, which can further delegate to its various divisions or product categories. Such a list of integers is called an “object identifier”. This is the ultimate identification for the managed object.
- Even though the object descriptor should be unique, it is useful to see the hierarchy. Therefore, usually the full list of object descriptors is displayed such as iso.org.dod.internet.private.enterprises.cisco…cpmCPUTotal5secRev.
- Why use integers instead of symbolic names? Probably to allow the network devices (with little RAM or CPU power) implementing SNMP to save space in processing. Symbolic names such as object descriptor can be used by human in commands, but in the protocol’s operation it is done using object identifier.
- In principle, the object a.b.c.d and the object a.b.c.d.e on a device have NO containment relationship. That is, they are NOT like a Java object containing a child object. In fact, the value of each object in SNMP is basically a simple value (scalar) such as an integer or a string. The only relationship between them is their names.
- Identifying an instance. Now comes the most complicated concept in SNMP. Consider the concept of the number of bytes that have been received by a network interface on a router. This concept is an object. As a router should have multiple interfaces, there must be multiple instances of that object. Then, how can an SNMP client indicate to the SNMP server which instance it is interested in? The solution is more or less a kludge: to allow the instance of, say, a.b.c.d, to represent a table (a compound, structural value), which contains rows (also compound, structural value) represented by a.b.c.d.e. Each row contains child object instances (with scalar values only). Each child object is called a “columnar object”. For example, each row may contain three object instances: a.b.c.d.e.f, a.b.c.d.e.g, and a.b.c.d.e.idx. If you’d like to refer to the a.b.c.d.e.f instance in a particular row, you will write a.b.c.d.e.f.<index>. The meaning of the index is defined by a.b.c.d.e (the row). For example, it may be defined as finding the row in the table which contains a columnar object a.b.c.d.e.idx whose value equals to <index>, then return the columnar object a.b.c.d.e.f as the result.
- Note that this is the only situation where the value of an object can be a structure and that there is object containment relationship in SNMP.
- What is confusing is that a.b.c.d.e.f is used both as an object identifier and the lookup key to find the child instance in the row. Unlike other object identifiers, the identifier now represents an object containment relationship so it must have a.b.c.d.e as the prefix, otherwise the server won’t know which table to look into and what is the definition for the index.
- The complete identifier a.b.c.d.e.f.<index> is called an instance identifier.
- Here is a concrete example: Consider iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifInOctets.1. The definition of iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry says that to find the row in the table, it should search for a row which contains a child object iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifIndex with the value of 1 (the index specified), then it will return the value of child object iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifInOctets in the row. Of course, for this to work, the iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifIndex child object in each row must have been assigned with sequential values 1, 2, …, etc. (which is indeed the case).
- Finally, a simple case is that there is no table at all. For example, to find the up time of the device, use the object identifier iso.org.dod.internet.mgmt.mib-2.host.hrSystem.hrSystemUptime and append a .0 as the index, so the instance identifier is iso.org.dod.internet.mgmt.mib-2.host.hrSystem.hrSystemUptime.0. BTW, “hr” stands for “host resources”.
- MIB (management information base). A MIB is just a a collection of managed objects (not instances). There are standard MIBs so that device manufacturers can implement and users can find the right object identifiers to use. There are also proprietary MIBs such as those designed by Cisco to provide information only available on its devices.
- Finding the supported OIDs. How can you find out the MIBs or the object identifiers supported by a device? It is easier to just “walk the MIB tree”: to show all the instances in the tree or in a subtree. On Linux, this is done as below. You specify the IP or hostname of the server and optionally specify a node so that only that subtree is displayed (the object identifier starts with a dot, otherwise it will be assumed it is relative to iso.org.dod.internet.mgmt.mib-2):
# snmpwalk <some args> localhost # snmpwalk <some args> localhost .iso.org.dod.internet.mgmt.mib-2.system # snmpwalk <some args> localhost system
- Getting an instance. Just specify the instance identifier:
# snmpget <some args> localhost .iso.org.dod.internet.mgmt.mib-2.host.hrSystem.hrSystemUptime.0 # snmpget <some args> localhost host.hrSystem.hrSystemUptime.0
- SNMP enttiy, engine and applications. SNMP is a peer to peer protocol. There is no concept of a server and a client (these terms are used here for simplicity). Instead, both peers have the same core capabilities such as sending or receiving SNMP messages, performing security processing (see below), integrating v1, v2c and v3 processing (dispatching) and etc. This part is called the SNMP engine. On top of the engine, there are different “applications”: one application may only respond to requests for object instances (called SNMP agent in v1 and v2), another application may probe others (called SNMP manager in v1 and v2), yet another may forward SNMP messages (SNMP proxy). The whole server or client is called the “SNMP entity”.
- Context. On some devices there are multiple copies of a complete MIB subtree. For example, a physical router may support the concept of virtual routers. Each such virtual router will have a complete MIB subtree of instances. In that case, each virtual router may be indicated as a “context” in the SNMP server. A context is identified by name. For example, a virtual router could be identified as the “vr1” context. There is a default context with empty string (“”) as its name. When a client sends a query, it can specify a context name. If not, it will query the default context.
- Notification (trap). An SNMP server may actively send a notification to the client when some condition occurs. This is very much like a response without a request. Otherwise, everything is similar. The condition (e..g., the changes of the value of an instance or its going out of a range), the destination, the credentials used (see the security section below) and etc. are configured on the server.
- Transport binding. Typically SNMP runs on UDP port 161.
- SNMP v1 and v2c security. In SNMP v1 and v2c (v2 was not widely adopted), there is little security. The only security is the “community string”. That is, the server is configured to be in a community identify by a string such as “foo”, “public” (commonly used and the default for many devices to mean no protection) or “private”. If the client can quote the community strnig, then it is allowed access. As the community string is included as plain text in SNMP packets, it practically provides no security. Therefore, in v1 and v2c, to access an SNMP server, you will do something like:
# snmpwalk -v 2c -c public localhost # snmpget -v 2c -c public localhost <INSTANCE ID>
- SNMP v3 security. In SNMP v3, there is user-based security. That is, the client may be required to authenticate the messages to the server as originating from a user using a password (authentication password). In addition, the client may be furthered required to encrypt the messages using another password (privacy password). This security requirement is called the “security level” (no authentication needed, authentication but no privacy, authentication with privacy). Therefore, in v3, you will access the server like:
# snmpwalk -v 3 -l noAuthNoPriv localhost # snmpwalk -v 3 -l authNoPriv -u kent -A "my auth passwd" localhost # snmpwalk -v 3 -l authPriv -u kent -A "my auth passwd" -X "my priv passwd" localhost
- Client configuration file. To save typing all those every time, you can store these parameters into the snmp.conf file as defaults.
- Security limitation. It is a bad idea to specify the password on the command line as it can be revealed by local users using “ps”. Storing it into the configuration file is better. However, the file only allows a single authentication password and a single privacy password, not enough to handle the case of using different passwords for different servers.
- Security name. A security name is just a user name. No more, no less. That’s the term used in the RFC (maybe in the future it could be something else?)
- Algorithm. Further, there are different algorithms for authentication (HMAC using MD5 or SHA) and for privacy (encryption using DES or AES). So, you need to specify the algorithms to use:
# snmpwalk -v 3 -l noAuthNoPriv localhost # snmpwalk -v 3 -l authNoPriv -u kent -a MD5 -A "my auth passwd" localhost # snmpwalk -v 3 -l authPriv -u kent -a MD5 -A "my auth passwd" -x DES -X "my priv passwd" localhost
- Ensure the algorithms match. As SNMP uses UDP and each query and response may use just a single UDP packet, there is no negotiation of algorithm at “connection phase” at all. In fact, presumably for simplicity in implementation, the algorithms used are not even indicated in the message, so the client must use the agreed-on algorithms as configured in the user account on the server, otherwise the server will simply fail to authenticate or decrypt the message.
- Localized keys. The authentication password and privacy password of a user account are not used directly. The idea is, most likely you will use the same password for all the user account on all devices on site. If it is directly used, then a hacker controlling one device will be able to find the password and use it to access all the other devices. Therefore, when creating a user account, you specify the password, but the Linux SNMP server will combine it with a unique ID (called the “engine ID”) generated for the device (such as the MAC or IP and/or a random number generated and stored on installation), hash it and use the result as the password (the “localized key”). This way, even if the hacker can find this localized key, he will still be unable to find the original password.
- But how can a client generate the same key? It has to retrieve the engine ID first and then perform the same hashing. This is supported by the SNMP protocol.
- User accounts creation. Due to the need to generate localized keys, the way to create user accounts on Linux is quite weird. You stop the server, specify the user account’s name and password in a file, then start the server. It will read the password, convert it to a localized key and overwrite the file. This file is /var/lib/snmp/snmpd.conf on Linux:
createUser kent MD5 "my auth password" DES "my privacy password" createUser paul SHA "my auth password, no encryption needed"
- Access control. The access control can specify the user account, the lowest security level required, which part of the MIB tree is accessed (may use an OID to identify a subtree), the type of access (read or write), in order to grant the access. Here are some example settings on Linux (although human user names are used, but in practice they should be representing devices):
rouser john noauth .iso.org.dod.internet.mgmt.mib-2.system rouser kent priv .iso.org.dod.internet.mgmt.mib-2.system rouser kent auth .iso.org.dod.internet.mgmt.mib-2 rwuser paul priv
- View. How to specify several subtrees in an access control rule? You can define a view. A view has a name and is defined as including some subtrees and excluding some subtree. Then you can refer to it by name in access control:
view myview included .iso.org.dod.internet.mgmt.mib-2.system view myview included .iso.org.dod.internet.mgmt.mib-2.host view myview excluded .iso.org.dod.internet.mgmt.mib-2.host.hrStorage rwuser paul priv -V myview
- Access control for v1 and v2c. For v1 and v2c, access control can specify the community string, the IP range of the client (the “source”), the subtree (OID) or the view:
rocommunity public 192.168.1.0/24 .iso.org.dod.internet.mgmt.mib-2.system rwcommunity private localhost -V myview
- Most flexible access control model. The above access control model is called the “traditional model”. The new, most flexible access control model is called the “view-based access control model (VACM)”, even though the former can also use views. It may be more suitable to called it group-based access control as it uses user groups in the rules (NOT the precise syntax yet!):
group g1 kent group g1 paul #access <group> <context> <min sec level> <exact context?> <view for read> <view for write> <view for notify> access g1 "" auth exact myview1 myview2 myview3
- Mapping community string to user name. When using the VACM, instead of granting access to community strings, you need to merge v1 and v2c into the user-based access control processing. To do that, a community string along with the source can be mapped to a user name (the user name mapped to do NOT have to be existing):
com2sec user1 192.168.1.0/24 public # "default" source means any com2sec user2 default private
- Security model. Even though the different types of identity in the different SNMP versions are represented uniformly as a user name, their trustworthiness is still significantly different. So, in specifying group memberships and access control rules, you are required to specify the “security model” (v1, v2c or the user security model as in v3) and that’s the correct syntax:
group g1 usm kent group g1 usm paul group g2 v2c user1 group g2 v1 user1 group g2 v1 user2 access g1 "" usm auth exact myview1 myview2 myview3 access g2 "" any noauth exact myview4 myview5 myview6