# VyOS CLI - Operational Mode and Configuration

> VyOS CLI - operational mode, configuration, set/commit/save commands, version management, and rollback for Yandex Cloud and VK Cloud

Source: https://opennix.org/en/docs/vyos/first-steps/vyos-cli/


VyOS provides a powerful command-line interface for managing the system. The CLI consists of two main modes: operational mode and configuration mode.

## Operational Mode

Operational mode is used to perform system tasks and to inspect the state of the system and its services.

### Key Characteristics

- Lets you perform system tasks without changing the configuration
- Provides a built-in help system
- Supports command auto-completion

### Getting Help

Use `?` to view the available commands:

```
vyos@vyos:~$ ?
Possible completions:
  clear      Clear system information
  configure  Enter configuration mode
  force      Force an operation
  monitor    Monitor system information
  ping       Send ICMP echo requests
  reset      Reset a service
  restart    Restart a service
  show       Show system information
  telnet     Telnet to a node
  traceroute Track network path to node
```

### Auto-Completion

Use the `TAB` key to auto-complete commands:

```
vyos@vyos:~$ sh<TAB>
vyos@vyos:~$ show
```

### Command Families

#### clear

Non-destructive actions, such as resetting counters or clearing logs:

```
vyos@vyos:~$ clear interfaces ethernet eth0 counters
```

#### reset

Locally destructive actions, such as terminating sessions:

```
vyos@vyos:~$ reset vpn ipsec-peer 192.0.2.1
```

#### restart

Restarting subsystems:

```
vyos@vyos:~$ restart service ssh
```

#### force

Forcing certain system actions:

```
vyos@vyos:~$ force arp-cache refresh
```

#### execute

Running diagnostic and helper tasks:

```
vyos@vyos:~$ execute ping 8.8.8.8
```

#### show

Displaying system information:

```
vyos@vyos:~$ show interfaces
vyos@vyos:~$ show ip route
vyos@vyos:~$ show version
```

#### monitor

Continuous output of information (real-time updates):

```
vyos@vyos:~$ monitor interfaces ethernet eth0 traffic
vyos@vyos:~$ monitor log
```

To exit monitoring mode, use `Ctrl+C`.

## Configuration Mode

Configuration mode is used to make changes to the system configuration.

### Entering Configuration Mode

```
vyos@vyos:~$ configure
[edit]
vyos@vyos#
```

Note how the command prompt changes from `~$` to `#`.

### Basic Configuration Commands

#### set

Add or modify a configuration item:

```
vyos@vyos# set interfaces ethernet eth0 address 192.168.1.1/24
vyos@vyos# set interfaces ethernet eth0 description 'LAN Interface'
```

#### delete

Remove a configuration item:

```
vyos@vyos# delete interfaces ethernet eth0 address 192.168.1.1/24
```

#### commit

Apply configuration changes:

```
vyos@vyos# commit
```

**Important**: Changes do not take effect until you run the `commit` command.

#### save

Save the configuration permanently:

```
vyos@vyos# save
Saving configuration to '/config/config.boot'...
Done
```

By default, the configuration is saved to `/config/config.boot`.

#### compare

View the differences between the current working and active configurations:

```
vyos@vyos# compare
[edit interfaces ethernet eth0]
+address 192.168.1.1/24
+description "LAN Interface"
```

#### exit discard

Exit configuration mode without saving changes:

```
vyos@vyos# exit discard
vyos@vyos:~$
```

#### exit

Exit configuration mode while keeping the changes:

```
vyos@vyos# commit
vyos@vyos# exit
vyos@vyos:~$
```

### Navigating the Configuration Hierarchy

The VyOS configuration is organized as a tree hierarchy.

#### edit

Move to a specific configuration level:

```
vyos@vyos# edit interfaces ethernet eth0
[edit interfaces ethernet eth0]
vyos@vyos#
```

Now all commands run in the context of `interfaces ethernet eth0`:

```
[edit interfaces ethernet eth0]
vyos@vyos# set address 192.168.1.1/24
vyos@vyos# set description 'LAN Interface'
```

#### up

Move up one level:

```
[edit interfaces ethernet eth0]
vyos@vyos# up
[edit interfaces]
vyos@vyos#
```

#### top

Move to the root configuration level:

```
[edit interfaces ethernet eth0]
vyos@vyos# top
[edit]
vyos@vyos#
```

#### exit

Exit up one level (similar to `up`):

```
[edit interfaces ethernet eth0]
vyos@vyos# exit
[edit interfaces]
vyos@vyos#
```

## Configuration Management

### Configuration History

VyOS automatically keeps a history of configurations. View the list of saved revisions:

