​Junos Comparing Configuration Files

It is really easy to compare configuration files on Junos. In this post we’ll look at three common scenarios:

  • Comparing configurations from configuration mode
  • Comparing configurations from operational mode
  • Comparing two rollback configurations

To help make the examples below clearer, I have made 11 commits already. Each commit set a description on the lo0 interface and a commit comment as per the table below. The first commit we make will become our tenth rollback configuration.

Commit NumberLo0 Interface DescriptionCommit Comment
1Commit 1 / Rollback 10Commit 1 / Rollback 10
2Commit 2 / Rollback 9Commit 2 / Rollback 9
3Commit 3 / Rollback 8Commit 3 / Rollback 8
4Commit 4 / Rollback 7Commit 4 / Rollback 7
5Commit 5 / Rollback 6Commit 5 / Rollback 6
6Commit 6 / Rollback 5Commit 6 / Rollback 5
7Commit 7 / Rollback 4Commit 7 / Rollback 4
8Commit 8 / Rollback 3Commit 8 / Rollback 3
9Commit 9 / Rollback 2Commit 9 / Rollback 2
10Commit 10 / Rollback 1Commit 10 / Rollback 1
11Commit 11 / Rollback 0Commit 11 / Rollback 0

This is confirmed by looking at the show system commit output on the router.

lab@vMX-3> show system commit 
0   2023-12-29 04:13:22 UTC by lab via cli
    Commit 11 / Rollback 0
1   2023-12-29 04:13:04 UTC by lab via cli
    Commit 10 / Rollback 1
2   2023-12-29 04:12:43 UTC by lab via cli
    Commit 9 / Rollback 2
3   2023-12-29 04:12:24 UTC by lab via cli
    Commit 8 / Rollback 3
4   2023-12-29 04:12:07 UTC by lab via cli
    Commit 7 / Rollback 4
5   2023-12-29 04:11:48 UTC by lab via cli
    Commit 6 / Rollback 5
6   2023-12-29 04:11:29 UTC by lab via cli
    Commit 5 / Rollback 6
7   2023-12-29 04:11:09 UTC by lab via cli
    Commit 4 / Rollback 7
8   2023-12-29 04:10:52 UTC by lab via cli
    Commit 3 / Rollback 8
9   2023-12-29 04:10:35 UTC by lab via cli
    Commit 2 / Rollback 9
10  2023-12-29 04:10:11 UTC by lab via cli
    Commit 1 / Rollback 10

Comparing Configurations From Configuration Mode

When comparing from configuration mode, you are comparing the current candidate configuration file you are working on, with whatever you are making the comparison to. It is a good idea to always check what has changed before making a commit, to ensure you know what configuration is being applied.

Compare To The Current Configuration

To compare your candidate configuration with the current running config you can use either ‘show | compare’ or ‘show | compare rollback 0’. Both will produce the same output.

The lines with a ‘+’ denote lines present in the current file, but not in the old file, which is rollback 0 in this case. The ‘-’ lines denote config that is not present in the current config but was in the comparison config, again, rollback 0 in this case.

ab@vMX-3# show | compare 
[edit interfaces lo0]
-   description "Commit 11 / Rollback 0";
+   description "This Is My New Description";

[edit]
lab@vMX-3# show | compare rollback 0 
[edit interfaces lo0]
-   description "Commit 11 / Rollback 0";
+   description "This Is My New Description";

[edit]
lab@vMX-3#

Compare To A Previous Configuration

To compare your configuration against one of the previous 50, you can specify which rollback to compare to.

[edit]
lab@vMX-3# show | compare rollback 10   
[edit interfaces lo0]
-   description "Commit 1 / Rollback 10";
+   description "This Is My New Description";

[edit]
lab@vMX-3# show | compare rollback 5     
[edit interfaces lo0]
-   description "Commit 6 / Rollback 5";
+   description "This Is My New Description";

[edit]
lab@vMX-3#

Compare To A Saved Configuration

You can also compare against a saved configuration file stored on the local file system by simply specifying the file.

[edit]
lab@vMX-3# show | compare /var/home/lab/test-config.conf 
[edit interfaces lo0]
-   description "This Is A Different Description";
+   description "This Is My New Description";

[edit]
lab@vMX-3#

Note that you can also do this comparison to a remote file. In this example, SCP is used.

[edit]
lab@vMX-3# show | compare scp://[email protected]/home/eve/test-config.conf    
[email protected]'s password: 
test-config.conf                                                                           100% 3466    30.1KB/s   00:00    
[edit interfaces lo0]
-   description "This Is A Different Description";
+   description "This Is My New Description";

[edit]
lab@vMX-3#

Comparing Configurations From Configuration Mode

When performing the comparison from configuration mode there are two key differences:

  • The command is ‘show configuration | compare …’
  • The configuration being compared is the current active configuration, not a candidate configuration.

Everything else remains the same.

lab@vMX-3> show configuration | compare rollback 1                                      
[edit interfaces lo0]
-   description "Commit 10 / Rollback 1";
+   description "Commit 11 / Rollback 0";

lab@vMX-3> show configuration | compare rollback 10                                     
[edit interfaces lo0]
-   description "Commit 1 / Rollback 10";
+   description "Commit 11 / Rollback 0";

lab@vMX-3> show configuration | compare /var/home/lab/test-config.conf                  
[edit interfaces lo0]
-   description "This Is A Different Description";
+   description "Commit 11 / Rollback 0";

lab@vMX-3> show configuration | compare scp://[email protected]/home/eve/test-config.conf 
[email protected]'s password: 
test-config.conf                                                                           100% 3466    28.6KB/s   00:00    
[edit interfaces lo0]
-   description "This Is A Different Description";
+   description "Commit 11 / Rollback 0";

lab@vMX-3>

Comparing Two Rollback Configurations

When we compare two rollbacks, we are comparing two previous configurations against one another. The command is ‘show system rollback compare x y’ where x and y are the two rollback numbers you want to compare.

The one thing I’ve always found a bit confusing is which order the rollbacks should be specified in, and what exactly the output is trying to say. That is why I set the lo0 interface descriptions to include which commit and rollback they should be, to make the following examples clearer.

lab@vMX-3> show system rollback compare 1 2    
[edit interfaces lo0]
-   description "Commit 10 / Rollback 1";
+   description "Commit 9 / Rollback 2";

lab@vMX-3>

In the above output, we know that rollback 1 was the 10th commit, and rollback 2 was the 9th. In this instance, it appears the ‘-’ or removed lines are not present in rollback 2, and the ‘+’ lines are present.

We can reverse the order of the comparison, listing the older rollback first.

lab@vMX-3> show system rollback compare 2 1    
[edit interfaces lo0]
-   description "Commit 9 / Rollback 2";
+   description "Commit 10 / Rollback 1";

lab@vMX-3> 

To me, this output makes more sense. The ‘+’ lines are present in rollback 1 and not in rollback 2, and the ‘-’ lines are not present in rollback 1, but present in rollback 2.

Showing A Previous Rollback Configuration

Sometimes we just want to see the entirety of a previous configuration.

To do this, we can use show system rollback x, where x is the rollback we want to see.

lab@vMX-3> show system rollback 5  
## Last changed: 2023-12-29 04:11:39 UTC
version 20.4R3-S2.6;
system {
    host-name vMX-3;
    root-authentication {
REMAINING OUTPUT REMOVED FOR BREVITY

Leave a Comment

Your email address will not be published. Required fields are marked *