Cisco IOS cli 提示 - 有什么方法可以知道您正在配置哪个接口?

网络工程 思科-ios 命令行
2021-07-10 00:26:49

与 Cisco 相比,我更习惯 Juniper 和 Extreme 世界。我可以过得很好,但是出现了一些基本的 cli 问题,这些问题最终让我感到沮丧。

在运行 8.3+ 的 Cisco ASA 5505/5510 或运行 15.2 的 Cisco 2901 路由器内部。

有没有办法设置 IOS 提示,以便您知道您在哪个界面的配置中,或者您在哪个子菜单中?例如,如果我输入“interface vlan 1”,它将更改为 (config-if) 但如果能够知道我在那个时候所在的接口子菜单肯定会很好,这样我就不会不小心更改某些内容错误的接口,就像我不小心输入了“interface vlan 2”一样。像: (config-if/vlan1) 会很好。

或者我只是从错误的角度看待它,并且有一个很好的理由来使用提示语法约定?

4个回答

AFAIK,答案是否定的我从来不明白这个有价值的功能是如何从 IOS 中逃脱的,或者我一直没有发现它。;-)

在某些情况下,当我想绝对确定我正在配置我认为的接口时,我会使用以下技术。评论 (!) 显示。我知道这项技术对于网络兽医来说是冗长的,但它非常适合偏执的人群,有时两者兼而有之。

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>

IOS 交换机/路由器没有命令来显示您所处的子配置模式。

NX-OS 有where命令。

与 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

不可以。但是,您可以简单地再次输入接口名称以确保您处于预期的接口中。