Arista EOS CLI: Command Modes and Key Features - 夜莺博客

Arista EOS CLI: Command Modes and Key Features

Arista EOS is famous for its easygoing CLI: command keywords are case-insensitive, unique abbreviations are accepted, aliases let you compress long commands into a few keystrokes, and the shell underneath is a normal Linux prompt. This guide collects the core EOS CLI features documented in the official user manual — access methods, command abbreviation and aliases, regular expressions in BGP, schedule timers, event handlers and terminal settings — so you can work faster in day-to-day operations.

Background: What Makes the EOS CLI Different

EOS borrowed the look and feel of Cisco IOS deliberately. Interface configuration, VLANs, routing protocols and ACLs all read the same way, which is why migrations from IOS are mostly a matter of translation rather than relearning. What is genuinely different sits in the layers around the CLI:

  • The CLI is an application, not the operating system. EOS implements it as FastCli running on a Linux base, so a bash shell is one command away and the running configuration is a readable file.
  • Every show command can emit JSON. The same data that fills an 80-column screen can be parsed by a script, which is the foundation for automation and monitoring.
  • The parser is generous. Keywords are case-insensitive, unique prefixes are accepted, and you can define your own aliases — three small features that compound into a large speed difference over a long troubleshooting session.
  • Automation primitives live in the CLI. schedule runs scripts on a timer and event handlers react to interface or system events, all without an external orchestrator.

Accessing the CLI and How Commands Are Processed

The EOS CLI is reachable over the management interface, the console port, Telnet and SSH. Command keywords are not case-sensitive, and the parser accepts truncations as long as the prefix matches exactly one command:

switch# con
% Ambiguous command            # both "configure" and "connect" match
switch# conf
switch(config)#                # unique match, enter global configuration

Two rules follow from this. First, abbreviations that work in one EOS version may become ambiguous in the next if a new command shares the prefix — keep full command names in production scripts. Second, the parser only reports ambiguity for the token you typed; it does not warn you that a later release will break your abbreviation. Anything that goes into a runbook or an automation template should be spelled out in full.

The Command Modes and Their Prompts

EOS uses the familiar layered structure, and the prompt always shows the current submode. Reading the prompt is faster than re-typing show running-config to work out where you are:

switch>                          # user EXEC (unprivileged)
switch#                          # privileged EXEC
switch(config)#                  # global configuration
switch(config-if-Et1)#           # interface Ethernet1
switch(config-if-Vl10)#          # VLAN interface 10
switch(config-router-bgp)#       # BGP routing process
switch(config-router-ospf)#      # OSPF routing process
switch(config-acl-NAME)#         # named ACL
switch(config-mgmt-api-http-cmds)#  # management API

Navigation is the same as IOS: exit goes back one level, end or Ctrl-Z returns to privileged EXEC, and ? lists the commands or keywords valid at the current position.

Creating Aliases

Aliases expand a short token into any command you type often. Define them in global configuration mode and use them from privileged EXEC:

switch(config)# alias srie show running-config interface ethernet 1-5
switch(config)# srie

Aliases are stored in the running configuration, so they are inherited by everyone who logs in — which is both the point and the risk. Keep them obvious (srie, shinv, logn) and avoid aliasing anything that changes state, because a mistyped two-letter alias that runs a clear command can ruin your afternoon. Use show aliases to list what is currently defined.

History and Syntax Help

The CLI keeps a per-session history buffer, and the ? character asks the parser what fits at the cursor:

switch# show history
switch# ping ?
  WORD  Ping destination address or hostname
  ip    IPv4 echo
  ipv6  IPv6 echo
  mpls  Send echo messages for LSP
  vrf   Ping in a VRF

In a long session, show history is often faster than scrolling: it gives you the last commands verbatim, including the ones you typed an hour ago when you were still exploring. Combine it with the shell — bash gives you pipes, grep and file editing, and everything in /mnt/flash is available from the CLI.

Regular Expressions in BGP

BGP AS-path filtering supports two regex modes, configured with ip as-path regex-mode: asn and string.

  • asn mode treats the AS path as a sequence of AS numbers rather than a string of characters. In this mode . matches any AS number (not any character), ^ anchors the start of the path, $ anchors the end, and _ acts as the AS separator (it matches a comma, brace, space or the beginning/end of the path).
  • string mode treats the AS path as a plain character string, which is the classic Cisco behaviour and what most engineers expect.
switch(config)# ip as-path regex-mode asn
switch(config)# ip as-path access-list 10 permit ^100_200$
! matches exactly the path "100 200"
switch(config)# ip as-path access-list 20 permit ^$
! matches locally originated routes (empty AS path)
switch(config)# router bgp 65001
switch(config-router-bgp)# neighbor 10.0.0.2 filter-list 10 in

