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 backbone switch: 10.10.0.253 |
---|
90 | * The access points: 10.10.0.251, 10.10.0.252 |
---|
91 | |
---|
92 | What happens if you try using the wrong community string (i.e. change |
---|
93 | 'NetManage' to something else?) |
---|
94 | |
---|
95 | |
---|
96 | 3. SNMP Walk and OIDs |
---|
97 | --------------------- |
---|
98 | |
---|
99 | Now, you are going to use the 'snmpwalk' command, part of the |
---|
100 | SNMP toolkit, to list the tables associated with the OIDs listed |
---|
101 | below, on each piece of equipment you tried above: |
---|
102 | |
---|
103 | .1.3.6.1.2.1.2.2.1.2 |
---|
104 | .1.3.6.1.2.1.31.1.1.1.18 |
---|
105 | .1.3.6.1.4.1.9.9.13.1 |
---|
106 | .1.3.6.1.2.1.25.2.3.1 |
---|
107 | .1.3.6.1.2.1.25.4.2.1 |
---|
108 | |
---|
109 | You will try this with two forms of the 'snmpwalk' command: |
---|
110 | |
---|
111 | $ snmpwalk -c 'NetManage' -v2c <IP_ADDRESS> <OID> |
---|
112 | |
---|
113 | and |
---|
114 | |
---|
115 | $ snmpwalk -On -c 'NetManage' -v2c <IP_ADDRESS> <OID> |
---|
116 | |
---|
117 | ... where OID is one of the OIDs listed above: .1.3.6... |
---|
118 | |
---|
119 | ...where IP_ADDRESS can be your group's router... |
---|
120 | |
---|
121 | Note: the "-On" option turns on numerical output, i.e.: no translation |
---|
122 | of the OID <-> MIB object takes place. |
---|
123 | |
---|
124 | For these OIDs: |
---|
125 | |
---|
126 | a) Do all the devices answer ? |
---|
127 | b) Do you notice anything important about the OID on the output ? |
---|
128 | |
---|
129 | 4. Configuration of snmpd on your PC |
---|
130 | ------------------------------------- |
---|
131 | |
---|
132 | For this exercise your group needs to verify that the snmpd service is running and |
---|
133 | responding to queries for all machines in your group. First enable snmpd on your machine, |
---|
134 | then test if your machine is responding, then check each machine of your other group |
---|
135 | members. |
---|
136 | |
---|
137 | * Install the SNMP agent (daemon) |
---|
138 | |
---|
139 | # apt-get install snmpd |
---|
140 | |
---|
141 | * Configuration. |
---|
142 | |
---|
143 | We will make a backup of the distributed config, and then we will |
---|
144 | create our own: |
---|
145 | |
---|
146 | # cd /etc/snmp |
---|
147 | # mv snmpd.conf snmpd.conf.dist |
---|
148 | # editor snmpd.conf |
---|
149 | |
---|
150 | Then, copy/paste the following (do not include the -- cut here -- lines) |
---|
151 | |
---|
152 | -- cut here ------------------------- |
---|
153 | |
---|
154 | # Listen for connections on all interfaces (both IPv4 *and* IPv6) |
---|
155 | agentAddress udp:161,udp6:[::1]:161 |
---|
156 | |
---|
157 | # Configure Read-Only community and restrict who can connect |
---|
158 | rocommunity NetManage 10.10.0.0/16 |
---|
159 | rocommunity NetManage 127.0.0.1 |
---|
160 | |
---|
161 | # Information about this host |
---|
162 | sysLocation NSRC Network Management Workshop |
---|
163 | sysContact sysadm@pcX.ws.nsrc.org |
---|
164 | |
---|
165 | # Which OSI layers are active in this host |
---|
166 | # (Application + End-to-End layers) |
---|
167 | sysServices 72 |
---|
168 | |
---|
169 | -- cut here ------------------------- |
---|
170 | |
---|
171 | Now save and exit from the editor. |
---|
172 | |
---|
173 | * Restart snmpd |
---|
174 | |
---|
175 | # service snmpd restart |
---|
176 | |
---|
177 | 5. Check that snmpd is working: |
---|
178 | ------------------------------- |
---|
179 | |
---|
180 | $ snmpstatus -c 'NetManage' -v2c localhost |
---|
181 | |
---|
182 | What do you observe ? |
---|
183 | |
---|
184 | 6. Test your neighbors |
---|
185 | ---------------------- |
---|
186 | |
---|
187 | Check now that you can run snmpstatus against your other group members servers: |
---|
188 | |
---|
189 | $ snmpstatus -c 'NetManage' -v2c pcN.ws.nsrc.org |
---|
190 | |
---|
191 | For instance, in group 4, you should verify against: |
---|
192 | |
---|
193 | pc17.ws.nsrc.org |
---|
194 | pc18.ws.nsrc.org |
---|
195 | pc19.ws.nsrc.org |
---|
196 | pc20.ws.nsrc.org |
---|
197 | |
---|
198 | |
---|
199 | 7. Adding MIBs |
---|
200 | -------------- |
---|
201 | |
---|
202 | Remember when you ran: |
---|
203 | |
---|
204 | $ snmpwalk -c 'NetManage' -v2c 10.10.X.254 .1.3.6.1.4.1.9.9.13.1 |
---|
205 | |
---|
206 | If you noticed, the SNMP client (snmpwalk) couldn't interpret |
---|
207 | all the OIDs coming back from the Agent: |
---|
208 | |
---|
209 | SNMPv2-SMI::enterprises.9.9.13.1.3.1.2.1 = STRING: "chassis" |
---|
210 | SNMPv2-SMI::enterprises.9.9.13.1.3.1.6.1 = INTEGER: 1 |
---|
211 | |
---|
212 | What is '9.9.13.1.3.1' ? |
---|
213 | |
---|
214 | To be able to interpret this information, we need to download extra MIBs: |
---|
215 | |
---|
216 | * We will use the following MIBs (Don't download them yet!): |
---|
217 | |
---|
218 | CISCO MIBS: |
---|
219 | |
---|
220 | ftp://ftp.cisco.com/pub/mibs/v2/CISCO-SMI.my |
---|
221 | ftp://ftp.cisco.com/pub/mibs/v2/CISCO-ENVMON-MIB.my |
---|
222 | |
---|
223 | To make it easier, we have a local mirror on http://noc.ws.nsrc.org/mibs/ |
---|
224 | |
---|
225 | # apt-get install wget |
---|
226 | # cd /usr/share/mibs |
---|
227 | # mkdir cisco && cd cisco |
---|
228 | |
---|
229 | # wget http://noc.ws.nsrc.org/mibs/CISCO-ENVMON-MIB.my |
---|
230 | # wget http://noc.ws.nsrc.org/mibs/CISCO-SMI.my |
---|
231 | |
---|
232 | Now we need to tell the snmp tools that we have the cisco MIBS it |
---|
233 | should load. So edit the file /etc/snmp/snmp.conf, and add the |
---|
234 | following two lines: |
---|
235 | |
---|
236 | mibdirs +/usr/share/mibs/cisco |
---|
237 | mibs +CISCO-ENVMON-MIB:CISCO-SMI |
---|
238 | |
---|
239 | * Save the file, quit. |
---|
240 | |
---|
241 | Now, try again: |
---|
242 | |
---|
243 | $ snmpwalk -c 'NetManage' -v2c 10.10.X.254 .1.3.6.1.4.1.9.9.13.1 |
---|
244 | |
---|
245 | What do you notice ? |
---|
246 | |
---|
247 | |
---|
248 | 8. SNMPwalk - the rest of MIB-II |
---|
249 | -------------------------------- |
---|
250 | |
---|
251 | Try and run snmpwalk on any hosts (routers, switches, machines) you |
---|
252 | have not tried yet, in the 10.10.0.X network |
---|
253 | |
---|
254 | Note the kind of information you can obtain. |
---|
255 | |
---|
256 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifDescr |
---|
257 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifTable |
---|
258 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifAlias |
---|
259 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifOperStatus |
---|
260 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X ifAdminStatus |
---|
261 | $ snmpwalk -c 'NetManage' -v2c 10.10.0.X if |
---|
262 | |
---|
263 | What do you think might be the difference between ifOperStatus and |
---|
264 | ifAdminStatus? |
---|
265 | |
---|
266 | Can you imagine a scenario where this could be useful ? |
---|
267 | |
---|
268 | |
---|
269 | 9. More MIB-OID fun |
---|
270 | -------------------- |
---|
271 | |
---|
272 | * Use SNMP to examine: |
---|
273 | |
---|
274 | a) the running processes on your neighbor's server (hrSWRun) |
---|
275 | b) the amount of free diskspace on your neighbor's server (hrStorage) |
---|
276 | c) the interfaces on your neighbor's server (ifIndex, ifDescr) |
---|
277 | |
---|
278 | Can you use short names to walk these OID tables ? |
---|
279 | |
---|
280 | * Experiment with the "snmptranslate" command, example: |
---|
281 | |
---|
282 | $ snmptranslate .1.3.6.1.4.1.9.9.13.1 |
---|
283 | |
---|
284 | * Try with various OIDs |
---|