7

I'm used to the Juniper and Extreme worlds more than Cisco. I'm able to get by OK, but some basic cli issues arise that have finally frustrated me enough.

Inside a Cisco ASA 5505/5510 running 8.3+ or a Cisco 2901 router running 15.2.

Is there a way to setup the IOS prompts so that you know which interface's config you are in, or which sub-menu you are in? For instance if I type "interface vlan 1" it will change to (config-if) but it sure would be nice to be able to know which interface submenu I'm in at that point that way I don't accidentally change something on the wrong interface, like if I had accidentally typed "interface vlan 2". Something like: (config-if/vlan1) would be nice.

Or am I simply looking at it from the wrong perspective and there's a good reason for the prompt syntax convention as is?

4 Answers 4

7

AFAIK, the answer is NO. I never understood how this valuable feature has escaped IOS for so many years or I manged to never discover it. ;-)

I use the following technique in some cases when I want to be absolutely sure I'm configuring the interface that I think I am. Comments (!) shown. I know this technique is long-winded for the net vets, but it fits perfectly with the paranoid crowd which is sometimes both.

conf t
do sh run int g1/1
! Look over int config and note description
int g1/1
 desc GiveMeThisInterfaceOrGiveMeDeath
 do sh run int g1/1
 !Confirm the int you think you're inside configuring is the one intended
 <config-if commands here>
2

IOS switches/routers do not have a command to show what sub-configuration mode you are in.

NX-OS has the where command.

2

I'm used to the Juniper and Extreme worlds more than Cisco. I'm able to get by OK, but some basic cli issues arise that have finally frustrated me enough.

Inside a Cisco ASA 5505/5510 running 8.3+ or a Cisco 2901 router running 15.2.

Technically with IOS 15.2, the answer is "yes, you can know what interface you're configuring" but admittedly my solution involves a rather unpleasant kludge-fix.

I will demonstrate how to use EEM version 3.2 to print out the interface name that you last configured. I do not pretend this solution is perfect, but it gets the job done.

Example:

DEN-EDGE-02#sh ver | i IOS
Cisco IOS Software, 2800 Software (C2800NM-ADVENTERPRISEK9-M), Version 15.1(4)M7, RELEASE 
SOFTWARE (fc2)
DEN-EDGE-02#
DEN-EDGE-02#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
DEN-EDGE-02(config)#username cisco password cisco
DEN-EDGE-02(config)#
DEN-EDGE-02(config)#interface Fa0/0
Last interface configured was: FastEthernet0/0

DEN-EDGE-02(config-if)#no ip proxy-arp
Last interface configured was: FastEthernet0/0

DEN-EDGE-02(config-if)#interface lo0
Last interface configured was: Loopback0

DEN-EDGE-02(config-if)#ip address 1.1.1.1 255.255.255.255
Last interface configured was: Loopback0

DEN-EDGE-02(config-if)#exit
Last interface configured was: Loopback0

DEN-EDGE-02(config)#
DEN-EDGE-02(config)#username cisco password cisco
Last interface configured was: Loopback0

DEN-EDGE-02(config)#end
DEN-EDGE-02#
DEN-EDGE-02#sh ver | i IOS
Cisco IOS Software, 2800 Software (C2800NM-ADVENTERPRISEK9-M), Version 15.1(4)M7, RELEASE 
SOFTWARE (fc2)
DEN-EDGE-02#

At this point, my answer is closer to proof-of-concept code, which has several caveats...

  • Interface logging happens even after exiting interface configuration sub-mode; thus you will be reminded about what interface you recently configured as long as you're still in any Cisco IOS configuration mode. The EEM policy silences itself after exiting config mode with end - but it doesn't catch exit via cntl-z at this point.
  • EEM configures the router to store script state variables (i.e. $_user_intf and $_config_mode). This means you get %SYS-5-CONFIG_I syslog messages each time the script changes state (which is quite annoying if you're on the console). Technically you could glue in an ESM policy to silence the EEM syslog messages, but that only increases the work you're doing to solve this problem...

Please find the configuration to print the last configured interface below... I need to give credit to Ivan Pepelnjak for his blog about _exit_status


! Reset to defaults...
no event manager applet IntfCliLog
no event manager environment _user_intf
no event manager environment _config_mode
!
event manager environment _user_intf _None_
event manager environment _config_mode 1
event manager applet IntfCliLog
 event cli pattern ".*" sync yes
 action 010 set match "_None_"
 action 020 regexp "^(configure t)" $_cli_msg match
 action 030 comment !! Set _config_mode upon entering config mode
 action 040 if $match ne "_None_"
 action 050 cli command "enable"
 action 060 cli command "configure t"
 action 070 cli command "event manager environment _config_mode 1"
 action 080 cli command "end"
 action 090 end
 action 100 set match "_None_"
 action 110 regexp "^(end)" $_cli_msg match
 action 120 comment !! clear variables upon exit from config mode
 action 130 if $match ne "_None_"
 action 140 cli command "enable"
 action 150 cli command "configure t"
 action 160 cli command "event manager environment _config_mode 0"
 action 170 cli command "event manager environment _user_intf _None_"
 action 180 cli command "end"
 action 190 end
 action 200 comment !! Parse any "interface" commands
 action 210 set intfName "_None_"
 action 220 regexp "^interface *(.*)" $_cli_msg match intfName
 action 230 if $intfName ne "_None_"
 action 240 cli command "enable"
 action 250 cli command "configure t"
 action 260 cli command "event manager environment _user_intf $intfName"
 action 270 cli command "end"
 action 280 end
 action 290 comment !! Log the last interface configured
 action 300 if $_config_mode eq 1
 action 340 if $_user_intf ne "_None_"
 action 350 puts "Last interface configured was: $_user_intf"
 action 360 end
 action 370 end
 action 380 comment !! Set _exit_status 1 to run commands with "event cli ... sync yes"
 action 390 set _exit_status 1
 action 400 exit
0

No. However, you can simply input the interface name again to ensure you're in the expected interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.