Nexus NXOS的一些小特性

https://aboutnetworks.net/cisco-nxos-tips-and-tricks/#:~:text=Cisco%20Nexus%20NX-OS%20tips%20and%20tricks%201%20Hexadecimal,a%20user%20session%20%28less%20classic%29%20…%20More%20items

0 Accessing VRF-Context

This is really a useful one if you work with many VRFs. You can run CLI commands without adding vrf xxx every time:

N7k-LabSW# routing-context vrf management 
N7k-LabSW%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 10.48.61.129, [1/0], 1w4d, static
10.48.61.128/26, ubest/mbest: 1/0, attached
    *via 10.48.61.150, mgmt0, [0/0], 1w4d, direct
10.48.61.150/32, ubest/mbest: 1/0, attached
    *via 10.48.61.150, mgmt0, [0/0], 1w4d, local

N7k-LabSW%management# 
N7k-LabSW%management# routing-context vrf default
N7k-LabSW# 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>

1 同一行执行多条命令

使用分号;分隔
example:

interface ethernet 1/1 ; no shutdown ; ip address 10.248.1.1 255.255.255.0 ; description To-CoreSW

n9k# show clock ; show switchname ; show license host-id
22:21:34.231 CEST Fri Sep 20 2019
Time source is NTP
n9k 
License hostid: VDH=TBM12351230

也可以在执行1条后,等待指定的时间,再执行下一条命令
sleep xx

n9k# show clock ; sleep 10 ; show clock
22:23:28.048 CEST Fri Sep 20 2019
Time source is NTP
22:23:38.116 CEST Fri Sep 20 2019
Time source is NTP
n9k#

2 10进制与16进制转换

可以互转
example:

n9k# hex 255
0xff
n9k# dec 0x100
256
n9k#

3 创建快照

Configuration Snapshots and rollback

You can make a snapshot of a configuration with the command: checkpoint name
This creates a backup of the current configuration with the name name

n9k# checkpoint mycheckpoint
…Done
n9k#

Then, you can see the current checkpoints with the command: show checkpoint summary

n9k# show checkpoint summary

  1. mycheckpoint:
    Created by user
    Created at Fri, 22:53:09 20 Sep 2019
    Size is 60,452 bytes
    User Checkpoint Summary

Description: None

  1. system-fm-lldp:
    Created by admin
    Created at Tue, 16:49:34 14 May 2019
    Size is 56,911 bytes
    System Checkpoint Summary

Description: None

n9k#

Then, I do a small configuration change on the hostname.
Now, you can run a “diff” between the current config and the snapshot, using the command: show diff rollback-patch checkpoint name running-config

n9k# config t
Enter configuration commands, one per line. End with CNTL/Z.
n9k(config)# hostname n9k-test
n9k-test(config)# end
n9k-test#
n9k-test# show diff rollback-patch checkpoint mycheckpoint running-config
Collecting Running-Config
Generating Rollback Patch

!!

hostname n9k-test

vdc n9k-test id 1

n9k-test#

At this point, you can restore the checkpoint config with the rollback command: Rollback running-config checkpoint name atomic

n9k-test# rollback running-config checkpoint mycheckpoint
ADVISORY: Rollback operation started…
Modifying running configuration from another VSH terminal in parallel
is not recommended, as this may lead to Rollback failure.

Collecting Running-Config
Generating Rollback patch for switch profile
Rollback Patch is Empty
Collecting Running-Config
Generating Rollback Patch
Executing Rollback Patch
During CR operation,will retain L3 configuration
when vrf member change on interface
Generating Running-config for verification
Generating Rollback Patch

Rollback completed successfully.

n9k#

4 变量的使用

CLI variables

You can use variables on the CLI and also on configuration commands:

n9k# show cli variables
VSH Variable List (* = session vars)

SWITCHNAME=“n9k”
TIMESTAMP=“2019-09-20-22.29.54”
n9k#
n9k# tac-pac bootflash: ( S W I T C H N A M E ) − (SWITCHNAME)- (SWITCHNAME)(TIMESTAMP)-show-tech-all.gz
Show tech detail can take more than 5 minutes to complete. Please Wait …
n9k#
n9k# dir bootflash: | i show-tech
34015611 Sep 20 22:40:54 2019 n9k-2019-09-20-22.31.10-show-tech-all.gz
n9k#

You can also create your own variables:

n9k# config t
Enter configuration commands, one per line. End with CNTL/Z.
n9k(config)# cli var name MYINF interface e1/10
n9k(config)# end
n9k#
n9k# show $(MYINF) counters


