Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Modifying the Configuration for a Device

 

Junos CLI enables you to modify an existing Junos OS configuration. This section also explains the specifics of adding a statement, deleting a statement, copying a statement, and inserting a new identifier, including examples.

Displaying Users Currently Editing the Junos OS Configuration

To display the users currently editing the configuration, use the status configuration mode command:

The system displays who is editing the configuration (rchen), where the user is logged in (terminal p0), the date and time the user logged in (2018-03-01 13:17:25 PST), and what level of the hierarchy the user is editing ([edit interfaces]).

If you issue the status configuration mode command and a user has scheduled a candidate configuration to become active for a future time, the system displays who scheduled the commit (root), where the user is logged in (terminal d0), the date and time the user logged in (2018-10-31 14:55:15 PST), and that a commit is pending (commit at).

If you issue the status configuration mode command and a user is editing the configuration in configure exclusive mode, the system displays who is editing the configuration (root), where the user is logged in (terminal d0), the date and time the user logged in (2018-11-01 13:05:11 PST), and that a user is editing the configuration in configure exclusive mode (exclusive [edit]).

Modifying the Junos OS Configuration

To configure a device running Junos OS or to modify an existing Junos OS configuration, you add statements to the configuration. For each statement hierarchy, you create the hierarchy starting with a statement at the top level and continuing with statements that move progressively lower in the hierarchy.

To modify the hierarchy, you use two configuration mode commands:

  • edit—Moves to a specified hierarchy level. If that hierarchy level does not exist, the edit command creates it. The edit command has the following syntax:

  • set—Creates a configuration statement and sets identifier values. After you issue a set command, you remain at the same level in the hierarchy. The set command has the following syntax:

    statement-path is the hierarchy to the configuration statement and the statement itself. If you have already moved to the statement’s hierarchy level, you can omit the statement path. statement is the configuration statement itself. identifier is a string that identifies an instance of a statement.

Note

You cannot use the edit command to change the value of identifiers. You must use the set command.

Adding Junos OS Configuration Statements and Identifiers

All properties of a device running Junos OS are configured by including statements in the configuration. A statement consists of a keyword, which is fixed text, and, optionally, an identifier. An identifier is an identifying name which you define, such as the name of an interface or a username, and which allows you and the CLI to discriminate among a collection of statements.

For example, the following list shows the statements available at the top level of configuration mode:

user@host# set ?

An angle bracket ( > ) before the statement name indicates that it is a container statement and that you can define other statements at levels below it. If there is no angle bracket ( > ) before the statement name, the statement is a leaf statement; you cannot define other statements at hierarchy levels below it.

A plus sign (+) before the statement name indicates that it can contain a set of values. To specify a set, include the values in brackets. For example:

In some statements, you can include an identifier. For some identifiers, such as interface names, you must specify the identifier in a precise format. For example, the interface name so-0/0/0 refers to a SONET/SDH interface that is on the Flexible PIC Concentrator (FPC) in slot 0, in the first PIC location, and in the first port on the Physical Interface Card (PIC).

For other identifiers, such as interface descriptive text and policy and firewall term names, you can specify any name, including special characters, spaces, and tabs.

You must enclose in quotation marks (double quotes) identifiers and any strings that include a space or tab character or any of the following characters:

If you do not type an option for a statement that requires one, a message indicates the type of information required. In this example, you need to type an area number to complete the command:

Deleting a Statement from a Junos OS Configuration

To delete a statement or identifier from a Junos OS configuration, use the delete configuration mode command. Deleting a statement or an identifier effectively "unconfigures" the functionality associated with that statement or identifier, returning that functionality to its default condition.

When you delete a statement, the statement and all its subordinate statements and identifiers are removed from the configuration.

For statements that can have more than one identifier, when you delete one identifier, only that identifier is deleted. The other identifiers in the statement remain.

To delete the entire hierarchy starting at the current hierarchy level, do not specify a statement or an identifier in the delete command. When you omit the statement or identifier, you are prompted to confirm the deletion:

[edit]
user@host# delete
Note

