Cisco Nexus useful commands

Table of Contents
In: Cisco

I have been working with Nexus for a while and picked up some really useful commands. I use these commands on a daily basis and it saves me few minutes every now and then :)

Please let me know in comments if you know any other interesting commands to try.

1.Find out when was the last time you copied the running config to start up config.

switch(config)# feature bash-shell

switch(config)# 2020 May 12 22:49:59 
switch %$ VDC-1 %$ %SECURITYD-2-FEATURE_ENABLE_DISABLE: User  has enabled the feature bash-shell


switch# run bash ls -ld /var/sysmgr/startup-cfg/ascii/system.cfg
-rw-rw-rw- 1 root root 4673 May 12 22:35 /var/sysmgr/startup-cfg/ascii/system.cfg
startup config

2. Create your own alias commands

The very first thing I do on a new Nexus switch is set up an alias for "wr" You can create an alias for any command you want.

switch# wr
         ^
% Invalid command at '^' marker.

switch# conf ter
Enter configuration commands, one per line. End with CNTL/Z.
    
switch(config)# cli alias name wr copy running-config startup-config
switch(config)# exit
    
switch# wr
[########################################] 100%
Copy complete, now saving to disk (please wait)...
Copy complete.
cli alias

3. Executing multiple CLI commands in one go

switch# conf t ; Interface Eth1/5 ; description packetswitch-demo

Enter configuration commands, one per line. End with CNTL/Z.
switch(config-if)# end

switch# show interface status | incl Eth1/5
Eth1/5        packetswitch-demo  notconnec 1         auto    auto    10g  
multiple cli commands

4. Filtering show logging output

switch# show clock 
22:36:23.745 UTC Tue May 12 2020
Time source is NTP
    

switch# show logging logfile start-time 2020 May 12 22:30:00
    
2020 May 12 22:30:10 switch %VDC_MGR-5-VDC_STATE_CHANGE: vdc 1 state changed to updating 
2020 May 12 22:30:10 switch %VDC_MGR-5-VDC_STATE_CHANGE: vdc 1 state changed to active 
2020 May 12 22:30:19 switch %ETHPORT-5-SPEED: Interface Ethernet1/1, operational speed changed to auto

switch# show logging last 2
2020 May 12 22:50:03 switch %VSHD-5-VSHD_SYSLOG_CONFIG_I: Configured from vty by cisco on console0
2020 May 12 22:50:17 switch %VSHD-5-VSHD_SYSLOG_CMD_EXEC: User:cisco executed the command:run bash
log

5. Tracking configuration changes / Accounting

switch# conf ter
Enter configuration commands, one per line. End with CNTL/Z.
switch(config)# inter eth1/2
switch(config-if)# description DEMO
switch(config-if)# end

switch# show accounting log | incl "DEMO"
    
Tue May 12 22:38:37 2020:type=update:id=console0:user=cisco:cmd=configure terminal ;
interface Ethernet1/2 ; description DEMO (REDIRECT)
Tue May 12 22:38:37 2020:type=update:id=console0:user=cisco:cmd=configure terminal ;
interface Ethernet1/2 ; description DEMO (SUCCESS)

switch# show accounting log | last 2
Tue May 12 22:58:57 2020:type=update:id=console0:user=cisco:cmd=configure termin
al ; 
interface Ethernet1/4 ; description diff (REDIRECT)
Tue May 12 22:58:57 2020:type=update:id=console0:user=cisco:cmd=configure termin
al ; 
interface Ethernet1/4 ; description diff (SUCCESS)
accounting

6. Easily generate "show tech-support" output

"show tech-support" might take a long time to show all the outputs. You can however, use the below command to create an archive file and send it over to TAC.

switch# tac-pac bootflash:showtechout.gz
Show tech detail can take more than 5 minutes to complete. Please Wait ...

switch# dir
       4096    May 12 22:28:14 2020  .rpmstore/
       4096    May 12 22:28:35 2020  .swtam/
 1335985152    Feb 17 15:30:28 2019  nxos.9.2.3.bin
          0    May 12 22:31:14 2020  platform-sdk.cmd
       4096    May 12 22:29:37 2020  scripts/
    5311525    May 12 22:42:44 2020  showtechout.gz  <<<<<< show tech-support
show tech

7. View previous and next lines from the "show" output

switch# show running-config | incl DEMO
  description DEMO
  
switch# show running-config | grep prev 2 next 2 DEMO

interface Ethernet1/2
  description DEMO

interface Ethernet1/3
switch# 
priv next

8. Turning off pagination

Display all the output without stopping at the end of each page. This is particularly useful with lengthy "show run" or "show ip route" commands.

switch# show run | no-more

switch# show ip route vrf prod | no-more
    
no-more

9. show cli history, self-explanatory

switch# show cli history 
31  22:57:15   conf ter
32  22:57:18   interface eth1/3
33  22:57:21   description test
34  22:57:23   no switchport 
35  22:57:24   end
36  22:57:27   show cli history 
cli history

10. Configuration difference between running-config and startup-config

switch(config)# interface eth1/4
switch(config-if)# description diff
switch(config-if)# end

switch# show run diff 
*** Startup-config
--- Running-config
***************
*** 39,48 ****
--- 39,49 ----
  interface Ethernet1/3
    description test
    no switchport
  
  interface Ethernet1/4
+   description diff
  
  interface Ethernet1/5
    description packetswitch-demo
  
  interface Ethernet1/6
diff

11. Run CLI commands for a specific VRF without adding VRF <vrf_name> every time to the command

switch# routing-context vrf prod 
    
switch%prod# show ip interface brief 

IP Interface Status for VRF "prod"(3)
Interface            IP Address      Interface Status
Vlan10               10.10.10.5      protocol-up/link-up/admin-up       
Vlan20               10.10.20.5      protocol-up/link-up/admin-up       
Vlan30               10.10.30.5      protocol-up/link-up/admin-up 

12. Embedded Logic Analyzer Module

ELAM can look inside Cisco ASIC and understand how a packet is forwarded. It can capture a packet in real-time without disruptions to performance or control-plane resources. Please check out my other blog for the full article: https://packetswitch.co.uk/cisco-embedded-logic-analyzer-module-2/

Reference

Nexus (NX-OS) tips and tricks
This document describes some quick tips and tricks which may enhance troubleshooting experience with NX-OS.

I learnt some of the tips from here: http://www.firewall.cx/cisco-technical-knowledgebase/cisco-data-center/1206-nexus-nx-os-commands-scripting-hints-and-tips.html

Thanks for reading

As always, your feedback and comments are more than welcome.

Written by
Suresh Vina
Tech enthusiast sharing Networking, Cloud & Automation insights. Join me in a welcoming space to learn & grow with simplicity and practicality.
Comments
More from Packetswitch
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Packetswitch.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.