| 1 | SNMP exercises, part I |
|---|
| 2 | ====================== |
|---|
| 3 | |
|---|
| 4 | Note: many of the commands in this exercise do not have to be run as root, |
|---|
| 5 | but it is safe to run them all as root. So it's simpler if you start a |
|---|
| 6 | root shell and enter them all there. You can start a root shell like this: |
|---|
| 7 | |
|---|
| 8 | $ sudo bash |
|---|
| 9 | |
|---|
| 10 | 0. Installing client tools |
|---|
| 11 | -------------------------- |
|---|
| 12 | |
|---|
| 13 | # apt-get install snmp |
|---|
| 14 | # apt-get install snmp-mibs-downloader |
|---|
| 15 | |
|---|
| 16 | The second of the two commands downloads the standard IETF and IANA |
|---|
| 17 | SNMP MIBs which are not included by default. |
|---|
| 18 | |
|---|
| 19 | Note: for this to work, you must enable the "multiverse" source in your |
|---|
| 20 | APT configuration, if you are using Ubuntu 12.04. This has already been |
|---|
| 21 | done for you here. |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | Now, edit the file /etc/snmp/snmp.conf |
|---|
| 25 | |
|---|
| 26 | Change this line: |
|---|
| 27 | |
|---|
| 28 | mibs : |
|---|
| 29 | |
|---|
| 30 | ... so that it looks like: |
|---|
| 31 | |
|---|
| 32 | # mibs : |
|---|
| 33 | |
|---|
| 34 | (You are "commenting out" the mibs statement, which is telling the |
|---|
| 35 | snmp* tools to automatically load the mibs downloaded into the |
|---|
| 36 | /usr/share/mibs/ directory). |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | 1. Configure SNMP on Your Router |
|---|
| 40 | -------------------------------- |
|---|
| 41 | |
|---|
| 42 | For this exercise you need to work in groups. Assign one person to type on |
|---|
| 43 | the keyboard. |
|---|
| 44 | |
|---|
| 45 | If you are unsure of what group you are in refer to the Network Diagram on the |
|---|
| 46 | classroom wiki by going to http://noc.ws.nsrc.org/ and clicking on the Network |
|---|
| 47 | Diagram link. |
|---|
| 48 | |
|---|
| 49 | Now connect to your router: |
|---|
| 50 | |
|---|
| 51 | $ ssh cisco@rtrN.ws.nsrc.org (or "ssh cisco@10.10.N.254") |
|---|
| 52 | |
|---|
| 53 | username: cisco |
|---|
| 54 | password: <CLASS PASSWORD> |
|---|
| 55 | |
|---|
| 56 | rtrN> enable |
|---|
| 57 | Password: <CLASS PASSWORD> |
|---|
| 58 | rtrN# configure terminal (conf t) |
|---|
| 59 | |
|---|
| 60 | Now we need to add an Access Control List rule for SNMP access, turn on SNMP, assign |
|---|
| 61 | a read-only SNMP community string and tell the router to maintain SNMP information |
|---|
| 62 | across reboots. To do this we do: |
|---|
| 63 | |
|---|
| 64 | rtrN(config)# access-list 99 permit 10.10.0.0 0.0.255.255 |
|---|
| 65 | rtrN(config)# snmp-server community NetManage ro 99 |
|---|
| 66 | rtrN(config)# snmp-server ifindex persist |
|---|
| 67 | |
|---|
| 68 | Now let's exit and save this new configuration to the routers permanent config. |
|---|
| 69 | |
|---|
| 70 | rtrN(config)# exit |
|---|
| 71 | rtrN# write memory (wr mem) |
|---|
| 72 | rtrN# exit (until you return to your pc) |
|---|
| 73 | |
|---|
| 74 | Now to see if your changes are working. |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | 2. Testing SNMP |
|---|
| 78 | --------------- |
|---|
| 79 | |
|---|
| 80 | To control that your SNMP installation works, run the |
|---|
| 81 | snmpstatus command on each of the following devices |
|---|
| 82 | |
|---|
| 83 | $ snmpstatus -c 'NetManage' -v2c <IP_ADDRESS> |
|---|
| 84 | |
|---|
| 85 | Where <IP_ADDRESS> is each of the following: |
|---|
| 86 | |
|---|
| 87 | * The NOC server: 10.10.0.254 |
|---|
| 88 | * Your group's router: 10.10.N.254 |
|---|
| 89 | * The access point: 10.10.0.251 |
|---|
| 90 | |
|---|
| 91 | What happens if you try using the wrong community string (i.e. change |
|---|
| 92 | 'NetManage' to something else?) |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | 3. SNMP Walk and OIDs |
|---|
| 96 | --------------------- |
|---|
| 97 | |
|---|
| 98 | Now, you are going to use the 'snmpwalk' command, part of the |
|---|
| 99 | SNMP toolkit, to list the tables associated with the OIDs listed |
|---|
| 100 | below, on each piece of equipment you tried above: |
|---|
| 101 | |
|---|
| 102 | .1.3.6.1.2.1.2.2.1.2 |
|---|
| 103 | .1.3.6.1.2.1.31.1.1.1.18 |
|---|
| 104 | .1.3.6.1.4.1.9.9.13.1 |
|---|
| 105 | .1.3.6.1.2.1.25.2.3.1 |
|---|
| 106 | .1.3.6.1.2.1.25.4.2.1 |
|---|
| 107 | |
|---|
| 108 | You will try this with two forms of the 'snmpwalk' command: |
|---|
| 109 | |
|---|
| 110 | $ snmpwalk -c 'NetManage' -v2c <IP_ADDRESS> <OID> |
|---|
| 111 | |
|---|
| 112 | and |
|---|
| 113 | |
|---|
| 114 | $ snmpwalk -On -c 'NetManage' -v2c <IP_ADDRESS> <OID> |
|---|
| 115 | |
|---|
| 116 | ... where OID is one of the OIDs listed above: .1.3.6... |
|---|
| 117 | |
|---|
| 118 | ...where IP_ADDRESS can be your group's router... |
|---|
| 119 | |
|---|
| 120 | Note: the "-On" option turns on numerical output, i.e.: no translation |
|---|
| 121 | of the OID <-> MIB object takes place. |
|---|
| 122 | |
|---|
| 123 | For these OIDs: |
|---|
| 124 | |
|---|
| 125 | a) Do all the devices answer ? |
|---|
| 126 | b) Do you notice anything important about the OID on the output ? |
|---|
| 127 | |
|---|
| 128 | 4. Configuration of snmpd on your PC |
|---|
| 129 | ------------------------------------- |
|---|
| 130 | |
|---|
| 131 | For this exercise your group needs to verify that the snmpd service is running and |
|---|
| 132 | responding to queries for all machines in your group. First enable snmpd on your machine, |
|---|
| 133 | then test if your machine is responding, then check each machine of your other group |
|---|
| 134 | members. |
|---|
| 135 | |
|---|
| 136 | * Install the SNMP agent (daemon) |
|---|
| 137 | |
|---|
| 138 | # apt-get install snmpd |
|---|
| 139 | |
|---|
| 140 | * Configuration. |
|---|
| 141 | |
|---|
| 142 | We will make a backup of the distributed config, and then we will |
|---|
| 143 | create our own: |
|---|
| 144 | |
|---|
| 145 | # cd /etc/snmp |
|---|
| 146 | # mv snmpd.conf snmpd.conf.dist |
|---|
| 147 | # editor snmpd.conf |
|---|
| 148 | |
|---|
| 149 | Then, copy/paste the following (do not include the -- cut here -- lines) |
|---|
| 150 | |
|---|
| 151 | -- cut here ------------------------- |
|---|
| 152 | |
|---|
| 153 | # Listen for connections on all interfaces (both IPv4 *and* IPv6) |
|---|
| 154 | agentAddress udp:161,udp6:[::1]:161 |
|---|
| 155 | |
|---|
| 156 | # Configure Read-Only community and restrict who can connect |
|---|
| 157 | rocommunity NetManage 10.10.0.0/16 |
|---|
| 158 | rocommunity NetManage 127.0.0.1 |
|---|
| 159 | |
|---|
| 160 | # Information about this host |
|---|
| 161 | sysLocation NSRC Network Management Workshop |
|---|
| 162 | sysContact sysadm@pcX.ws.nsrc.org |
|---|
| 163 | |
|---|
| 164 | # Which OSI layers are active in this host |
|---|
| 165 | # (Application + End-to-End layers) |
|---|
| 166 | sysServices 72 |
|---|
| 167 | |
|---|
| 168 | -- cut here ------------------------- |
|---|
| 169 | |
|---|
| 170 | Now save and exit from the editor. |
|---|
| 171 | |
|---|
| 172 | * Restart snmpd |
|---|
| 173 | |
|---|
| 174 | # service snmpd restart |
|---|
| 175 | |
|---|
| 176 | 5. Check that snmpd is working: |
|---|
| 177 | ------------------------------- |
|---|
| 178 | |
|---|
| 179 | $ snmpstatus -c 'NetManage' -v2c localhost |
|---|
| 180 | |
|---|
| 181 | What do you observe ? |
|---|
| 182 | |
|---|
| 183 | 6. Test your neighbors |
|---|
| 184 | ---------------------- |
|---|
| 185 | |
|---|
| 186 | Check now that you can run snmpstatus against your other group members servers: |
|---|
| 187 | |
|---|
| 188 | $ snmpstatus -c 'NetManage' -v2c pcN.ws.nsrc.org |
|---|
| 189 | |
|---|
| 190 | For instance, in group 4, you should verify against: |
|---|
| 191 | |
|---|
| 192 | pc17.ws.nsrc.org |
|---|
| 193 | pc18.ws.nsrc.org |
|---|
| 194 | pc19.ws.nsrc.org |
|---|
| 195 | pc20.ws.nsrc.org |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | 7. Adding MIBs |
|---|
| 199 | -------------- |
|---|
| 200 | |
|---|
| 201 | Remember when you ran: |
|---|
| 202 | |
|---|
| 203 | $ snmpwalk -c 'NetManage' -v2c 10.10.X.254 .1.3.6.1.4.1.9.9.13.1 |
|---|
| 204 | |
|---|
| 205 | If you noticed, the SNMP client (snmpwalk) couldn't interpret |
|---|
| 206 | all the OIDs coming back from the Agent: |
|---|
| 207 | |
|---|
| 208 | SNMPv2-SMI::enterprises.9.9.13.1.3.1.2.1 = STRING: "chassis" |
|---|
| 209 | SNMPv2-SMI::enterprises.9.9.13.1.3.1.6.1 = INTEGER: 1 |
|---|
| 210 | |
|---|
| 211 | What is '9.9.13.1.3.1' ? |
|---|
| 212 | |
|---|
| 213 | To be able to interpret this information, we need to download extra MIBs: |
|---|
| 214 | |
|---|
| 215 | * We will use the following MIBs (Don't download them yet!): |
|---|
| 216 | |
|---|
| 217 | CISCO MIBS: |
|---|
| 218 | |
|---|
| 219 | ftp://ftp.cisco.com/pub/mibs/v2/CISCO-SMI.my |
|---|
| 220 | ftp://ftp.cisco.com/pub/mibs/v2/CISCO-ENVMON-MIB.my |
|---|
| 221 | |
|---|
| 222 | To make it easier, we have a local mirror on http://noc.ws.nsrc.org/mibs/ |
|---|
| 223 | |
|---|
| 224 | # apt-get install wget |
|---|
| 225 | # cd /usr/share/mibs |
|---|
| 226 | # mkdir cisco && cd cisco |
|---|
| 227 | |
|---|
| 228 | # wget http://noc.ws.nsrc.org/mibs/CISCO-ENVMON-MIB.my |
|---|
| 229 | # wget http://noc.ws.nsrc.org/mibs/CISCO-SMI.my |
|---|
| 230 | |
|---|
| 231 | Now we need to tell the snmp tools that we have the cisco MIBS it |
|---|
| 232 | should load. So edit the file /etc/snmp/snmp.conf, and add the |
|---|
| 233 | following two lines: |
|---|
| 234 | |
|---|
| 235 | mibdirs +/usr/share/mibs/cisco |
|---|
| 236 | mibs +CISCO-ENVMON-MIB:CISCO-SMI |
|---|
| 237 | |
|---|
| 238 | * Save the file, quit. |
|---|
| 239 | |
|---|
| 240 | Now, try again: |
|---|
| 241 | |
|---|
| 242 | $ snmpwalk -c 'NetManage' -v2c 10.10.X.254 .1.3.6.1.4.1.9.9.13.1 |
|---|
| 243 | |
|---|
| 244 | What do you notice ? |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | 8. SNMPwalk - the rest of MIB-II |
|---|
| 248 | -------------------------------- |
|---|
| 249 | |
|---|
| 250 | Try and run snmpwalk on any hosts (routers, switches, machines) you |
|---|
| 251 | have not tried yet, in the 10.10.0.X network |
|---|
| 252 | |
|---|
| 253 | Note the kind of information you can obtain. |
|---|
| 254 | |
|---|
| 255 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifDescr |
|---|
| 256 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifTable |
|---|
| 257 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifAlias |
|---|
| 258 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifOperStatus |
|---|
| 259 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifAdminStatus |
|---|
| 260 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X if |
|---|
| 261 | |
|---|
| 262 | What do you think might be the difference between ifOperStatus and |
|---|
| 263 | ifAdminStatus? |
|---|
| 264 | |
|---|
| 265 | Can you imagine a scenario where this could be useful ? |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | 9. More MIB-OID fun |
|---|
| 269 | -------------------- |
|---|
| 270 | |
|---|
| 271 | * Use SNMP to examine: |
|---|
| 272 | |
|---|
| 273 | a) the running processes on your neighbor's server (hrSWRun) |
|---|
| 274 | b) the amount of free diskspace on your neighbor's server (hrStorage) |
|---|
| 275 | c) the interfaces on your neighbor's server (ifIndex, ifDescr) |
|---|
| 276 | |
|---|
| 277 | Can you use short names to walk these OID tables ? |
|---|
| 278 | |
|---|
| 279 | * Experiment with the "snmptranslate" command, example: |
|---|
| 280 | |
|---|
| 281 | $ snmptranslate .1.3.6.1.4.1.9.9.13.1 |
|---|
| 282 | |
|---|
| 283 | * Try with various OIDs |
|---|