```
vyos@vyos# show system commit
0   2024-10-13 15:30:45 by vyos via cli
1   2024-10-13 14:15:22 by vyos via cli
2   2024-10-13 12:05:10 by vyos via cli
```

### Configuration Rollback

Roll back to a previous configuration revision:

```
vyos@vyos# rollback 1
vyos@vyos# commit
```

Roll back to the last saved configuration:

```
vyos@vyos# rollback
vyos@vyos# commit
```

### Comparing Configurations

Compare the current configuration with a saved revision:

```
vyos@vyos# compare 1
```

Compare two saved revisions:

```
vyos@vyos# compare 1 2
```

### Configuration Comments

Add comments to configuration items for documentation purposes:

```
vyos@vyos# comment interfaces ethernet eth0 address 192.168.1.1/24 "Primary LAN address"
```

View comments:

```
vyos@vyos# show interfaces ethernet eth0
/* Primary LAN address */
address 192.168.1.1/24
description "LAN Interface"
```

### Commit Confirm

For critical changes, you can use a confirmation with a timeout. If the changes are not confirmed within the specified time, the configuration is rolled back automatically:

```
vyos@vyos# commit-confirm 5
```

Confirm the changes within 5 minutes:

```
vyos@vyos# confirm
```

This is useful when changing the network settings of a remote router, so that you avoid losing access.

## Viewing the Configuration

### show

View the current configuration:

```
vyos@vyos# show
```

View a specific part of the configuration:

```
vyos@vyos# show interfaces
vyos@vyos# show interfaces ethernet eth0
```

### show | commands

Display the configuration as `set` commands:

```
vyos@vyos# show interfaces ethernet eth0 | commands
set interfaces ethernet eth0 address '192.168.1.1/24'
set interfaces ethernet eth0 description 'LAN Interface'
```

This is useful for copying a configuration or building scripts.

### show | display-set

An alternative way to display the configuration as `set` commands:

```
vyos@vyos# show | display-set
```

## Loading a Configuration

### load

Load a configuration from a file:

```
vyos@vyos# load /config/backup-config.boot
```

Merge a configuration from a file into the current one:

```
vyos@vyos# merge /config/additional-config.boot
```

## Configuration Archiving

### Local Archiving

VyOS automatically saves every committed revision of the configuration.

Configure the number of retained revisions:

```
set system config-management commit-archive location '/config/archive'
set system config-management commit-revisions 50
```

### Remote Archiving

Configure automatic upload of the configuration to a remote server after every commit:

```
set system config-management commit-archive location 'scp://user@192.0.2.100/backup'
```

## Tips and Recommendations

### Keyboard Shortcuts

- `TAB` - auto-complete a command
- `?` - show available commands
- `Ctrl+A` - move to the beginning of the line
- `Ctrl+E` - move to the end of the line
- `Ctrl+U` - delete everything to the left of the cursor
- `Ctrl+K` - delete everything to the right of the cursor
- `Ctrl+W` - delete the word to the left of the cursor
- `Ctrl+L` - clear the screen
- `Ctrl+C` - interrupt the command

### Command History

- Up/Down arrow - navigate through command history
- `Ctrl+R` - search the command history

### Pipelines

Commands can be piped to filter their output:

```
vyos@vyos# show | grep address
vyos@vyos# show | match "192.168"
```

Available filters:
- `match` - show lines that contain the pattern
- `except` - exclude lines that contain the pattern
- `commands` - show as set commands

### Copy and Paste

When working over a remote session, use copy/paste of the configuration in the form of `set` commands:

```
vyos@vyos# show interfaces ethernet eth0 | commands
```

Copy the output and paste it into another VyOS system.

## Example Workflow

A typical configuration change process:

```
# 1. Enter configuration mode
vyos@vyos:~$ configure
[edit]

# 2. Make changes
vyos@vyos# set interfaces ethernet eth1 address 192.168.2.1/24
vyos@vyos# set interfaces ethernet eth1 description 'DMZ'

# 3. Review the changes
vyos@vyos# compare

# 4. Apply the changes
vyos@vyos# commit

# 5. Save the configuration
vyos@vyos# save

# 6. Exit configuration mode
vyos@vyos# exit
vyos@vyos:~$
```

## Next Steps

Now that you are familiar with the CLI, continue with:

- [Configuration Overview](/docs/vyos/first-steps/vyos-config-overview/) - understanding the configuration structure
- [Configuration](/docs/vyos/) - detailed guide to configuring components
- [Operational Mode](/docs/vyos/admin-guide/vyos-operation-mode/) - advanced operational commands