You cannot delete multiple statements or identifiers within a hierarchy using a single delete command. You must delete each statement or identifier individually using multiple delete commands. For example, consider the following configuration at the [edit system] hierarchy level:

To delete the domain-name, host-name, and backup-router from the configuration, you cannot issue a single delete command. For example, the following command would not work:

user@host> delete system hostname host-211 domain-name domain-122 backup-router 192.168.71.254

Instead, you must delete each statement individually:

user@host delete system host-name host-211
user@host delete system domain-name domain-122
user@host delete system backup-router 192.168.71.254

Example: Deleting a Statement from the Junos OS Configuration

The following example shows how to delete the ospf statement, effectively unconfiguring OSPF on the router:

Delete all statements from the current level down:

Unconfigure a specific property, in this case, removing the interface speed setting:

Copying a Junos OS Statement in the Configuration

When you have many similar statements in a Junos configuration, you can add one statement and then make copies of that statement. Copying a statement duplicates that statement and the entire hierarchy of statements configured under that statement. Copying statements is useful when you are configuring many physical or logical interfaces of the same type.

To make a copy of an existing statement in the configuration, use the configuration mode copy command:

Immediately after you have copied a portion of the configuration, the configuration might not be valid. You must check the validity of the new configuration, and if necessary, modify either the copied portion or the original portion for the configuration to be valid.

Example: Copying a Statement in the Junos Configuration

This example shows how you can create one virtual connection (VC) on an interface by copying an existing VC.

Requirements

No special configuration beyond device initialization is required before configuring this example.

Before you begin this example, configure the following initial configuration.

To quickly configure the initial configuration for this example, copy the following commands, paste it into a text file, remove any line breaks and change any details necessary to match your network configuration, copy and paste this command into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

Overview

Copying statements is useful when you are configuring many physical or logical interfaces of the same type. You can add one statement and then make copies of that statement. Copying a statement duplicates that statement and the entire hierarchy of statements configured under that statement. In the case of this example, we are adding a virtual connection that is very similar to a virtual connection already configured.

Configuration

CLI Quick Configuration

Start at the [edit interfaces at-1/0/0] hierarchy level.

Configuring by Copying

Step-by-Step Procedure

To configure by copying a configuration:

  1. Go to the [edit interfaces at-1/0/0] hierarchy level and copy unit 61.
  2. Take a look at the new configuration and see what you need to change to make the configuration valid..
  3. Change the configuration to make it valid.

    In this example you want to reconfigure the virtual circuit identifier (VCI) and virtual path identifier (VPI).

    You also want to replace the IP address of the new interface with its own IP address.

Results

Example: Re-Using Configuration

If you need to make changes to the configuration of a device, you can always remove the original configuration settings using the delete command and add your new configuration settings using the set command. However, there are other ways of modifying a configuration that are more efficient and easier to use.

This example shows how to use the following configuration mode commands to update an existing configuration:

  • rename—Rename an existing configuration setting, such as an interface name. This can be useful when you are adding new interfaces to a device.

  • copy—Copy a configuration setting and the entire hierarchy of statements configured under that setting. Copying configuration statements is useful when you are configuring many physical or logical interfaces of the same type.

  • replace—Make global changes to text patterns in the configuration. For example, if you consistently misspell a word common to the description statement for all of the interfaces on your device, you can fix this mistake with a single command.

Requirements

No special configuration beyond device initialization is required before configuring this example.

Overview

During the first example in this topic, you will make the following configuration changes:

  • Create a new interface with a description that contains a typing error.

  • Copy the configuration from the interface that you created to create a new interface.

  • Rename one of the interfaces that you created.

  • Fix the typing error in the description for the interfaces that you created.

In the second, shorter example, you will experiment with some of the same commands under slightly different circumstances.

Configuration

CLI Quick Configuration

This example does not use commands that are suitable for this section.

Using the Copy, Rename, and Replace Commands to Modify a Loopback Interface Configuration

Step-by-Step Procedure

Caution

