与 Cisco 相比,我更习惯 Juniper 和 Extreme 世界。我可以过得很好,但是出现了一些基本的 cli 问题,这些问题最终让我感到沮丧。
在运行 8.3+ 的 Cisco ASA 5505/5510 或运行 15.2 的 Cisco 2901 路由器内部。
从技术上讲,对于 IOS 15.2,答案是“是的,您可以知道您正在配置什么接口”,但无可否认,我的解决方案涉及一个相当令人不快的kludge-fix。
我将演示如何使用EEM 3.2 版打印出您上次配置的接口名称。我不假装这个解决方案是完美的,但它完成了工作。
示例:
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#
在这一点上,我的答案更接近于概念验证代码,其中有几个警告......
- 即使在退出接口配置子模式后,接口日志也会发生;因此,只要您仍处于任何 Cisco IOS 配置模式,就会提醒您最近配置的接口。EEM 策略在退出配置模式后自行静音
end
- 但此时它不会通过退出来捕获退出cntl-z
。
- EEM 配置路由器以存储脚本状态变量(即
$_user_intf
和$_config_mode
)。这意味着%SYS-5-CONFIG_I
每次脚本更改状态时您都会收到系统日志消息(如果您在控制台上,这很烦人)。从技术上讲,您可以粘贴ESM 策略来使 EEM 系统日志消息静音,但这只会增加您为解决此问题所做的工作......
请在下面找到打印最后配置界面的配置...我需要感谢 Ivan Pepelnjak 的博客关于_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