Read ^100_200$ as "begins with AS 100, then a separator, then AS 200, then the path ends". Switching a mature configuration from string mode to asn mode changes the meaning of existing filters, because . and _ no longer match the same things — test in a lab before you flip the mode on a production pair.

Scheduled Tasks and Event Automation

EOS can run scripts on a schedule and react to events without any external system. schedule takes an interval in minutes or hours, a timeout so a stuck job does not run forever, and a log-file limit:

# run a script every 12 hours, timeout the job after 40 minutes
switch# schedule ms_1 interval 720 timeout 40 max-log-files 0 command bash /mnt/flash/myscript.sh
switch(config)# show schedule summary

Event handlers trigger an action when something changes — an interface flapping, a process restarting, a log pattern appearing. The typical use is to capture diagnostics the moment a problem starts, which is far more valuable than a report that arrives an hour later:

switch(config)# event-handler track-uplink
switch(config-handler-track-uplink)# trigger on-intf Ethernet1/1 operstatus
switch(config-handler-track-uplink)# action bash /mnt/flash/on-change.sh
switch(config-handler-track-uplink)# delay 10
switch(config-handler-track-uplink)# asynchronous
switch(config)# show event-handler track-uplink
switch(config)# show event-handler track-uplink log

The delay timer prevents a flapping interface from launching the handler repeatedly, and asynchronous stops a slow script from blocking the CLI. Pair an event handler with show ... | json inside the script and you can push a compact structured snapshot to a collector every time an uplink transitions — a cheap, self-contained monitoring solution for branch or lab sites.

Filtering and Piping Show Output

EOS pipes work on the output of any command, which turns a long configuration dump into a single answer. The three filters worth memorising are include, exclude and section, and each can be chained with a JSON or bash escape hatch when the text output stops being enough:

switch# show running-config | include hostname
switch# show running-config | exclude ^!
switch# show running-config | section interface Ethernet1
switch# show interfaces Ethernet1 counters | include errors
switch# show ip route | begin Gateway
switch# show version | json

include keeps only the matching lines, exclude drops them, section prints the matching line plus everything indented under it — which is exactly what you want when you are auditing one interface without scrolling through a thousand lines of unrelated configuration. Because the CLI is a Linux application, you can also reach the shell with bash and run standard tools against the very same data files.

Terminal Settings and Verification

switch# terminal length 0      # disable paging (SSH sessions)
switch# terminal monitor       # display logs on the terminal in real time
switch# show history
switch# show aliases
switch# show schedule summary

terminal length 0 matters more than it looks: without it, a long show command through an SSH session pauses at every screen, and any script that scrapes CLI output will get only the first page. terminal monitor sends syslog from the host to your session, which is how you watch an adjacency come up while you are still typing the configuration.

Troubleshooting the CLI Itself

  • Command rejected but the syntax looks right. You are in the wrong submode. Check the prompt; interface-level commands only exist under an interface, and routing parameters only under router bgp or router ospf.
  • Ambiguous command on a prefix that used to work. A newer EOS release added a command with the same prefix. Use the full command name.
  • Alias does nothing. Aliases defined in one session are only in the running configuration if you saved them; check show aliases and re-enter the alias in config mode.
  • Schedule job never runs. Confirm the script path exists and is executable from bash, and check the schedule's last-run state and log.
  • Event handler fires once and stops. The handler is still running, or the trigger condition never reset. Check show event-handler <name> log and the delay value.
  • Output truncated in a script. Add terminal length 0 before the show command, or use the JSON output, which is not paginated.

FAQ

Are EOS commands case-sensitive? No, keywords are case-insensitive, but configuration values such as hostnames, descriptions and community strings preserve the case you type.

Can I use a Cisco IOS shortcut I rely on? Most commands migrate, but DTP, VTP and HSRP do not exist. Check the translation table before you start cutting and pasting.

Do aliases survive a reboot? Only if the configuration is saved with write memory.

What is the fastest way to script against the CLI? Use show ... | json from the Linux shell or eAPI. Screen-scraping plain text output works but breaks whenever a column is added.

Related Reading

EOS MLAG configuration is covered in Arista EOS MLAG Configuration: Complete Guide and in this site's MLAG peer-link and domain setup walkthrough. EOS automation at scale is covered in Ansible for Network Engineers: Complete Guide and Ansible Jinja2 templates for network device configs. For topology context see Spine-Leaf Architecture: Modern Data Center Topology, and for a full command reference see the Arista EOS configuration cheat sheet alongside the Cisco to Arista EOS migration cheat sheet.

原文链接:https://www.arista.com/en/um-eos/eos-command-line-interface-cli