If your existing configuration uses any of the loopback interface unit numbers used in this example, you must substitute different unused loopback interface unit numbers. Otherwise, following these steps could damage the existing operational status of your device.

To create and modify a configuration of a loopback interface using the copy, rename, and replace commands:

  1. Create a new loopback interface unit number and include a description.

    The mistakes in the spelling of loopback in the description are intentional.

  2. Display the configuration for the loopback interface you have just added.
  3. Duplicate the loopback interface you have just created, warts and all, from unit 100 to unit 101.
  4. Display the configurations for loopback interfaces lo0 unit 100 and lo0 unit 101.

    The copy command duplicates an interface including any child statements such as description.

  5. Rename the loopback interface lo0 unit 100 to loopback interface lo0 unit 102.
  6. Display the configuration for loopback interface lo0 unit 100.

    You should not see any results from this command. The loopback interface lo0 unit 100 is now gone. The rename command replaces the configuration statement indicated with the new configuration.

  7. Fix the misspelling of the word loopback in the descriptions for loopback interfaces lo0 unit 101 and lo0 unit 102.
  8. Display the configuration for loopback interfaces lo0 unit 101 and lo0 102 to verify that the word loopback is spelled correctly now.

    The replace command replaces all instances of the pattern specified in the command, unless limited in some way. The next example in this topic shows one way to limit the effect of the replace command.

  9. From configuration mode, use the rollback command to put the device’s configuration back to the state it was in before you executed the previous steps.

Results

From configuration mode, use the show interfaces lo0 unit 101 and show interfaces lo0 unit 102 commands to ensure that the device’s configuration is back to the state it was in before you executed the steps in this example.

You should not see any results from this command.

You should not see any results from this command.

Compare the Copy Command at the Top-Level Configuration Hierarchy Level

Step-by-Step Procedure

The previous example shows the copy, rename, and replace commands at the [edit interfaces interface-name unit logical-interface-number] hierarchy level. This example shows how some of these commands work at the top level of the CLI configuration mode hierarchy.

The following example requires you to navigate to various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode .

  1. Create an Ethernet interface.
  2. Copy the interface you just created to another interface.

    Compare this copy command to the one in the previous example, where the copy command takes the keyword unit before the value to be copied:

    Notice that the keyword interfaces is not repeated after the preposition to and before the value to be copied. This happens in some top-level statements with the copy command.

    Tip

    Similarly, in the rename command, you do not repeat the keyword part of the statement before the new identifier in some top-level statements.

  3. Show your configuration so far.
  4. Replace the address for et-2/1/0 with another IP address.

    Notice that if you want to change only a specific occurrence of a pattern instead of all of them, you need to navigate down to that specific hierarchy level before using the replace command.

  5. Show the interfaces again.
  6. From configuration mode, use the rollback command to put the device’s configuration back to the state it was in before you executed the previous steps.

Results

From configuration mode, use the show interfaces et-2/0/0 and show interfaces et-2/1/0 commands to ensure that the device’s configuration is back to the state it was in before you executed the steps in this example.

You should not see any results from this command.

You should not see any results from this command.

Inserting a New Identifier in a Junos OS Configuration

When configuring a device running Junos OS, you can enter most statements and identifiers in any order. Regardless of the order in which you enter the configuration statements, the CLI always displays the configuration in a strict order. However, there are a few cases where the ordering of the statements matters because the configuration statements create a sequence that is analyzed in order.

For example, in a routing policy or firewall filter, you define terms that are analyzed sequentially. Also, when you create a named path in dynamic MPLS, you define an ordered list of the transit routers in the path, starting with the first transit router and ending with the last one.

To modify a portion of the configuration in which the statement order matters, use the insert configuration mode command:

If you do not use the insert command, but instead simply configure the identifier, it is placed at the end of the list of similar identifiers.

Example: Inserting a New Identifier in a Junos Configuration

This example shows the use of the insert command.

Whereas a term added using the set command is placed at the end of the existing list of terms, you use the insert command to add a term in the order you specify. Specifying the order of statement is important in the cases in which the order of the statements matters because the configuration statements create a sequence that is analyzed in order.

As this example shows, you must create the term (or it must already exist), before you can place it using the insert command. The reference point for placing the term must also exist, for example, to place the term T1 before the term T2, both T1 and T2 must already exist, and be populated (Junos automatically removes empty terms).

Requirements

Before you can insert a term, you must configure an initial policy. To quickly configure the initial policy for this example, copy the following commands, paste them into a text file, remove any line breaks and change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit policy-options] hierarchy level, and then enter commit from configuration mode.

Now check to verify you have the hierarchy correctly configured.

Overview

When configuring a device running Junos OS, you can enter most statements and identifiers in any order. However, there are a few cases, such as in routing policies or firewall filters, in which the order of the statements matters because the configuration statements create a sequence that is analyzed in order.

To modify a portion of the configuration in which the statement order matters, you must use the insert configuration mode command. If you use the set command instead, the added statement or identifier will be in the wrong place sequentially. The only other way to get the terms of the command in the correct order is to dismantle the configuration and start over.

Configuration

CLI Quick Configuration

To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks and change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit policy-options] hierarchy level, and then enter commit from configuration mode.

Configuring to Insert Terms

Step-by-Step Procedure

  1. Determine in what order the terms in your configuration need to go, both the original terms and the new terms you plan to add.

    In the original configuration, the policy is named statics and there are four terms. Each of the first three terms matches on a different match criteria and the resulting matches are rejected. The last term accepts all the rest of the traffic.

    In this example, you need to add two terms that eliminate additional types of traffic. Both these terms need to go before the last term in the original configuration.

  2. Rename original term4 to term6.

    This step preserves the original last term, now renamed term6, as the last term.

  3. Create a new term4.

    A new term is added that matches traffic from local system addresses and rejects it.

  4. Create new term5.

    A new term is added that matches traffic from aggregate routes and rejects it.

  5. Insert term4 after term3.
  6. Insert term5 after term4.

Results

Renaming an Identifier in a Junos OS Configuration

When modifying a Junos configuration, you can rename an identifier that is already in the configuration. You can do this either by deleting the identifier (using the delete command) and then adding the renamed identifier (using the set and edit commands), or you can rename the identifier using the rename configuration mode command:

Deactivating and Reactivating Statements and Identifiers in a Junos OS Configuration

In a Junos OS configuration, you can deactivate statements and identifiers so they do not take effect when you issue the commit command. Any deactivated statements and identifiers are marked with the inactive tag. They remain in the configuration but are not activated when you issue a commit command.

To deactivate a statement or identifier, use the deactivate configuration mode command:

To reactivate a statement or identifier, use the activate configuration mode command:

In both commands, the statement and identifier you specify must be at the current hierarchy level. When you deactivate a statement, that specific statement is ignored and is not applied at all when you issue a commit command.

To disable a statement, use the disable configuration mode command:

In some portions of the configuration hierarchy, you can include a disable statement to disable functionality. One example is disabling an interface by including the disable statement at the [edit interface interface-name] hierarchy level. When you disable a functionality, it is activated when you issue a commit command but is treated as though it is down or administratively disabled.

Example: Deactivating and Reactivating Statements and Identifiers in a Junos OS Configuration

This example shows a common use case in which the deactivate and activate configuration mode commands are used. It involves dual Routing Engines, master and backup, that have graceful Routing Engine switchover (GRES) configured. The software on both Routing Engines needs to be upgraded. This can easily be accomplished by deactivating GRES, updating the Routing Engines, and then reactivating GRES.

Note

You can also perform a similar upgrade using the same setup except that nonstop active routing (NSR) is configured instead of GRES. You would need to deactivate NSR and then upgrade the Routing Engines before reactivating NSR.

Requirements

This example requires the use of a device with dual Routing Engines that can be upgraded.

Before you begin this example, make sure that you have GRES configured.

Overview

In this example, there are two Routing Engines. GRES is configured, and the Routing Engines need to be upgraded. To accomplish the upgrading, you need to deactivate the GRES feature, upgrade each of the Routing Engines, and then activate GRES again.

Configuration

Configuring the Deactivation and Reactivation of GRES

Step-by-Step Procedure

To deactivate and reactivate GRES for Routing Engine upgrade:

  1. Show that GRES is enabled for the router.
    user@host# show chassis
  2. Deactivate GRES.
  3. Show that GRES is deactivated.
    user@host# show chassis
  4. Upgrade the Routing Engines one by one.

    For instructions on upgrading Junos OS on dual Routing Engines, see Installing the Software Package on a Device with Redundant Routing Engines.

  5. Reactivate GRES.

Results

Verify that GRES feature is activated again.

user@host# show chassis

Using Global Replace in the Junos OS Configuration

You can make global changes to variables and identifiers in the Junos OS configuration by using the replace configuration mode command. This command replaces a pattern in a configuration with another pattern. For example, you can use this command to find and replace all occurrences of an interface name when a PIC is moved to another slot in the router.

pattern pattern1 is a text string or regular expression that defines the identifiers and values you want to replace in the configuration.

pattern2 is a text string or regular expression that replaces the identifiers and values located with pattern1.

Juniper Networks uses standard UNIX-style regular expression syntax (as defined in POSIX 1003.2). If the regular expression contains spaces, operators, or wildcard characters, enclose the expression in quotation marks. Greedy qualifiers (match as much as possible) are supported. Lazy qualifiers (match as little as possible) are not.

The upto n option specifies the number of objects replaced. The value of n controls the total number of objects that are replaced in the configuration (not the total number of times the pattern occurs). Objects at the same hierarchy level (siblings) are replaced first. Multiple occurrences of a pattern within a given object are considered a single replacement. For example, if a configuration contains a 010101 text string, the command replace pattern 01 with pattern 02 upto 2 replaces 010101 with 020202 (instead of 020201). Replacement of 010101 with 020202 is considered a single replacement (n = 1), not three separate replacements (n =3).

If you do not specify an upto option, all identifiers and values in the configuration that match pattern1 are replaced.

The replace command is available in configuration mode at any hierarchy level. All matches are case-sensitive.

Common Regular Expressions to Use with the replace Command

Table 1: Common Regular Expressions to Use with the replace Command

Operator

Function

|

Indicates that a match can be one of the two terms on either side of the pipe.

^

Used at the beginning of an expression, denotes where a match should begin.

$

Used at the end of an expression, denotes that a term must be matched exactly up to the point of the $ character.

[ ]

Specifies a range of letters or digits to match. To separate the start and end of a range, use a hyphen ( - ).

( )

Specifies a group of terms to match. Stored as numbered variables. Use for back references as \1 \2 .... \9.

*

0 or more terms.

+

One or more terms.

.

Any character except for a space (" ").

\

A backslash escapes special characters to suppress their special meaning. For example, \. matches . (period symbol).

\n

Back reference. Matches the nth group.

&

Back reference. Matches the entire match.

The following table lists some replacement examples.

Table 2: Replacement Examples

Command

Result

replace pattern myrouter with router1

Match: myrouter

Result: router1

replace pattern "192\.168\.(.*)/24" with "10.2.\1/28"

Match: 192.168.3.4/24

Result: 10.2.3.4/28

replace pattern "1.\1" with "abc&def"

Match: 1.1

Result: abc1.1def

replace pattern 1.1 with " abc\&def"

Match: 1#1

Result: abc&def

Example: Using Global Replace in a Junos OS Configuration—Using the \n Back Reference

This example shows how you can use a backreference to replace a pattern.

Requirements

No special configuration beyond device initiation is required before configuring this example.

Before you begin, configure the following:

To quickly configure this initial configuration, copy the following commands and paste them in a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the [edit] hierarchy level:

Overview

One of the most useful features of regular expressions is the backreference. Backreferences provide a convenient way to identify a repeated character or substring within a string. Once you find the pattern, you can repeat it without writing it again. You refer to the previously captured pattern with just \# (where # is a numeral that indicates the number of times you want the pattern matched).

You can use backreferences to recall, or find, data and replace it with something else. In this way you can reformat large sets of data with a single replace command, thus saving you the time it would take to look for and replace the pattern manually.

Configuration

Configuring a Replacement Using a Backreference in the Command

Step-by-Step Procedure

To replace a pattern in a Junos OS configuration using a backreference:

  • Use the replace command.

    In this case, we want to replace :1bf5with 1bf5.

    Notice the backreference (\1), which indicates the pattern should be searched for and replaced only once.

Results

Here is the resulting configuration:

In this example, the pattern 2000::c0a8::1bf5 is replaced with 2000::c0a8:1bf5 once.

Example: Using Global Replace in a Junos OS Configuration—Replacing an Interface Name

This example shows how to replace an interface name globally in a configuration by using the replace command.

Using the replace command can be a faster and better way to change a configuration. For example, a PIC might be moved to another slot in a router, which changes the interface name. With one command you can update the whole configuration. Or you might want to quickly extend the configuration with other similar configurations, for example, similar interfaces.

By using a combination of the copy and replace commands, you can add to a configuration and then replace certain aspects of the newly copied configurations. The replace command works with regular expressions. Regular expressions are quick, flexible, and ubiquitous. You can fashion just about any pattern you might need to search for, and most programming languages support regular expressions.

Requirements

No special configuration beyond device initialization is required before configuring this example.

Before you begin, configure the following hierarchy on the router. To quickly configure this hierarchy, see CLI Quick Configuration .

Overview

This example shows how to replace an interface name globally in a configuration by using the replace command. It is a simple example.

The previous configuration is the starting point for this configuration update. In the course of this example, you change the name of the initial interface throughout the configuration with one command.

Configuration

CLI Quick Configuration

To quickly configure the initial configuration for this example, copy the following commands, paste them into a text file, remove any line breaks and change any details necessary to match your network configuration, copy and paste these commands into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.:

Configuring an Interface Name Change

Step-by-Step Procedure

To change an interface name:

  1. Make sure that you are at the top of the configuration mode hierarchy.
  2. Replace so-0/0/0 with so-1/1/0 using the replace command, which uses the pattern keyword.

Results

After making the required changes, verify the configuration by using the show interfaces and show protocols configuration mode commands.

After you have confirmed that the configuration is correct, enter the commit command.

Example: Using Global Replace in a Junos OS Configuration—Using the upto Option

Consider the hierarchy shown in Figure 1. The text string 010101 appears in three places: the description sections of ge-0/0/0, ge-0/0/0.0, and fe-0/0/1. These three instances are three objects. The following example shows how you can use the upto option to perform replacements in a JUNOS configuration:

Figure 1: Replacement by Object
Replacement by Object

An upto 2 option in the replace command converts 01 to 02 for two object instances. The objects under the main interfaces ge-0/0/0 and fe-0/0/1 will be replaced first (since these are siblings in the hierarchy level). Because of the upto 2 restriction, the replace command replaces patterns in the first and second instance in the hierarchy (siblings), but not the third instance (child of the first instance).

The Junos OS command-line interface (CLI) enables you to delete related configuration items simultaneously, such as channelized interfaces or static routes, by using a single command and regular expressions. Deleting a statement or an identifier effectively “unconfigures” the functionality associated with that statement or identifier, returning that functionality to its default condition.

You can only delete certain parts of the configuration where you normally put multiple items, for example, interfaces. However, you cannot delete "groups" of different items; for example:

When you delete a statement, the statement and all its subordinate statements and identifiers are removed from the configuration.

To delete related configuration items, issue the wildcard configuration mode command with the delete option and specify the statement path, the items to be summarized with a regular expression, and the regular expression.

Note

When you use the wildcard command to delete related configuration items, the regular expression must be the final statement.

If the Junos OS matches more than eight related items, the CLI displays only the first eight items.

Deleting Interfaces from the Configuration

Delete multiple T1 interfaces in the range from t1-0/0/0:0 through t1-0/0/0:23:

Deleting Routes from the Configuration

Delete static routes in the range from 172.0.0.0 to 172.255.0.0:

Adding Comments in a Junos OS Configuration

You can include comments in a Junos configuration to describe any statement in the configuration. You can add comments interactively in the CLI and by editing the ASCII configuration file.

When configuring interfaces, you can add comments about the interface by including the description statement at the [edit interfaces interface-name] hierarchy level. Any comments you include appear in the output of the show interfaces commands. For more information about the description statement, see the Junos OS Network Interfaces Library for Routing Devices.

Adding Comments in the CLI

When you add comments in configuration mode, they are associated with a statement at the current level. Each statement can have one single-line comment associated with it. Before you can associate a comment with a statement, the statement must exist. The comment is placed on the line preceding the statement.

To add comments to a configuration, use the annotate configuration mode command:

statement is the configuration statement to which you are attaching the comment; it must be at the current hierarchy level. If a comment for the specified statement already exists, it is deleted and replaced with the new comment.

comment-string is the text of the comment. The comment text can be any length, and you must type it on a single line. If the comment contains spaces, you must enclose it in quotation marks. In the comment string, you can include the comment delimiters /* */ or #. If you do not specify any, the comment string is enclosed with the /* */ comment delimiters.

To delete an existing comment, specify an empty comment string:

If you add comments with the annotate command, you can view the comments within the configuration by entering the show configuration mode command or the show configuration operational mode command.

Note

The Junos OS supports annotation up to the last level in the configuration hierarchy, including oneliners. However, annotation of parts (the child statements or identifiers within the oneliner) of the oneliner is not supported. For example, in the following sample configuration hierarchy, annotation is supported up to the level 1 parent hierarchy, but not supported for the metric child statement:

Adding Comments in a File

When you edit the ASCII configuration file and add comments, they can be one or more lines and must precede the statement they are associated with. If you place the comments in other places in the file, such as on the same line following a statement or on a separate line following a statement, they are removed when you use the load command to open the configuration into the CLI.

The following excerpt from a configuration example illustrates how to place and how not to place comments in a configuration file:

When you include comments in the configuration file directly, you can format comments in the following ways:

  • Start the comment with a /* and end it with a */. The comment text can be on a single line or can span multiple lines.

  • Start the comment with a # and end it with a new line (carriage return).

Example: Including Comments in a Junos OS Configuration by Using the CLI

Adding comments to a Junos OS configuration makes the configuration file readable and more readily understood by users. Using the Junos OS CLI, you can include comments as you configure by using the annotate statement. In this example, comments are added by using the CLI for an already existing configuration:

Requirements

No special configuration beyond device initialization is required before configuring this example.

Before you add a comment, you must configure the following hierarchy on the router.

To quickly configure the initial configuration for this example, copy the following command, paste it into a text file, remove any line breaks and change any details necessary to match your network configuration, copy and paste this command into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

Now verify that you have this hierarchy configured.

Overview

When you add comments by using the CLI, you do so in configuration mode using the annotate statement. Each comment you add is associated with a statement at the current level. Each statement can have one single-line comment associated with it.

To configure the annotate statement, move to the level of the statement with which you want to associate a comment. To view the comments, go to the top of the configuration hierarchy and use the show command.

Configuration

CLI Quick Configuration

To quickly configure the comments for this example, copy the following commands, paste them into a text file, remove any line breaks and change any details necessary to match your network configuration, copy and paste the commands into the CLI, starting at the [edit] hierarchy level, and then enter commit from configuration mode.

Notice that the commands are moving you down the hierarchy as you annotate different sections of the hierarchy.

Including Comments in the CLI Configuration Mode

Step-by-Step Procedure

This procedure assumes that you have already configured the initial configuration.

To add comments to a configuration:

  1. Move to the first hierarchy level to which you need to add a comment.
  2. Add a comment to the area configuration statement by using the annotate statement.
  3. Move down a level to the interface configuration statement.
  4. Add a comment to interface so-0/0/0.0 by using the annotate statement.

Results

Move to the top of the hierarchy and use the show command to see the comments you added. The comments precede the statement they are associated with.

After you have confirmed that the configuration is correct, enter the commit command.