Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Loading Configuration Files

 

Loading configuration files on the device are helpful for loading parts of configuration files that might be common across many devices within a network.

Loading a Configuration from a File or the Terminal

You can create a file containing configuration data for a device running Junos OS, copy the file to the local router, and then load the file into the CLI. After you have loaded the file, you can commit it to activate the configuration on the router, or you can edit the configuration interactively using the CLI and commit it at a later time.

You can also create a configuration while typing at the terminal and then load it. Loading a configuration from the terminal is generally useful when you are cutting existing portions of the configuration and pasting them elsewhere in the configuration.

To load an existing configuration file that is located on the router, use the load configuration mode command:

For information about specifying the filename, see Viewing Files and Directories on a Device Running Junos OS.

To load a configuration from the terminal, use the following version of the load configuration mode command. Press Ctrl-d to end the input.

To replace an entire configuration, specify the override option at any level of the hierarchy. A load override operation completely replaces the current candidate configuration with the file you are loading. Thus, if you saved a complete configuration, use this option.

An override operation discards the current candidate configuration and loads the configuration in filename or the configuration that you type at the terminal. When you use the override option and commit the configuration, all system processes reparse the configuration. .

To replace portions of a configuration, specify the replace option. The load replace operation looks for replace: tags that you added to the loaded file, and replaces the parts of the candidate configuration with whatever is specified after the tag. This is useful when you want more control over exactly what is being changed. For this operation to work, you must include replace: tags in the file or configuration you type at the terminal. The software searches for the replace: tags, deletes the existing statements of the same name, if any, and replaces them with the incoming configuration. If there is no existing statement of the same name, the replace operation adds to the configuration the statements marked with the replace: tag.

If, in an override or merge operation, you specify a file or type text that contains replace: tags, the replace: tags are ignored and the override or merge operation is performed.

If you are performing a replace operation and the file you specify or text you type does not contain any replace: tags, the replace operation is effectively equivalent to a merge operation. This might be useful if you are running automated scripts and cannot know in advance whether the scripts need to perform a replace or a merge operation. The scripts can use the replace operation to cover either case.

The load merge operation merges the configuration from the saved file or terminal with the existing candidate configuration. This is useful if you are adding new configuration sections. For example, suppose that you are adding a BGP configuration to the [edit protocols] hierarchy level, where there was no BGP configuration before. You can use the load merge operation to combine the incoming configuration with the existing candidate configuration. If the existing configuration and the incoming configuration contain conflicting statements, the statements in the incoming configuration override those in the existing configuration.

To replace only those parts of the configuration that have changed, specify the update option at any level of the hierarchy. The load update operation compares the candidate configuration and the new configuration data, and only changes the parts of the candidate configuration that are different from the new configuration. You would use this, for example, if there is an existing BGP configuration and the file you are loading changes it in some way.

The merge, override, and update options support loading configuration data in JavaScript Object Notation (JSON) format. When loading configuration data that uses JSON format, you must specify the json option in the command.

To change part of the configuration with a patch file, specify the patch option. The load patch operation loads a file or terminal input that contains configuration changes. First, on a device that already has the configuration changes, you type the show | compare command to output the differences between two configurations. Then you can load the differences on another router. The advantage of the load patch command is that it saves you from having to copy snippets from different hierarchy levels into a text file prior to loading them into the target device. This might be a useful time saver if you are configuring several devices with the same options. For example, suppose that you configure a routing policy on router1 and you want to replicate the policy configuration on router2, router3, and router4. You can use the load patch operation.

First, run the show | compare command.

user@router1# show | compare rollback 3

Copy the output of the show | compare command to the clipboard, making sure to include the hierarchy levels. On router2, router3, and router4, type load patch terminal and paste the output. Press Enter and then press Ctrl-d to end the operation. If the patch input specifies different values for an existing statement, the patch input overrides the existing statement.

To use the merge, replace, set, or update option without specifying the full hierarchy level, specify the relative option. This option loads the incoming configuration relative to your current edit point in the configuration hierarchy. For example:

To load a configuration that contains set configuration mode commands, specify the set option. This option executes the configuration instructions line by line as they are stored in a file or from a terminal. The instructions can contain any configuration mode command, such as set, edit, exit, and top.

