Creating Command Aliases – Be faster in IOS typing

If You want to create aliases on Cisco device for commonly used or complex commands we will show you how in this short configuration article.

You can create command aliases on your router with the alias command:

Router1#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#alias exec rt show ip route
Router1(config)#alias exec on show ip ospf neighbor
Router1(config)#end
Router1#

These shortcut commands allow you to to type a few simple characters and the IOS will execute complex command sequences. This is most useful for common commands, and for commands that are complex or difficult to remember and type. You can create an alias for any command.

Here we have created the alias, r, for one of the most common commands we use everyday, show ip route:

Router1(config)#alias exec r show ip route

We can now use this simple one-letter command to display the routing table, saving time and typing:

Router1#r
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is 172.25.1.1 to network 0.0.0.0

C       172.16.2.0 is directly connected, FastEthernet0/0
Router1#

The key to choosing a good alias command name is to pick something that is short, easy to remember and that does not conflict with an existing command.

You can also use a command alias as part of a continued command. We could use our “r" alias to shorten the command show ip route 172.16.2.0:

Router1#r 172.16.2.0
Routing entry for 172.16.2.0/24
  Known via "connected", distance 0, metric 0 (connected, via interface)
  Routing Descriptor Blocks:
  * directly connected, via FastEthernet0/0.2
      Route metric is 0, traffic share count is 1
Router1#

The show alias command displays all the command aliases configured on the device:

Router1#show aliases
Exec mode aliases:
  h                     help
  lo                    logout
  p                     ping
  r                     resume
  s                     show
  u                     undebug
  un                    undebug
  w                     where
  rt                    show ip route
  on                    show ip ospf neighbor

Router1#

Leave a Reply

%d bloggers like this: