Macros Make Your Life Easier

Macros are sequences of commands stored on the device (router/switch/whatever) that automate common tasks.  The most common application of a macro is setting interface configurations in complex environments.  For example, imagine if you ran a single 6500 chassis with a few hundred interfaces, and your client was always changing the interface designation from these profiles: end user desktop, server, and IP phone.

Sure you could do this manually.  You could even have these various configurations as templates in a text file that you just paste in whenever you need it.  This totally works, and is pretty much how everybody does it.

There is another way, and it is called Macros.  A macro is just a series of configuration commands that are remembered by your device, and that you can apply when you need them.

The Macro Template

[code]]czo0OTU6XCJtYWNybyBuYW1lIHVudXNlZA0KbWFjcm8gZGVzY3JpcHRpb24gdW51c2VkDQpzaHV0ZG93bg0KZGVzY3JpcHRpb24gKip7WyYqJl19KiBVTlVTRUQgUG9ydCAqKioNCm5vIGlwIGFkZHJlc3MNCiMgU2V0IHNlY3VyZSBkZWZhdWx0cyBmb3IgYWNjZXNzIG1vZGUNCnN3aXtbJiomXX10Y2hwb3J0IG1vZGUgYWNjZXNzDQpzd2l0Y2hwb3J0IGFjY2VzcyB2bGFuIDk5OQ0Kc3dpdGNocG9ydCBub25lZ290aWF0ZQ0KIyBTe1smKiZdfWV0IHNlY3VyZSBkZWZhdWx0cyBmb3IgbWlzYy4gZmxhZ3MgYW5kIHByb3RvY29scw0Kbm8gYXV0byBxb3Mgdm9pcCB0cnVzdA0Kbm97WyYqJl19IGNkcCBlbmFibGUNCnBvd2VyIGlubGluZSBuZXZlcg0KIyBEZWZhdWx0IFNwYW5uaW5nLXRyZWUgdG8gc2VjdXJlIGhvc3Qgc2V0dHtbJiomXX1pbmdzDQpzcGFubmluZy10cmVlIHBvcnRmYXN0DQpzcGFubmluZy10cmVlIGJwZHVmaWx0ZXIgZW5hYmxlDQpzcGFubmluZy10cmVle1smKiZdfSBicGR1Z3VhcmQgZW5hYmxlDQpzcGFubmluZy10cmVlIGd1YXJkIHJvb3QNCkBcIjt7WyYqJl19[[/code]

This is an macro to represent the default configuration of an interface.  The objective here is to be able to use the UNUSED macro whenever an interface is to change its profile.

[code]]czoyMzQ6XCJtYWNybyBuYW1lIHNlcnZlcg0KbWFjcm8gZGVzY3JpcHRpb24gc2VydmVyIGludGVyZmFjZQ0KIyBBcHBseSBtYWNybyB7WyYqJl19XFxcJ3VudXNlZFxcXCcgZmlyc3QNCmRlc2NyaXB0aW9uIFNlcnZlcg0Kc3dpdGNocG9ydCBhY2Nlc3MgdmxhbiAyMDANCm5vIHNwYW5uaW57WyYqJl19Zy10cmVlIHBvcnRmYXN0DQpubyBzcGFubmluZy10cmVlIGJwZHVmaWx0ZXIgZW5hYmxlDQpubyBzcGFubmluZy10cmVlIGJwZHVndXtbJiomXX1hcmQgZW5hYmxlDQpAXCI7e1smKiZdfQ==[[/code]

This SERVER macro puts the server in the right VLAN, and also enables some STP functions that would otherwise have been disabled.  I always run STP facing servers — just in case somebody accidentally creates a switching loop within the server architecture.

[code]]czoyNTM6XCJtYWNybyBuYW1lIGRlc2t0b3BpcHBob25lDQptYWNybyBkZXNjcmlwdGlvbiBEZXNrdG9wICsgSVAgUGhvbmUgaW50ZXJ7WyYqJl19ZmFjZQ0KIyBBcHBseSBtYWNybyBcXFwndW51c2VkXFxcJyBmaXJzdA0KZGVzY3JpcHRpb24gRGVza3RvcCArIElQIFBob25lDQpzd2l0Y2h7WyYqJl19cG9ydCBhY2Nlc3MgdmxhbiAzMDANCnN3aXRjaHBvcnQgdm9pY2UgdmxhbiA0MDANCmNkcCBlbmFibGUNCmF1dG8gcW9zIHZvaXAgY3tbJiomXX1pc2NvLXBob25lDQpwb3dlciBpbmxpbmUgYXV0bw0KQFwiO3tbJiomXX0=[[/code]

This macro handles an interface that faces an IP phone with a desktop attached.  In this case we need to assign the voice and access VLANs, enable PoE, enable Auto QoS and enable CDP.  CDP allows Cisco phones to automatically trunk the VLANs, negotiate the required power levels, and tells the switch to prioritize voice traffic with Auto QoS.

[code]]czoxMzk6XCJtYWNybyBuYW1lIGRlc2t0b3ANCm1hY3JvIGRlc2NyaXB0aW9uIERlc2t0b3AgaW50ZXJmYWNlDQojIEFwcGx5IG1hY3J7WyYqJl19byBcXFwndW51c2VkXFxcJyBmaXJzdA0KZGVzY3JpcHRpb24gRGVza3RvcA0Kc3dpdGNocG9ydCBhY2Nlc3MgdmxhbiAzMDANCkBcIjt7WyYqJl19[[/code]

Lastly the DESKTOP macro assigns the access VLAN, and leaves all other configuration at default.

Using Macros

So now that you’ve done all this work, how does it make your life easier?  Like this:

[code]]czoyMjE6XCJpbnRlcmZhY2UgcmFuZ2UgZmEgMS8wLzEg4oCUIDQ4DQptYWNybyBhcHBseSB1bnVzZWQNCmludGVyZmFjZSByYW5nZSB7WyYqJl19ZmEgMS8wLzEg4oCUIDEwDQptYWNybyBhcHBseSBzZXJ2ZXINCmludGVyZmFjZSByYW5nZSBmYSAxLzAvMTEg4oCUIDIwDQptYWNyb3tbJiomXX0gYXBwbHkgZGVza3RvcGlwcGhvbmUNCmludGVyZmFjZSByYW5nZSBmYSAxLzAvMjEg4oCUIDQ4DQptYWNybyBhcHBseSBkZXNrdG9we1smKiZdfVwiO3tbJiomXX0=[[/code]

And that’s it!  You’ve just configured 48 interfaces with the right templated configurations.  Maybe you need to make sure that interfaces 8 — 16 are configured as desktop ports?

[code]]czo2OTpcImludGVyZmFjZSByYW5nZSBmYSAxLzAvOC0gMTYNCm1hY3JvIGFwcGx5IHVudXNlZA0KbWFjcm8gYXBwbHkgZGVza3RvcFwie1smKiZdfTt7WyYqJl19[[/code]

The nice thing about this is that your templates are stored on the device, and not on your laptop/desktop so you can make these changes from anywhere.

Other Uses for Macros

Macros also work in global configuration mode, so you can use them to prevent accidental slip-ups.  I made an earlier posting about blackholing IP addresses with BGP; one of the caveats is that it is possible for my client to accidentally blackhole his entire network.  Naturally this would be the worst possible scenario, even worse than a DDoS.

To accommodate this, I created a macro that takes a single IP address as an input and then writes the appropriate command to blackhole just one IP.

[code]]czo2NzpcIm1hY3JvIG5hbWUgYmxhY2tob2xlDQppcCByb3V0ZSAkSVAgMjU1LjI1NS4yNTUuMjU1IE51bGwwIHRhZyA5OTkNCkBcIjt7WyYqJl19[[/code]

In this case, $IP is a variable that is accepted by the following command:

[code]]czo1MjpcImNvbmYgdA0KbWFjcm8gYXBwbHkgYmxhY2tob2xlICRJUCAxOTIuMTY4LjIuMTAwDQplbmRcIjt7WyYqJl19[[/code]

This takes a single IP and correctly applies the route so that there is no chance of a tired, over caffeinated, stressed out finger accidentally setting the wrong mask and blackholing more IPs than are necessary.

2 thoughts on “Macros Make Your Life Easier

  1. Very interesting article Paul. Just one of the many under utilized features of Cisco IOS. I can see this easily cutting down configuration changes/management for any customer.

    The scripting nature of this article compels me to write a article about the uses of Cisco IOS EMM; another great feature that is, for the most part, unused.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s