To copy a configuration file from another network system to the local router, you can use the SSH and Telnet utilities, as described in the CLI Explorer.

Note

If you are using Junos OS in a Common Criteria environment, system log messages are created whenever a secret attribute is changed (for example, password changes or changes to the RADIUS shared secret). These changes are logged during the following configuration load operations:

For more information, see the Secure Configuration Guide for Common Criteria and Junos-FIPS.

Understanding Character Encoding on Devices Running Junos OS

Junos OS configuration data and operational command output might contain non-ASCII characters, which are outside of the 7-bit ASCII character set. When displaying operational or configuration data in certain formats or within a certain type of session, Junos OS escapes and encodes these characters using the equivalent UTF-8 decimal character reference.

The Junos OS command-line interface (CLI) attempts to display any non-ASCII characters in configuration data that is emitted in text, set, or JSON format, and similarly attempts to display these characters in command output that is emitted in text format. In the exception cases, which include configuration data in XML format and command output in XML or JSON format, the Junos OS CLI displays the UTF-8 decimal character reference instead. In NETCONF and Junos XML protocol sessions, if you request configuration data or command output that contains non-ASCII characters, the server returns the equivalent UTF-8 decimal character reference for those characters for all formats.

For example, suppose the following user account, which contains the Latin small letter n with a tilde (ñ), is configured on the device running Junos OS.

When you display the resulting configuration in text format, the CLI prints the corresponding character.

[edit]
user@host# show system login user mariap

When you display the resulting configuration in XML format in the CLI or display the configuration in any format in a NETCONF or Junos XML protocol session, the ñ character maps to its equivalent UTF-8 decimal character reference ñ.

When you load configuration data onto a device running Junos OS, you can load non-ASCII characters using their equivalent UTF-8 decimal character reference.

Additional Details About Specifying Junos OS Statements and Identifiers

This topic provides more detailed information about CLI container and leaf statements so that you can better understand how you must specify them when creating ASCII configuration files. It also describes how the CLI performs type checking to verify that the data you entered is in the correct format.

Specifying Statements

Statements are shown one of two ways, either with braces or without:

  • Statement name and identifier, with one or more lower level statements enclosed in braces:

  • Statement name, identifier, and a single identifier:

The statement-name is the name of the statement.

The identifier-name is a name or other string that uniquely identifies an instance of a statement. An identifier is used when a statement can be specified more than once in a configuration.

When specifying a statement, you must specify either a statement name or an identifier name, or both, depending on the statement hierarchy.

You specify identifiers in one of the following ways:

  • identifier-name—The identifier-name is a keyword used to uniquely identify a statement when a statement can be specified more than once in a statement.

  • identifier-name value—The identifier-name is a keyword, and the value is a required option variable.

  • identifier-name [value1 value2 value3 ...]—The identifier-name is a keyword that accepts multiple values. The brackets are required when you specify a set of values; however, they are optional when you specify only one value.

The following examples illustrate how statements and identifiers are specified in the configuration:

When you create an ASCII configuration file, you can specify statements and identifiers in one of the following ways. However, each statement has a preferred style, and the CLI uses that style when displaying the configuration in response to a configuration mode show command.

  • Statement followed by identifiers:

  • Statement followed by identifiers enclosed in braces:

  • For some repeating identifiers, you can use one set of braces for all the statements:

Performing CLI Type Checking

When you specify identifiers and values, the CLI performs type checking to verify that the data you entered is in the correct format. For example, for a statement in which you must specify an IP address, the CLI requires you to enter an address in a valid format. If you have not, an error message indicates what you need to type. Table 1 lists the data types the CLI checks.

Table 1: CLI Configuration Input Types

Data Type

Format

Examples

Physical interface name (used in the [edit interfaces] hierarchy)

type-fpc/pic/port

Correct: so-0/0/1

Incorrect: so-0

Full interface name

type-fpc/pic/port<:channel>.logical

Correct: so-0/0/1.0

Incorrect: so-0/0/1

Full or abbreviated interface name (used in places other than the [edit interfaces] hierarchy)

type-<fpc</pic/port>><<: channel>.logical>

