Written for NX-OS 9 and 10 on Nexus 9000 switches. Some commands differ on other Nexus models and older versions. Most things have to be switched on with a feature command before their commands appear. Each command shows the mode to type it in. Config blocks start in global config mode (after configure terminal), and indented lines go inside the line above them. Names, addresses and passwords are examples, so swap in your own.

Modes and getting around #

  • Enter config modeCisco NX-OS · EXEC (#)
    configure terminal
  • Leave config modeCisco NX-OS · Global config (config)#
    end
  • Run a show command from config mode (no do needed)Cisco NX-OS · Global config (config)#
    show ip interface brief
  • See which mode and context you're inCisco NX-OS · EXEC (#)
    where detail
  • List the commands you've typedCisco NX-OS · EXEC (#)
    show cli history
  • Stop output pausing at each screenCisco NX-OS · EXEC (#)
    terminal length 0
  • Make a short alias for a long commandCisco NX-OS · Global config (config)#
    cli alias name wr copy running-config startup-config

Filtering output #

  • Show only the lines that contain a wordCisco NX-OS · EXEC (#)
    show running-config | include hostname
  • Search output with grep, ignoring caseCisco NX-OS · EXEC (#)
    show interface status | grep -i connected
  • Show one section of the configCisco NX-OS · EXEC (#)
    show running-config | section bgp
  • Show output without pagingCisco NX-OS · EXEC (#)
    show running-config | no-more
  • Get output as JSONCisco NX-OS · EXEC (#)
    show interface brief | json-pretty
  • Show the config including default settingsCisco NX-OS · EXEC (#)
    show running-config all

Features #

  • List features and whether they're onCisco NX-OS · EXEC (#)
    show feature
  • Turn on VLAN interfaces (SVIs)Cisco NX-OS · Global config (config)#
    feature interface-vlan
  • Turn on LACP for port channelsCisco NX-OS · Global config (config)#
    feature lacp
  • Turn on vPCCisco NX-OS · Global config (config)#
    feature vpc
  • Turn on OSPFCisco NX-OS · Global config (config)#
    feature ospf
  • Turn on BGPCisco NX-OS · Global config (config)#
    feature bgp
  • Turn on HSRPCisco NX-OS · Global config (config)#
    feature hsrp
  • Turn on LLDPCisco NX-OS · Global config (config)#
    feature lldp
  • Turn on the DHCP relay and snooping featureCisco NX-OS · Global config (config)#
    feature dhcp
  • Turn on TACACS+Cisco NX-OS · Global config (config)#
    feature tacacs+
  • Let other devices copy files to this switch with SCPCisco NX-OS · Global config (config)#
    feature scp-server
  • Turn off TelnetCisco NX-OS · Global config (config)#
    no feature telnet

Basic setup #

  • Set the hostnameCisco NX-OS · Global config (config)#
    hostname N9K-1
  • Create an admin userCisco NX-OS · Global config (config)#
    username admin password MyPassword role network-admin
  • Create a read-only userCisco NX-OS · Global config (config)#
    username ops password MyPassword role network-operator
  • Give the management port an IP addressCisco NX-OS · Global config (config)#
    interface mgmt0 ip address 192.168.1.10/24
  • Set the default gateway for management trafficCisco NX-OS · Global config (config)#
    vrf context management ip route 0.0.0.0/0 192.168.1.1
  • Set the domain nameCisco NX-OS · Global config (config)#
    ip domain-name corp.example.com
  • Set a DNS server, reached through the management VRFCisco NX-OS · Global config (config)#
    ip name-server 1.1.1.1 use-vrf management
  • Set an NTP server, reached through the management VRFCisco NX-OS · Global config (config)#
    ntp server 192.168.1.5 use-vrf management
  • Set the time zoneCisco NX-OS · Global config (config)#
    clock timezone GMT 0 0
  • Show a login bannerCisco NX-OS · Global config (config)#
    banner motd # Authorised access only #
  • Log out idle SSH sessions after 10 minutesCisco NX-OS · Global config (config)#
    line vty exec-timeout 10
  • Log out an idle console session after 10 minutesCisco NX-OS · Global config (config)#
    line console exec-timeout 10

Save, back up and roll back #

  • Save the running configCisco NX-OS · EXEC (#)
    copy running-config startup-config
  • Show what's changed since the last saveCisco NX-OS · EXEC (#)
    show running-config diff
  • Show the saved configCisco NX-OS · EXEC (#)
    show startup-config
  • Copy the config to a file on the switchCisco NX-OS · EXEC (#)
    copy running-config bootflash:N9K-1-backup.cfg
  • Back up the config to a TFTP serverCisco NX-OS · EXEC (#)
    copy running-config tftp://192.168.1.5/N9K-1-backup.cfg vrf management
  • Back up the config to a server with SCPCisco NX-OS · EXEC (#)
    copy running-config scp://[email protected]/N9K-1-backup.cfg vrf management
  • Take a checkpoint before a changeCisco NX-OS · EXEC (#)
    checkpoint before-change
  • List checkpointsCisco NX-OS · EXEC (#)
    show checkpoint summary
  • Show what rolling back to a checkpoint would changeCisco NX-OS · EXEC (#)
    show diff rollback-patch checkpoint before-change running-config
  • Roll back to a checkpointCisco NX-OS · EXEC (#)
    rollback running-config checkpoint before-change

    Warning: Replaces the running config with the checkpoint. Check the rollback-patch diff first.

  • Delete a checkpointCisco NX-OS · EXEC (#)
    no checkpoint before-change
  • See who changed the config and whenCisco NX-OS · EXEC (#)
    show accounting log
  • List files on the switchCisco NX-OS · EXEC (#)
    dir bootflash:
  • Show the contents of a fileCisco NX-OS · EXEC (#)
    show file bootflash:N9K-1-backup.cfg
  • Delete a fileCisco NX-OS · EXEC (#)
    delete bootflash:N9K-1-backup.cfg

    Warning: Deleted files can't be recovered.

  • Erase the saved configCisco NX-OS · EXEC (#)
    write erase

    Warning: Wipes the startup config. The switch comes up unconfigured after the next reload.

  • Restart the switchCisco NX-OS · EXEC (#)
    reload

    Warning: Restarts the switch and drops all traffic through it. Save the config first.

Show and verify #

  • Show the software version and uptimeCisco NX-OS · EXEC (#)
    show version
  • Show modules and their statusCisco NX-OS · EXEC (#)
    show module
  • Show serial numbers and hardwareCisco NX-OS · EXEC (#)
    show inventory
  • Show fans, power supplies and temperatureCisco NX-OS · EXEC (#)
    show environment
  • Show CPU and memory useCisco NX-OS · EXEC (#)
    show system resources
  • Show the busiest processesCisco NX-OS · EXEC (#)
    show processes cpu sort
  • Show how long the switch has been upCisco NX-OS · EXEC (#)
    show system uptime
  • Show why the switch last restartedCisco NX-OS · EXEC (#)
    show system reset-reason
  • Show every interface in one tableCisco NX-OS · EXEC (#)
    show interface brief
  • Show port status, VLAN, speed and duplexCisco NX-OS · EXEC (#)
    show interface status
  • Show one interface in detailCisco NX-OS · EXEC (#)
    show interface Ethernet1/1
  • Show interface descriptionsCisco NX-OS · EXEC (#)
    show interface description
  • Show interface error countersCisco NX-OS · EXEC (#)
    show interface counters errors
  • Show an optic's type and light levelsCisco NX-OS · EXEC (#)
    show interface Ethernet1/1 transceiver details
  • Show IP addresses in the default VRFCisco NX-OS · EXEC (#)
    show ip interface brief
  • Show IP addresses in every VRFCisco NX-OS · EXEC (#)
    show ip interface brief vrf all
  • Show neighbours seen with CDPCisco NX-OS · EXEC (#)
    show cdp neighbors
  • Show neighbours seen with LLDPCisco NX-OS · EXEC (#)
    show lldp neighbors
  • Show the MAC address tableCisco NX-OS · EXEC (#)
    show mac address-table
  • Find which port a MAC address is onCisco NX-OS · EXEC (#)
    show mac address-table address aabb.cc00.0100
  • Show the ARP tableCisco NX-OS · EXEC (#)
    show ip arp
  • Show who's logged inCisco NX-OS · EXEC (#)
    show users
  • Show the last 50 log messagesCisco NX-OS · EXEC (#)
    show logging last 50
  • Show the whole log fileCisco NX-OS · EXEC (#)
    show logging logfile

Interfaces #

  • Describe an interfaceCisco NX-OS · Global config (config)#
    interface Ethernet1/1 description Uplink to core
  • Turn an interface onCisco NX-OS · Global config (config)#
    interface Ethernet1/1 no shutdown
  • Turn an interface offCisco NX-OS · Global config (config)#
    interface Ethernet1/1 shutdown
  • Configure several interfaces at onceCisco NX-OS · Global config (config)#
    interface Ethernet1/1-4 description Server ports
  • Make a port a routed (Layer 3) port with an IP addressCisco NX-OS · Global config (config)#
    interface Ethernet1/1 no switchport ip address 10.0.0.1/30 no shutdown
  • Make a routed port a switch port againCisco NX-OS · Global config (config)#
    interface Ethernet1/1 switchport
  • Create a loopback interfaceCisco NX-OS · Global config (config)#
    interface loopback0 ip address 10.255.255.1/32
  • Set the speed of a portCisco NX-OS · Global config (config)#
    interface Ethernet1/1 speed 10000
  • Allow jumbo frames on a portCisco NX-OS · Global config (config)#
    interface Ethernet1/1 mtu 9216
  • Reset an interface to its default configCisco NX-OS · Global config (config)#
    default interface Ethernet1/1

    Warning: Removes all config from the interface.

  • Split a 40G or 100G port into fourCisco NX-OS · Global config (config)#
    interface breakout module 1 port 49 map 10g-4x

    Warning: Removes the config on that port. Supported ports and speeds depend on the model.

  • Clear an interface's countersCisco NX-OS · EXEC (#)
    clear counters interface Ethernet1/1

VLANs and trunks #

  • Create a VLAN and name itCisco NX-OS · Global config (config)#
    vlan 10 name Users
  • Delete a VLANCisco NX-OS · Global config (config)#
    no vlan 10
  • List VLANs and their portsCisco NX-OS · EXEC (#)
    show vlan brief
  • Make a port an access port in a VLANCisco NX-OS · Global config (config)#
    interface Ethernet1/1 switchport switchport mode access switchport access vlan 10
  • Make a port a trunk carrying some VLANsCisco NX-OS · Global config (config)#
    interface Ethernet1/48 switchport switchport mode trunk switchport trunk allowed vlan 10,20,30

    Warning: Replaces the trunk's allowed VLAN list. Use add to include one more without removing the others.

  • Add a VLAN to a trunkCisco NX-OS · Global config (config)#
    interface Ethernet1/48 switchport trunk allowed vlan add 40
  • Remove a VLAN from a trunkCisco NX-OS · Global config (config)#
    interface Ethernet1/48 switchport trunk allowed vlan remove 40
  • Change a trunk's native VLANCisco NX-OS · Global config (config)#
    interface Ethernet1/48 switchport trunk native vlan 99
  • List trunk ports and their VLANsCisco NX-OS · EXEC (#)
    show interface trunk
  • Show a port's VLAN and trunk settingsCisco NX-OS · EXEC (#)
    show interface Ethernet1/1 switchport
  • Give a VLAN an IP address (SVI)Cisco NX-OS · Global config (config)#
    feature interface-vlan interface Vlan10 ip address 192.168.10.1/24 no shutdown

Port channels #

  • Bundle ports into a port channel with LACPCisco NX-OS · Global config (config)#
    feature lacp interface Ethernet1/47-48 channel-group 10 mode active
  • Make a port channel a trunkCisco NX-OS · Global config (config)#
    interface port-channel10 switchport mode trunk
  • Show port channels and their member portsCisco NX-OS · EXEC (#)
    show port-channel summary
  • Show the LACP partner on each portCisco NX-OS · EXEC (#)
    show lacp neighbor

vPC #

  • Create a vPC domain and its keepalive linkCisco NX-OS · Global config (config)#
    feature vpc vpc domain 1 peer-keepalive destination 192.168.1.2 source 192.168.1.1 vrf management
  • Make a port channel the vPC peer linkCisco NX-OS · Global config (config)#
    interface port-channel1 switchport mode trunk vpc peer-link
  • Make a port channel a vPC to another deviceCisco NX-OS · Global config (config)#
    interface port-channel10 vpc 10
  • Turn on the usual vPC domain optionsCisco NX-OS · Global config (config)#
    vpc domain 1 peer-switch peer-gateway auto-recovery ip arp synchronize
  • Choose which switch is the vPC primaryCisco NX-OS · Global config (config)#
    vpc domain 1 role priority 1000
  • Show vPC statusCisco NX-OS · EXEC (#)
    show vpc
  • Show which switch is primaryCisco NX-OS · EXEC (#)
    show vpc role
  • Show the keepalive link's statusCisco NX-OS · EXEC (#)
    show vpc peer-keepalive
  • Check both switches' settings matchCisco NX-OS · EXEC (#)
    show vpc consistency-parameters global

Spanning tree #

  • Show spanning treeCisco NX-OS · EXEC (#)
    show spanning-tree
  • Show spanning tree for one VLANCisco NX-OS · EXEC (#)
    show spanning-tree vlan 10
  • Show a spanning tree summaryCisco NX-OS · EXEC (#)
    show spanning-tree summary
  • Make this switch the root for a VLANCisco NX-OS · Global config (config)#
    spanning-tree vlan 10 root primary
  • Set the spanning tree priority for a VLANCisco NX-OS · Global config (config)#
    spanning-tree vlan 10 priority 4096
  • Mark a port as an edge port (a server or PC)Cisco NX-OS · Global config (config)#
    interface Ethernet1/1 spanning-tree port type edge
  • Mark a trunk to a server as an edge portCisco NX-OS · Global config (config)#
    interface Ethernet1/1 spanning-tree port type edge trunk
  • Turn on BPDU guard for a portCisco NX-OS · Global config (config)#
    interface Ethernet1/1 spanning-tree bpduguard enable
  • Turn on BPDU guard for every edge portCisco NX-OS · Global config (config)#
    spanning-tree port type edge bpduguard default
  • Stop a port becoming the path to a new root (root guard)Cisco NX-OS · Global config (config)#
    interface Ethernet1/48 spanning-tree guard root

VRFs #

  • Create a VRFCisco NX-OS · Global config (config)#
    vrf context TENANT-A description Tenant A
  • Put an interface in a VRFCisco NX-OS · Global config (config)#
    interface Ethernet1/1 vrf member TENANT-A

    Warning: Removes the interface's IP address, so set the address again afterwards.

  • List VRFsCisco NX-OS · EXEC (#)
    show vrf
  • Show which interfaces are in each VRFCisco NX-OS · EXEC (#)
    show vrf interface
  • Show a VRF's routing tableCisco NX-OS · EXEC (#)
    show ip route vrf TENANT-A
  • Ping through the management VRFCisco NX-OS · EXEC (#)
    ping 192.168.1.1 vrf management
  • Trace a route through the management VRFCisco NX-OS · EXEC (#)
    traceroute 8.8.8.8 vrf management
  • SSH to another device through the management VRFCisco NX-OS · EXEC (#)
    ssh [email protected] vrf management
  • Run the commands that follow in one VRFCisco NX-OS · EXEC (#)
    routing-context vrf management

Static routing #

  • Add a static routeCisco NX-OS · Global config (config)#
    ip route 10.20.0.0/16 192.168.1.254
  • Add a default routeCisco NX-OS · Global config (config)#
    ip route 0.0.0.0/0 203.0.113.1
  • Add a static route in a VRFCisco NX-OS · Global config (config)#
    vrf context TENANT-A ip route 10.20.0.0/16 192.168.1.254
  • Remove a static routeCisco NX-OS · Global config (config)#
    no ip route 10.20.0.0/16 192.168.1.254
  • Show the routing tableCisco NX-OS · EXEC (#)
    show ip route
  • Show static routesCisco NX-OS · EXEC (#)
    show ip route static
  • Show which route a destination usesCisco NX-OS · EXEC (#)
    show ip route 10.20.1.5

OSPF #

  • Start OSPF and set the router IDCisco NX-OS · Global config (config)#
    feature ospf router ospf 1 router-id 1.1.1.1
  • Turn on OSPF on an interfaceCisco NX-OS · Global config (config)#
    interface Ethernet1/1 ip router ospf 1 area 0.0.0.0
  • Stop OSPF sending hellos on an interfaceCisco NX-OS · Global config (config)#
    interface Vlan10 ip ospf passive-interface
  • Treat a link as point-to-point in OSPFCisco NX-OS · Global config (config)#
    interface Ethernet1/1 ip ospf network point-to-point
  • Set an interface's OSPF costCisco NX-OS · Global config (config)#
    interface Ethernet1/1 ip ospf cost 10
  • Show OSPF neighboursCisco NX-OS · EXEC (#)
    show ip ospf neighbors
  • Show which interfaces run OSPFCisco NX-OS · EXEC (#)
    show ip ospf interface brief
  • Show routes learned from OSPFCisco NX-OS · EXEC (#)
    show ip route ospf-1

BGP #

  • Start BGP and set the router IDCisco NX-OS · Global config (config)#
    feature bgp router bgp 65001 router-id 1.1.1.1
  • Add a BGP neighbourCisco NX-OS · Global config (config)#
    router bgp 65001 neighbor 203.0.113.1 remote-as 65000 address-family ipv4 unicast
  • Advertise a network in BGPCisco NX-OS · Global config (config)#
    router bgp 65001 address-family ipv4 unicast network 198.51.100.0/24
  • Show BGP neighbours and their stateCisco NX-OS · EXEC (#)
    show bgp ipv4 unicast summary
  • Show the BGP tableCisco NX-OS · EXEC (#)
    show bgp ipv4 unicast
  • Show the routes you're sending to a neighbourCisco NX-OS · EXEC (#)
    show bgp ipv4 unicast neighbors 203.0.113.1 advertised-routes
  • Ask a neighbour to resend its routes without dropping the sessionCisco NX-OS · EXEC (#)
    clear bgp ipv4 unicast 203.0.113.1 soft in

Gateway redundancy (HSRP) #

  • Share a gateway address between two switchesCisco NX-OS · Global config (config)#
    feature hsrp feature interface-vlan interface Vlan10 hsrp 10 ip 192.168.10.1 priority 110 preempt
  • Show HSRP groups and which switch is activeCisco NX-OS · EXEC (#)
    show hsrp brief

Access lists #

  • Create an ACL that only allows web traffic to a serverCisco NX-OS · Global config (config)#
    ip access-list WEB-IN permit tcp any host 192.168.1.20 eq 443 deny ip any any log
  • Count how many packets hit each line of an ACLCisco NX-OS · Global config (config)#
    ip access-list WEB-IN statistics per-entry
  • Apply an ACL to traffic coming into a routed interfaceCisco NX-OS · Global config (config)#
    interface Ethernet1/1 ip access-group WEB-IN in

    Warning: Anything the ACL doesn't permit is blocked. Make sure you have another way in, such as the console, before you apply it over SSH.

  • Apply an ACL to traffic coming into a switch portCisco NX-OS · Global config (config)#
    interface Ethernet1/1 ip port access-group WEB-IN in

    Warning: Anything the ACL doesn't permit is blocked.

  • Only allow SSH from addresses in an ACLCisco NX-OS · Global config (config)#
    line vty access-class MGMT in

    Warning: Make sure you have another way in, such as the console, before you apply it over SSH.

  • Show ACLs and their hit countsCisco NX-OS · EXEC (#)
    show ip access-lists

TACACS+, logging and SNMP #

  • Add a TACACS+ serverCisco NX-OS · Global config (config)#
    feature tacacs+ tacacs-server host 192.168.1.6 key MyTacacsKey aaa group server tacacs+ TACACS server 192.168.1.6 use-vrf management
  • Log in with TACACS+, falling back to local usersCisco NX-OS · Global config (config)#
    aaa authentication login default group TACACS local
  • List local users and their rolesCisco NX-OS · EXEC (#)
    show user-account
  • Show what each role is allowed to doCisco NX-OS · EXEC (#)
    show role
  • Show the SSH server's settingsCisco NX-OS · EXEC (#)
    show ssh server
  • Send logs to a syslog server through the management VRFCisco NX-OS · Global config (config)#
    logging server 192.168.1.5 6 use-vrf management
  • Clear the log fileCisco NX-OS · EXEC (#)
    clear logging logfile
  • Set a read-only SNMP communityCisco NX-OS · Global config (config)#
    snmp-server community MyReadOnlyString group network-operator
  • Create an SNMPv3 userCisco NX-OS · Global config (config)#
    snmp-server user monitor network-operator auth sha MyAuthPass priv aes-128 MyPrivPass
  • Check the time and NTP syncCisco NX-OS · EXEC (#)
    show ntp peer-status

Troubleshooting #

  • Ping an addressCisco NX-OS · EXEC (#)
    ping 192.168.1.1
  • Ping 100 times from a chosen source addressCisco NX-OS · EXEC (#)
    ping 8.8.8.8 source 10.0.0.1 count 100
  • Trace the route to an addressCisco NX-OS · EXEC (#)
    traceroute 8.8.8.8
  • Capture traffic to and from the switch itself on the management portCisco NX-OS · EXEC (#)
    ethanalyzer local interface mgmt limit-captured-frames 50
  • Copy a port's traffic to another port (SPAN)Cisco NX-OS · Global config (config)#
    interface Ethernet1/48 switchport switchport monitor monitor session 1 source interface Ethernet1/1 both destination interface Ethernet1/48 no shut
  • Show SPAN sessionsCisco NX-OS · EXEC (#)
    show monitor session all
  • List crash filesCisco NX-OS · EXEC (#)
    show cores
  • Gather everything Cisco support asks forCisco NX-OS · EXEC (#)
    show tech-support details

Upgrades and automation #

  • Show which image the switch bootsCisco NX-OS · EXEC (#)
    show boot
  • Check what an upgrade would do before running itCisco NX-OS · EXEC (#)
    show install all impact nxos bootflash:nxos64-cs.10.3.4a.M.bin
  • Upgrade NX-OSCisco NX-OS · EXEC (#)
    install all nxos bootflash:nxos64-cs.10.3.4a.M.bin

    Warning: Reloads the switch unless the upgrade can be done without disruption. Check the impact first and save the config.

  • Turn on the NX-API for scripts and toolsCisco NX-OS · Global config (config)#
    feature nxapi
  • Allow the Linux shell on the switchCisco NX-OS · Global config (config)#
    feature bash-shell
  • Open a Linux shell on the switchCisco NX-OS · EXEC (#)
    run bash
  • Run a Linux shell commandCisco NX-OS · EXEC (#)
    run bash df -h