Cisco Nexus Alias别名使用方法

发布时间:2024年01月12日

alias是个啥?

就是一个别名。 啥意思呢?
就是通过自定义一个名称来代表一条命令,
目的: 简化敲键盘的次数。 怎么偷懒怎么来。

Nexus 系列

Nexus交换机在保存配置时,需要copy running startup,默认是没有write命令的,有没有更好的方法?
比如使用传统的wirte命令。

3548-1# copy running-config startup-config 
[########################################] 100%
Copy complete, now saving to disk (please wait)...

操作方法

定义alias

3548-1# conf t
3548-1(config)#cli alias name wri copy runn start

查看已经配置的alias

Nexus# show cli alias 
CLI alias commands
==================
alias           :show cli alias
wri             :copy runn start
cpu             :show processes cpu history
mod             :show module
inv             :show inventory
env             :show env
log             :sh logg la 50

测试,直接输入 wri保存

3548-1# wri
[########################################] 100%

添加echo

有一些show的命令时,我们想在输出前面加描述,可以使用echo 方式

example

Nexus#(config)# cli alias name f18 echo ********** ; echo To-Office-7609; echo ********** ; show int e1/8 | in Ethernet.*is|rate.*bps

上面命令中使用的分号 ;作用是啥?
用于分隔多条命令,Nexus支持在一行中执行多条命令,中间用 ;分隔即可。
关于命令;分隔可以参考这个链接。
思科Nexus在一行中执行多条命令 Link

测试效果

Nexus(config)# f18
**********
To-Office-7609
**********
Ethernet1/8 is up
    input rate 204.65 Mbps, 48.85 Kpps; output rate 1.02 Gbps, 138.28 Kpps
    input rate 182.73 Mbps, 46.65 Kpps; output rate 979.57 Mbps, 131.72 Kpps

1.2 Cisco 官方说明
Alias还可以实现嵌套,即定义的第2个alias 可以在其中调用其他的alias

Using Command Aliases
? Command alias support has the following characteristics:
? Command aliases are global for all user sessions.
? Command aliases are saved across reboots.
? Commands being aliased must be typed in full without abbreviation.
? Command alias translation always takes precedence over any keyword in any configuration mode or submode.
? Command alias support is only available on the supervisor module, not the switching modules.
? Command alias configuration takes effect for other user sessions immediately.
You cannot override the default command alias alias, which aliases the show cli aliascommand.
Nesting of command aliases is permitted to a maximum depth of 1. One command alias can refer to another command alias that must refer to a valid command, not to another command alias.
A command alias always replaces the first command keyword on the command line.
You can define command aliases for commands in any configuration submode or the EXEC mode.
Defining Command Aliases
You can define command aliases using the cli alias name command in configuration mode.
This following example shows how to define command aliases:
switch# configure terminal
switch(config)# cli alias name eth interface ethernet
switch(config)# cli alias name shintbr show interface brief
switch(config)# cli alias name shfcintup shintbr | include up | include fc

You can display the command aliases defined on the switch using the alias default command alias.
The following example shows how to display the command aliases defined on the switch:
switch# alias
CLI alias commands

alias :show cli alias
gigint :interface gigabitethernet
shintbr :show interface brief
shfcintup :shintbr | include up | include fc

2 IOS, IOS XE系列
以catalyst 3750为例, IOS
3850和ASR1000为例, IOS XE
这2个平台的alias命令语法相同.

语法:alias exec 变量名 具体命令

CISCO-ASR1000-AS1(config)#alias exec ship show ip int brief 

2.1.1	测试

CISCO-ASR1000-AS1#  ship
Interface              IP-Address      OK? Method Status                Protocol
Vlan1                  unassigned      YES NVRAM  administratively down down    
Vlan136                100.64.0.10     YES NVRAM  up                    up      
GigabitEthernet0/0     169.254.9.42     YES NVRAM  up                    up      
GigabitEthernet1/0/1   unassigned      YES unset  up                    up    






文章来源:https://blog.csdn.net/funnycoffee123/article/details/135543897
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。