Correct: so, so-1, so-1/2/3:4.5

IP address

0xhex-bytesoctet<.octet<.octet.<octet>>>

Correct: 1.2.3.4, 0x01020304, 128.8.1, 128.8

Sample translations:

1.2.3 becomes 1.2.3.0

0x01020304 becomes 1.2.3.4

0x010203 becomes 0.1.2.3

IP address (destination prefix) and prefix length

0xhex-bytes</length>octet<octet <octet.<octet>>></length>

Correct: 10/8, 128.8/16, 1.2.3.4/32, 1.2.3.4

Sample translations:

1.2.3 becomes 1.2.3.0/32

0x01020304 becomes 1.2.3.4/32

0x010203 becomes 0.1.2.3/32

default becomes 0.0.0.0/0

International Organization for Standardization (ISO) address

hex-nibble<hex-nibble ...>

Correct: 47.1234.2345.3456.00, 47123423453456.00, 47.12.34.23.45.34.56.00

Sample translations:

47123456 becomes 47.1234.56

47.12.34.56 becomes 47.1234.56

4712.3456 becomes 47.1234.56

OSPF area identifier (ID)

0xhex-bytesoctet<.octet<.octet.< octet >>> decimal-number

Correct: 54, 0.0.0.54, 0x01020304, 1.2.3.4

Sample translations:

54 becomes 0.0.0.54

257 becomes 0.0.1.1

128.8 becomes 128.8.0.0

0x010203 becomes 0.1.2.3

Examples: Loading a Configuration from a File

Figure 1: Overriding the Current Configuration
Overriding the Current Configuration
Figure 2: Using the replace Option
Using the replace Option
Figure 3: Using the merge Option
Using the merge Option
Figure 4: Using a Patch File
Using a Patch File
Figure 5: Using the set Option
Using the set Option

Uploading a Configuration File

You can create a configuration file on your local system, copy the file to the switch, and then load the file into the CLI. After you have loaded the configuration file, you can commit it to activate the configuration on the switch. You can also edit the configuration interactively using the CLI and commit it at a later time.

To upload a configuration file from your local system:

  1. Create the configuration file using a text editor such as Notepad, making sure that the syntax of the configuration file is correct. For more information about testing the syntax of a configuration file, see the Junos OS System Basics and Services Command Reference at https://www.juniper.net/documentation/software/junos/index.html.
  2. In the configuration text file, use an option to perform the required action when the file is loaded. Table 2 lists and describes some options for the load command.

    Table 2: Options for the load Command

    OptionsDescription

    merge

    Combines the current active configuration and the configuration in the filename you specify or the one that you type at the terminal. A merge operation is useful when you are adding a new section to an existing configuration. If the active configuration and the incoming configuration contain conflicting statements, the statements in the incoming configuration override those in the active configuration.

    override

    Discards the current candidate configuration and loads the configuration in the filename you specify or the one that you type at the terminal. When you use the override option and commit the configuration, all system processes reparse the configuration. You can use the override option at any level of the hierarchy.

    replace

    Searches for the replace tags, deletes the existing statements of the same name, if any, and replaces them with the incoming configuration. If there is no existing statement of the same name, the replace operation adds the statements marked with the replace tag to the active configuration.

    Note: For this operation to work, you must include replace tags in the text file or in the configuration you type at the terminal.

  3. Press Ctrl+a to select all the text in the configuration file.
  4. Press Ctrl+c to copy the contents of the configuration text file to the Clipboard.
  5. Log in to the switch using your username and password.
  6. Enter configuration mode:

    user@switch> configure

    [edit]

    user@switch#

  7. Load the configuration file:

    [edit]

    user@switch# load merge terminal
  8. At the cursor, paste the contents of the Clipboard using the mouse and the Paste icon:

    [edit]

    user@switch# load merge terminal

    [Type ^D at a new line to end input]

    >Cursor is here. Paste the contents of the clipboard here<
  9. Press Enter.
  10. Press Ctrl+d to set the end-of-file marker.

To view results of the configuration steps before committing the configuration, type the show command at the user prompt.

To commit these changes to the active configuration, type the commit command at the user prompt. You can also edit the configuration interactively using the CLI and commit it at a later time.