Port InOctets InUcastPkts

Eth1/10 0 0


Port InMcastPkts InBcastPkts

Eth1/10 0 0


Port OutOctets OutUcastPkts

Eth1/10 231807771524466 175789738428


Port OutMcastPkts OutBcastPkts

Eth1/10 1266300 177
n9k#

5 定义别名

mmand Aliases for a user session (less classic)

You can define alias for the current user session. With the persist argument, you can also save the command alias for future use by the current user account:

n9k# terminal alias persist shintst show interface status
n9k# shintst


Port Name Status Vlan Duplex Speed Type

mgmt0 – connected routed full 1000 –
(…)

6 terminal的一些设置

Customize terminal settings

Remove terminal session timeouts:

n9k# show terminal | i Timeout
Session Timeout: 30 minutes
n9k#
n9k# terminal session-timeout 0
n9k#
n9k# show terminal | i Timeout
Session Timeout: 0 minutes

Set the width / length of the display terminal:
Nice when you don’t want output to break to a new line for long width outputs

n9k# show terminal | i Width
Length: 25 lines, Width: 98 columns
n9k#
n9k# terminal width 300
n9k#
n9k# show terminal | i Width
Length: 25 lines, Width: 300 columns

7 grep less count

grep, less, count

You can use “grep” instead of “include” on the show commands:

n9k# show int eth1/10 | grep multicast
0 unicast packets 0 multicast packets 0 broadcast packets
175478606395 unicast packets 1264673 multicast packets 177 broadcast packets

And there are more options, like:

Case insensitive matching (-i):

n9k# show int des | grep -i test
Eth1/1 eth 10G test-1
Eth1/12 eth 10G Test-12
n9k#

You can add count to count the lines (count the interfaces with description “test” in this example):

n9k# show int des | grep -i test | count
2
n9k#

8 Diff

Diff

You can see the differences between the interface counters with the diff argument. Example:

n9k# show int eth1/10 | diff
n9k#
(at the first command you have no output, it takes the “reference”)
n9k#
n9k# show int eth1/10 | diff
7c7
< reliability 255/255, txload 25/255, rxload 1/255

reliability 255/255, txload 24/255, rxload 1/255
25,26c25,26
< 30 seconds output rate 1000195376 bits/sec, 95761 packets/sec
< input rate 0 bps, 0 pps; output rate 1.00 Gbps, 95.76 Kpps


30 seconds output rate 942112632 bits/sec, 90670 packets/sec
input rate 0 bps, 0 pps; output rate 942.11 Mbps, 90.67 Kpps

29,30c29,30
< 300 seconds output rate 1800485896 bits/sec, 138192 packets/sec
< input rate 0 bps, 0 pps; output rate 1.80 Gbps, 138.19 Kpps

300 seconds output rate 1770948136 bits/sec, 135997 packets/sec
input rate 0 bps, 0 pps; output rate 1.77 Gbps, 136.00 Kpps

41,42c41,42
< 175412557922 unicast packets 1264324 multicast packets 177 broadcast packets
< 175413822423 output packets 231306944699930 bytes

175412712610 unicast packets  1264326 multicast packets  177 broadcast packets
175413977113 output packets  231307146937683 bytes

n9k#

You can do the same with an “inc” filter, for example:

n9k# show int eth1/10 | inc unicast | diff
2c2
< 175430277381 unicast packets 1264463 multicast packets 177 broadcast packets

175432920374 unicast packets 1264481 multicast packets 177 broadcast packets
n9k#

NOTE: NX-OS creates temporary files for the most current output for a show command for all current and previous users sessions. You can remove these temporary files using the diff-clean command:

n9k# diff-clean ?

all-sessions Remove ‘| diff’ temp files from all sessions (past and present!) of current user
all-users Remove ‘| diff’ temp files from all sessions (past and present!) of all users

n9k# diff-clean all-users

By default, the diff-clean command removes the temporary files for the current user’s active session. The all-sessions keyword removes temporary files for all past and present sessions for the current user. The all-users keyword removes temporary files for all past and present sessions for the all users.

9 Watch (N9K only)

Watch (n9k)

More or less the same as diff above, but in a different way:

9300# watch differences interval 1 show int eth1/10 counter

This is an image because I was not able to make a copy / past of the terminal

escape with Ctrl-C

Try also this command for example:

9300# watch show interface counters table

posted @ 2024-01-08 16:38  朱军杰  阅读(28)  评论(0)    收藏  举报  来源