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