Alias, the Unsung Hero of the Cisco CLI

Basic Alias Commands

There are plenty of articles and posts around showing you how to use alias commands, but I never see them being used to their full potential. Let’s look at how we can get a bit more than the obvious out of this useful little critter!

We’ll start with some basic aliases we are all probably familiar with.  If not, put them in your templates. They are worth the effort!

 alias exec srb sh run | beg
 alias exec srs sh run | sec
 alias exec sri sh run | incl
 alias exec siib sh ip int brief
 alias exec srint sh run interface

These give you great shortcuts to common “show” commands and are invaluable, especially in a CCIE lab setting.

Let’s Get Clever

Now, we all probably use the do command to ‘do’ a show command from within config mode or interface config mode…something like:

 R1(config)#do sh ip int brief

You can do the same with your aliases:

 R1(config)#do srs alias

I don’t know about anyone else, but I’m forever forgetting to type ‘do’, especially when switching between IOS and ASA devices. Why not put the “show” command in an alias of its own that is applied at the configure level of the cli?

 R1(config)#alias configure sh do sh

You can extend this further to any other cli mode you are frequently in:

 R1(config)#alias interface sh do sh
 R1(config)#alias subinterface sh do sh

There are plenty more cli levels that may be more useful if you have a voice or security focus – “alias ?” is worth trawling through…

Now we are in a position where we can ignore the do command at several depths of the cli, much like on an ASA. Useful, but what about our other aliases? Unfortunately, the do show alias isn’t used recursively in other alias commands so the srint we created at the top won’t automatically become do show run interface. That would be nice, but I can see how recursive alias resolution could break things unexpectedly.

That’s not the end of the world though, because with some copy/paste, and finding/replacing, we can replicate our aliases to each level of cli and insert the “do” directly into the alias, like so…

 R1(config)#alias exec srb sh run | beg
 R1(config)#alias exec srs sh run | sec
 R1(config)#alias exec sri sh run | incl
 R1(config)#alias exec siib sh ip int brief
 R1(config)#alias exec srint sh run interface
 R1(config)#
 R1(config)#alias configure sh do sh
 R1(config)#alias configure siib do sh ip int brief
 R1(config)#alias configure srb do sh run | beg
 R1(config)#alias configure srs do sh run | sec
 R1(config)#alias configure sri do sh run | incl
 R1(config)#alias configure srint do sh run interface
 R1(config)#
 R1(config)#alias interface sh do sh
 R1(config)#alias interface siib do sh ip int brief

…etc., down to all the config sub levels you frequently use. I’ll leave it there. You get the concept by now I’m sure.

Using Alias Cross-Platform

Now we have all our usual aliases directly available at config, interface and subinterface level. So where else can this little command help us out? On the odd occasions where Cisco is not being consistent across platforms (whatever happened to one IOS anyway?), a useful approach is to use the alias command to standardize your shortcuts:

 ASA(config)# command-alias exec siib sh interface ip brief
 ! Did you see what they did there?!?

or replace the standard shortcuts that Cisco somehow forgot:

 NX-OS(config)#cli alias name wr copy run start

or just to save your sanity because every OS has different ways of grepping:

 IOS-XR(config)#alias shcrc sh int | utility egrep expr "Descri|CRC|line protocol"

Hopefully that’s given you some food for thought. Sometimes amidst all the complicated MPLS/IPv6/IS-IS stuff, it’s nice to take a break and get a really simple tool to help out with the day to day finger trouble! Of course, it might not be so useful if you’re a roaming tech that works on different sites every day, but “alias” is great in an enterprise or SP environment where you can control, or at least influence, the device templates.

(You are using templates aren’t you?)

About Ian Castleman

Ian is currently serving a sentence as Network Architect at one of South Africa's largest consumer ISPs and was previously incarcerated in a more security-focused role based in London. CCIE #9888, he briefly contemplated going into Emeritus status, then booked the security lab in a mid-life crisis kind of way.
You can find him (usually lurking) @iancastleman

  • http://twitter.com/MarkTurpinSTL Mark Turpin

    Great article and ideas on using alias.  Wish Cisco would incorporate ‘show’ into the ‘configure’ mode and be done with it though.

  • http://twitter.com/caskings caskings

    For me another useful aliases for *nix users:

    alias su enable

  • cisco ccie security

    good articles i appreciate your work and such useful aliases

  • Jsicuran

    I use them all the time. Great for menu systems or a custom command set for a large deployment. Complement them with switch macros or EEM/TCL applets on IOS/XE/NX and you have some cool tools. However, not recommended for Associate or Professional level cisco cert training for you get used to “your” shortcuts and it may trip you up on a test.

  • Jsicuran

    For some common clear commands or other commands with feedback I would create an EEM applet to do my clears and feed the Y/N and use the alias to execute the EEM applet.

  • Jsicuran

    Great article Ian.

  • cisco ccie security

    a good post is been given,its really been appreciated.the article and ideas are well performed.good work.thank you.

  • http://twitter.com/iancastleman Ian Castleman

    Thanks for the feedback all, working on some IPv6 posts, hope to get them out soon…