| 1 | Network Management & Monitoring |
|---|
| 2 | |
|---|
| 3 | Using RANCID |
|---|
| 4 | ============ |
|---|
| 5 | |
|---|
| 6 | Notes: |
|---|
| 7 | ------ |
|---|
| 8 | * Commands preceded with "$" imply that you should execute the command as |
|---|
| 9 | a general user - not as root. |
|---|
| 10 | * Commands preceded with "#" imply that you should be working as root. |
|---|
| 11 | * Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>") |
|---|
| 12 | imply that you are executing commands on remote equipment, or within |
|---|
| 13 | another program. |
|---|
| 14 | |
|---|
| 15 | Exercises |
|---|
| 16 | --------- |
|---|
| 17 | |
|---|
| 18 | 1. Connect to your PC using ssh |
|---|
| 19 | |
|---|
| 20 | 2. Become root, and install postfix (mail system we are using) |
|---|
| 21 | |
|---|
| 22 | $ sudo bash |
|---|
| 23 | # apt-get install postfix |
|---|
| 24 | You might get a prompt on Postfix install, select "Internet Site" |
|---|
| 25 | At the next prompt, enter your hostname (e.g. pcxx.ws.nsrc.org) |
|---|
| 26 | # service postfix status |
|---|
| 27 | |
|---|
| 28 | Also check that the 'mutt' mail client is installed, as well as telnet |
|---|
| 29 | and subversion: |
|---|
| 30 | |
|---|
| 31 | # apt-get install mutt telnet subversion |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | 3. Add an alias for the rancid user in /etc/aliases file |
|---|
| 35 | |
|---|
| 36 | # editor /etc/aliases |
|---|
| 37 | |
|---|
| 38 | rancid-all: sysadm |
|---|
| 39 | rancid-admin-all: sysadm |
|---|
| 40 | |
|---|
| 41 | Save the file, then run: |
|---|
| 42 | |
|---|
| 43 | # newaliases |
|---|
| 44 | |
|---|
| 45 | 4. Install Rancid itself |
|---|
| 46 | |
|---|
| 47 | # apt-get install rancid |
|---|
| 48 | |
|---|
| 49 | It will prompt for warning, and Really continue? Select Yes |
|---|
| 50 | |
|---|
| 51 | 5. Edit /etc/rancid/rancid.conf |
|---|
| 52 | |
|---|
| 53 | # editor /etc/rancid/rancid.conf |
|---|
| 54 | |
|---|
| 55 | Find this line in rancid.conf: |
|---|
| 56 | |
|---|
| 57 | #LIST_OF_GROUPS="sl joebobisp" |
|---|
| 58 | |
|---|
| 59 | And, underneath it add the following line: |
|---|
| 60 | |
|---|
| 61 | LIST_OF_GROUPS="all" |
|---|
| 62 | |
|---|
| 63 | (with no '#' at the front of line) |
|---|
| 64 | |
|---|
| 65 | Also, we want to use Subversion, and not CVS: |
|---|
| 66 | |
|---|
| 67 | Find the line with the parameter RCSSYS, and change it to: |
|---|
| 68 | |
|---|
| 69 | RCSSYS=svn; export RCSSYS |
|---|
| 70 | |
|---|
| 71 | and the line with CVSROOT: |
|---|
| 72 | |
|---|
| 73 | CVSROOT=$BASEDIR/svn; export CSVROOT |
|---|
| 74 | |
|---|
| 75 | 6. Change to the rancid user |
|---|
| 76 | |
|---|
| 77 | From a root prompt, switch identity to become the 'rancid' user: |
|---|
| 78 | |
|---|
| 79 | # su -s /bin/bash rancid |
|---|
| 80 | |
|---|
| 81 | Check that you ARE the rancid user: |
|---|
| 82 | |
|---|
| 83 | $ id |
|---|
| 84 | |
|---|
| 85 | You should see something similar (numbers may be different): |
|---|
| 86 | |
|---|
| 87 | uid=104(rancid) gid=109(rancid) groups=109(rancid) |
|---|
| 88 | |
|---|
| 89 | ***** IF YOU ARE NOT USER RANCID NOW, do NOT continue ****** |
|---|
| 90 | |
|---|
| 91 | 7. Create /var/lib/rancid/.cloginrc |
|---|
| 92 | |
|---|
| 93 | $ editor /var/lib/rancid/.cloginrc |
|---|
| 94 | |
|---|
| 95 | add user 10.10.* cisco |
|---|
| 96 | add password 10.10.* cisco cisco |
|---|
| 97 | |
|---|
| 98 | (The first 'cisco' is the username, the first and second 'cisco' are the |
|---|
| 99 | password and enable password used to login to your router. The star in |
|---|
| 100 | the IP means that it will try to use this username and password for all |
|---|
| 101 | routers in 10.10. network) |
|---|
| 102 | |
|---|
| 103 | Now protect this file so that it cannot be read by other users: |
|---|
| 104 | |
|---|
| 105 | $ chmod 600 /var/lib/rancid/.cloginrc |
|---|
| 106 | |
|---|
| 107 | In reality you want to create an extra user for RANCID on the Cisco |
|---|
| 108 | with limited rights instead. |
|---|
| 109 | |
|---|
| 110 | 8. Test login to the router of your group |
|---|
| 111 | |
|---|
| 112 | Login to your router with clogin. You might have to type yes to the first |
|---|
| 113 | warning, but should not need to enter a password, this should be |
|---|
| 114 | automatic. |
|---|
| 115 | |
|---|
| 116 | $ /var/lib/rancid/bin/clogin 10.10.0.X |
|---|
| 117 | (replace x with your group no.) |
|---|
| 118 | You should get something like: |
|---|
| 119 | spawn ssh -c 3des -x -l cisco 10.10.0.X |
|---|
| 120 | The authenticity of host '10.10.0.X (10.10.0.X)' can't be established. |
|---|
| 121 | RSA key fingerprint is 73:f3:f0:e8:78:ab:49:1c:d9:5d:49:01:a4:e1:2a:83. |
|---|
| 122 | Are you sure you want to continue connecting (yes/no)? |
|---|
| 123 | Host 10.10.0.X added to the list of known hosts. |
|---|
| 124 | yes |
|---|
| 125 | Warning: Permanently added '10.10.0.X' (RSA) to the list of known hosts. |
|---|
| 126 | Password: |
|---|
| 127 | |
|---|
| 128 | rtr2>enable |
|---|
| 129 | Password: |
|---|
| 130 | rtr2# |
|---|
| 131 | |
|---|
| 132 | Exit the router |
|---|
| 133 | rtr2#exit |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | 9. Initialize the SVN repository for rancid: |
|---|
| 138 | |
|---|
| 139 | $ /usr/lib/rancid/bin/rancid-cvs |
|---|
| 140 | |
|---|
| 141 | You should see something similar to this: |
|---|
| 142 | |
|---|
| 143 | Committed revision 1. |
|---|
| 144 | Checked out revision 1. |
|---|
| 145 | At revision 1. |
|---|
| 146 | A configs |
|---|
| 147 | Adding configs |
|---|
| 148 | |
|---|
| 149 | Committed revision 2. |
|---|
| 150 | A router.db |
|---|
| 151 | Adding router.db |
|---|
| 152 | Transmitting file data . |
|---|
| 153 | Committed revision 3. |
|---|
| 154 | |
|---|
| 155 | ***** If you have problems ****** |
|---|
| 156 | |
|---|
| 157 | If this does not work, then either you are missing the subversion package, or |
|---|
| 158 | something was not properly configured during the previous steps. You should verify |
|---|
| 159 | that subversion is installed and then before running the rancid-cvs command again |
|---|
| 160 | do the following: |
|---|
| 161 | |
|---|
| 162 | $ exit |
|---|
| 163 | # apt-get install subversion |
|---|
| 164 | # su -s /bin/bash rancid |
|---|
| 165 | $ cd /var/lib/rancid |
|---|
| 166 | $ rm -rf all |
|---|
| 167 | $ rm -rf svn |
|---|
| 168 | |
|---|
| 169 | Now try running the rancid-cvs command again: |
|---|
| 170 | |
|---|
| 171 | $ /usr/lib/rancid/bin/rancid-cvs |
|---|
| 172 | |
|---|
| 173 | ******************************** |
|---|
| 174 | |
|---|
| 175 | 10. Create the router.db |
|---|
| 176 | |
|---|
| 177 | $ editor /var/lib/rancid/all/router.db |
|---|
| 178 | |
|---|
| 179 | Add this line: |
|---|
| 180 | |
|---|
| 181 | 10.10.0.xxx:cisco:up |
|---|
| 182 | |
|---|
| 183 | (remember to replace xxx as appropriate) |
|---|
| 184 | |
|---|
| 185 | 11. Let's run rancid! |
|---|
| 186 | |
|---|
| 187 | $ /usr/lib/rancid/bin/rancid-run |
|---|
| 188 | |
|---|
| 189 | (Should take about half a minute) |
|---|
| 190 | Run it again, since the first time it might not commit correctly: |
|---|
| 191 | |
|---|
| 192 | $ /usr/lib/rancid/bin/rancid-run |
|---|
| 193 | |
|---|
| 194 | 12. Check out the logs: |
|---|
| 195 | |
|---|
| 196 | $ cd /var/lib/rancid/logs |
|---|
| 197 | $ ls -l |
|---|
| 198 | |
|---|
| 199 | ... View the contents of the file(s): |
|---|
| 200 | |
|---|
| 201 | $ less all.* |
|---|
| 202 | |
|---|
| 203 | 13. Look at the configs |
|---|
| 204 | |
|---|
| 205 | $ cd /var/lib/rancid/all/configs |
|---|
| 206 | $ less 10.10.0.xxx |
|---|
| 207 | |
|---|
| 208 | If all went well, you can see the config of the router. |
|---|
| 209 | |
|---|
| 210 | 14. Let's change an interface Description on the router |
|---|
| 211 | |
|---|
| 212 | $ /usr/lib/rancid/bin/clogin 10.10.0.xxx |
|---|
| 213 | |
|---|
| 214 | At the "rtrX#" prompt, enter the command: |
|---|
| 215 | |
|---|
| 216 | rtrX# conf term |
|---|
| 217 | |
|---|
| 218 | You should see: |
|---|
| 219 | |
|---|
| 220 | Enter configuration commands, one per line. End with CNTL/Z. |
|---|
| 221 | rtrX(config)# |
|---|
| 222 | |
|---|
| 223 | Enter: |
|---|
| 224 | |
|---|
| 225 | rtrX(config)# interface LoopbackXX (replace XX with your PC no) |
|---|
| 226 | for example |
|---|
| 227 | rtr5(config)# interface Loopback17 (if your PC is number 17) |
|---|
| 228 | |
|---|
| 229 | You should get this prompt: |
|---|
| 230 | |
|---|
| 231 | rtr2(config-if)# |
|---|
| 232 | |
|---|
| 233 | Enter: |
|---|
| 234 | |
|---|
| 235 | rtr2(config-if)# description <put your name here> |
|---|
| 236 | rtr2(config-if)# end |
|---|
| 237 | |
|---|
| 238 | You should now have this prompt: |
|---|
| 239 | |
|---|
| 240 | rtr2# |
|---|
| 241 | |
|---|
| 242 | To save the config to memory: |
|---|
| 243 | |
|---|
| 244 | rtr2# write memory |
|---|
| 245 | |
|---|
| 246 | You should see: |
|---|
| 247 | |
|---|
| 248 | Building configuration... |
|---|
| 249 | [OK] |
|---|
| 250 | |
|---|
| 251 | To exit type: |
|---|
| 252 | |
|---|
| 253 | exit |
|---|
| 254 | |
|---|
| 255 | 15. Let's run rancid again: |
|---|
| 256 | |
|---|
| 257 | $ /usr/lib/rancid/bin/rancid-run |
|---|
| 258 | |
|---|
| 259 | Look at the config and logs |
|---|
| 260 | |
|---|
| 261 | $ ls /var/lib/rancid/logs/ |
|---|
| 262 | |
|---|
| 263 | 16. Let's see the differences |
|---|
| 264 | |
|---|
| 265 | $ cd /var/lib/rancid/all/configs |
|---|
| 266 | $ ls -l |
|---|
| 267 | |
|---|
| 268 | You should see all the router config files |
|---|
| 269 | |
|---|
| 270 | $ svn log 10.10.0.xxx |
|---|
| 271 | |
|---|
| 272 | (where xxx is the IP of your router, .201 - .210) |
|---|
| 273 | |
|---|
| 274 | Notice the revisions. Let's view the difference between two versions: |
|---|
| 275 | |
|---|
| 276 | $ svn diff -r 5:6 10.10.0.xxx | less |
|---|
| 277 | |
|---|
| 278 | ... can you find your changes ? Or those of others in the same time? |
|---|
| 279 | |
|---|
| 280 | 17. Check your mail |
|---|
| 281 | |
|---|
| 282 | Now we will exit from these shells to get back to being the "sysadm" |
|---|
| 283 | user, and run 'mutt' to see the mails which rancid has sent: |
|---|
| 284 | |
|---|
| 285 | $ exit |
|---|
| 286 | # exit |
|---|
| 287 | $ id |
|---|
| 288 | ... check that you are now the 'sysadm' user again; |
|---|
| 289 | ... if not, log out and in again |
|---|
| 290 | $ mutt |
|---|
| 291 | |
|---|
| 292 | (When asked to create the Mail directory, say Yes) |
|---|
| 293 | |
|---|
| 294 | If everything goes as planned, you should be able to read the mails |
|---|
| 295 | sent by Rancid. |
|---|
| 296 | |
|---|
| 297 | (use 'q' return to mail index, and 'q' again to quit mutt) |
|---|
| 298 | |
|---|
| 299 | 18. Let's make rancid run automatically every 30 minutes from cron |
|---|
| 300 | |
|---|
| 301 | $ sudo bash |
|---|
| 302 | # crontab -e -u rancid |
|---|
| 303 | |
|---|
| 304 | It will ask you for your favorite editor. |
|---|
| 305 | |
|---|
| 306 | Add this line: |
|---|
| 307 | |
|---|
| 308 | */30 * * * * /usr/lib/rancid/bin/rancid-run |
|---|
| 309 | |
|---|
| 310 | ... then save and quit |
|---|
| 311 | |
|---|
| 312 | 19. Now add all the other routers |
|---|
| 313 | Note the IP addresses for the routers |
|---|
| 314 | |
|---|
| 315 | 10.10.0.xxx where xxx is .201 - .210 |
|---|
| 316 | |
|---|
| 317 | Update the router.db |
|---|
| 318 | |
|---|
| 319 | # su -s /bin/bash rancid |
|---|
| 320 | $ editor /var/lib/rancid/all/router.db |
|---|
| 321 | |
|---|
| 322 | Add some other classroom routers to the file. You should end up with |
|---|
| 323 | something like: |
|---|
| 324 | |
|---|
| 325 | 10.10.0.201:cisco:up |
|---|
| 326 | 10.10.0.202:cisco:up |
|---|
| 327 | 10.10.0.203:cisco:up |
|---|
| 328 | 10.10.0.204:cisco:up |
|---|
| 329 | 10.10.0.205:cisco:up |
|---|
| 330 | 10.10.0.206:cisco:up |
|---|
| 331 | 10.10.0.207:cisco:up |
|---|
| 332 | 10.10.0.208:cisco:up |
|---|
| 333 | 10.10.0.209:cisco:up |
|---|
| 334 | 10.10.0.210:cisco:up |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | (Note that "cisco" means this is Cisco equipment -- it tells Rancid |
|---|
| 338 | that we are expecting to talk to a Cisco device here. You can also |
|---|
| 339 | talk to Juniper, HP, ...) |
|---|
| 340 | |
|---|
| 341 | 20. Run rancid again: |
|---|
| 342 | |
|---|
| 343 | $ /usr/lib/rancid/bin/rancid-run |
|---|
| 344 | |
|---|
| 345 | (Should take a minute or more now, be patient) |
|---|
| 346 | |
|---|
| 347 | 21. Check out the logs: |
|---|
| 348 | |
|---|
| 349 | $ cd /var/lib/rancid/logs |
|---|
| 350 | $ ls -l |
|---|
| 351 | |
|---|
| 352 | ... Pick the latest file and view it |
|---|
| 353 | |
|---|
| 354 | $ less all.YYYYMMDD.HHMMSS |
|---|
| 355 | |
|---|
| 356 | 22. Look at the configs |
|---|
| 357 | |
|---|
| 358 | $ cd /var/lib/rancid/all/configs |
|---|
| 359 | $ more 10.10.* |
|---|
| 360 | |
|---|
| 361 | If all went well, you can see the configs of ALL routers |
|---|
| 362 | |
|---|
| 363 | 23. Run RANCID again just in case someone changed some configuration on the router |
|---|
| 364 | |
|---|
| 365 | $ /usr/lib/rancid/bin/rancid-run |
|---|
| 366 | (patienceÉ) |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | 23. Play with clogin: |
|---|
| 370 | |
|---|
| 371 | $ /usr/lib/rancid/bin/clogin -c "show clock" 10.10.0.X |
|---|
| 372 | |
|---|
| 373 | What do you notice ? |
|---|
| 374 | |
|---|
| 375 | 24. Add the RANCID SVN repository in to SVNWeb |
|---|
| 376 | |
|---|
| 377 | If you are still logged in as user rancid, get back to root |
|---|
| 378 | |
|---|
| 379 | $ exit |
|---|
| 380 | # |
|---|
| 381 | |
|---|
| 382 | Install SVNWeb: |
|---|
| 383 | |
|---|
| 384 | # apt-get install websvn |
|---|
| 385 | * Say Yes to the question if you want to configure it now |
|---|
| 386 | * Hit Ok for the next question about supporting various web servers |
|---|
| 387 | * As directory add /var/lib/rancid/svn both times when asked on the next screens. |
|---|
| 388 | * Hit Ok for the next screen talking about permissions |
|---|
| 389 | |
|---|
| 390 | 25. Fix permissions. The web server must be able to read the SVN archive |
|---|
| 391 | # chgrp -R www-data /var/lib/rancid/svn |
|---|
| 392 | # chmod g+w -R /var/lib/rancid/svn |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | 26. Browse files from your webbrowser |
|---|
| 396 | http://pcXXX.ws.nsrc.org/websvn |
|---|
| 397 | |
|---|
| 398 | Browse the files under the 'all/configs' directory. |
|---|
| 399 | You can see all your router configuration files here. |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | 27. Review revisions |
|---|
| 404 | |
|---|
| 405 | If you want to see different revisions side by side, you can do that with WebSVN too. |
|---|
| 406 | |
|---|
| 407 | However diffs between revisions are broken in the package which comes with Ubuntu 10.04 LTS solved in the latest version |
|---|
| 408 | |
|---|
| 409 | Patch that bug with a simple patchfile: |
|---|
| 410 | |
|---|
| 411 | # apt-get install wget patch |
|---|
| 412 | # cd /usr/share/websvn/include |
|---|
| 413 | # wget http://noc.ws.nsrc.org/downloads/patch-svn |
|---|
| 414 | # patch < patch-svn |
|---|
| 415 | |
|---|
| 416 | You can now also browse difference between file revisions with WebSVN. |
|---|
| 417 | |
|---|
| 418 | Browse to http://pcXXX.ws.nsrc.org/websvn again, go to all, configs |
|---|
| 419 | Select your router file (10.10.0.X) and click "Compare with Previous" |
|---|
| 420 | You should now see the latest changes side by side. |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | +---- |
|---|
| 424 | Rev. 15 Nov 2011 |
|---|