cisco NXOS 终端技巧

下面展示了一些可以增强NX-OS故障排查经验的技巧。

十六进制/十进制转换

1
2
3
4
Nexus# hex 100
0x64
Nexus# dec 0x64
100

注:hex 和 dec 均为隐藏命令。

一次执行多个命令

1
2
3
4
5
6
Nexus# show clock ; show switchname ; show ip int brie
09:00:00.642 CST Wed Nov 01 2020
Nexus
IP Interface Status for VRF "default"(1)
Interface IP Address Interface Status
Nexus#

注:命令可简写/后续命令无法Tab或?

配置命令

1
2
3
Nexus# conf t ; hostname NXOSSW ; end
Enter configuration commands, one per line. End with CNTL/Z.
NXOSSW#

查看命令执行时间

1
2
3
4
Nexus# show clock ; show run | ex .* ; show clock
11:15:24.510 CST Wed Nov 01 2020
11:15:24.576 CST Wed Nov 01 2020
Nexus#

tech-support文件输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Nexus# tac-pac
Nexus# dir volatile:
0 Jan 01 08:02:16 2001 nginx_logflag
926120 Nov 01 16:49:56 2020 show_tech_out.gz

Usage for volatile://sup-local
937984 bytes used
103919616 bytes free
104857600 bytes total
Nexus#
Nexus# tac-pac bootflash:
Nexus# dir bootflash: | i show_tech_out
926120 Nov 01 17:36:36 2020 show_tech_out.gz
Nexus#
Nexus# tac-pac bootflash:20191106-show-tech.gz
Nexus#

注:使用传统 show tech-support 方式获取该文件有时会非常大而且需要非常长的时间去生成,并且会弹到终端内刷新页面。
nexus设备可以使用tac-pac命令替代,输入命令回车后等待一段时间后,自动生成show_tech_out.gz文件,默认保存在volatile:中。
推荐使用tac-pac bootflash:,保存在bootflash:里,之后可以通过FTP等方式导出。

使用CLI变量

1
2
3
4
5
6
7
8
9
Nexus# show cli variables
VSH Variable List (* = session vars)
-----------------
SWITCHNAME="Nexus"
TIMESTAMP="2020-11-01-15.09.50"
Nexus#
Nexus# tac-pac bootflash:$(SWITCHNAME)-$(TIMESTAMP)-show-tech-out.gz
Nexus# dir bootflash: | i show-tech-out
926120 Nov 02 08:56:36 2020 Nexus-2020-11-01-15.14.15-show-tech-out.gz

使用cli alias

默认配置

1
2
3
4
5
6
7
8
9
Nexus# alias
CLI alias commands
==================
alias :show cli alias
Nexus# show cli alias
CLI alias commands
==================
alias :show cli alias
Nexus#

全局配置

1
2
3
4
5
6
7
8
9
10
11
12
Nexus(config)# cli alias name shiib show ip int brief
Nexus# shiib
IP Interface Status for VRF "default"(1)
Interface IP Address Interface Status
Vlan100 1.1.1.1 protocol-up/link-up/admin-up
Nexus#
Nexus# show cli alias
CLI alias commands
==================
alias :show cli alias
shiib :show ip int brief
Nexus#

基于终端会话临时配置

1
2
3
4
5
6
Nexus# terminal alias shiib show ip int brief
Nexus# shiib
IP Interface Status for VRF "default"(1)
Interface IP Address Interface Status
Vlan100 1.1.1.1 protocol-up/link-up/admin-up
Nexus#

使用cli alias & 一次性执行多个命令

1
2
3
4
5
6
7
8
9
Nexus# terminal alias shall show clock ; show switchname ; show ip int brief
Nexus# shall
15:25:33.097 UTC Thu Nov 05 2020
Time source is NTP
Nexus

IP Interface Status for VRF "default"(1)
Interface IP Address Interface Status
Nexus#

注:全局或会话alias,show 或 config命令都可以组合尝试。

定制终端设置

终端会话超时

1
2
3
4
5
6
7
8
9
Nexus# show terminal | in Timeout
Session Timeout: 30 minutes
Nexus#
Nexus# terminal session-timeout ?
<0-525600> Enter timeout in minutes, 0 to disable

Nexus# terminal session-timeout 0
Nexus# show terminal | in Timeout
Session Timeout: 0 minutes

显示终端的宽度长度

1
2
3
4
5
6
Nexus# show terminal | in Length
Length: 43 lines, Width: 152 columns
Nexus# terminal length 35
Nexus# show terminal | in Length
Length: 35 lines, Width: 152 columns
Nexus#

延迟命令执行

1
2
3
4
5
6
Nexus# show clock ; sleep 2 ; show clock
15:30:36.009 UTC Thu Nov 05 2020
Time source is NTP
15:30:38.022 UTC Thu Nov 05 2020
Time source is NTP
Nexus#

查看其他vrf的路由

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Nexus# routing-context vrf management
Nexus%management# sh ip route
IP Route Table for VRF "management"
'*' denotes best ucast next-hop
'**' denotes best mcast next-hop
'[x/y]' denotes [preference/metric]
'%<string>' in via output denotes VRF <string>

0.0.0.0/0, ubest/mbest: 1/0
*via 11.1.1.1, [1/0], 6w5d, static
11.1.1.0/24, ubest/mbest: 1/0, attached
*via 11.1.1.2, mgmt0, [0/0], 6w6d, direct
11.1.1.2/32, ubest/mbest: 1/0, attached
*via 11.1.1.2, mgmt0, [0/0], 6w6d, local
Nexus%management# routing-context vrf default
Nexus# sh ip route
IP Route Table for VRF "default"
'*' denotes best ucast next-hop
'**' denotes best mcast next-hop
'[x/y]' denotes [preference/metric]
'%<string>' in via output denotes VRF <string>

0.0.0.0/0, ubest/mbest: 1/0
*via 10.1.1.1, [1/0], 6w5d, static
10.1.1.0/24, ubest/mbest: 1/0, attached
*via 10.1.1.2, Vlan1, [0/0], 6w5d, direct
10.1.1.2/32, ubest/mbest: 1/0, attached
*via 10.1.1.2, Vlan1, [0/0], 6w5d, local
Nexus#