Configuring the Router by Copying a File from a Server

Problem

You have a router configuration file on a server and you want to copy it to the router and activate it.

Solution

Use the following command to copy the configuration to the router:

aviva@router1> file copy server1: router- base-configuration . aviva@router1's password: router-base-configuration 100% 10KB 10.0KB/s 00:00

Verify that the file has been copied to the router:

aviva@router1> file list /var/home/aviva/: .ssh/ router-base-configuration

Then load the file into the JUNOS CLI:

[edit] aviva@router1# load override router-base-configuration load complete

You should use the show command to review the loaded configuration and make sure it's what you expect:

aviva@router1# show

Then activate the configuration:

[edit] aviva@router1# commit commit complete

 

Discussion

JUNOS configuration files are simply formatted text files, so you can create a configuration file on a server and then load it onto the router. Use the file copy command on the router to copy the file from the server to the router. This command is similar to the Unix scp command. In this example, the file is copied from the user's home directory on the server to her home directory on the router. The home directory is effectively the current directory, so you can type a dot (.) for the directory name, just as in Unix. The explicit path is /var/home/aviva. No text is shown here for the password because the CLI does not echo what you type when you enter the password.

Because the file copy command uses SSH, the server must also be running SSH. (You can use the file copy command because you enabled SSH when you initially configured the router [see Recipe 1.1].)

If the file on the server is not in your home directory, you can specify the full path to the directory. In this example, the file you want to copy is in the /tmp/config directory:

aviva@router1> file copy server1:/tmp/config/router-base-configuration .

Including the override option with the load command replaces the entire candidate configuration with the contents of the file you are loading.

If you are just adding a new section to the configuration, use the load merge command instead. For instance, if you are setting up router access for a new user, you can create a file that contains the configuration information. For example, if you create the file router-config-new-user that contains the following:

system { login { user mike { class superuser; } } }

after you copy this file to the router, use the load merge command to incorporate only this section of the configuration into the candidate configuration:

[edit] aviva@router1# show system host-name router1; domain-name mynetwork.com; backup-router 192.168.600.1; time-zone America/Los_Angeles root-authentication { encrypted-password "$1$ZUlES4dp$OUwWo1g7cLoV/aMWpHUnC/"; ## SECRET-DATA; } name-server { 192.168.400.1; } login { class superuser-local { permissions all; } user aviva { class superuser; } } aviva@router1# load merge router-config-new-user aviva@router1# show system host-name router1; domain-name mynetwork.com; backup-router 192.168.600.1; time-zone America/Los_Angeles; root-authentication { encrypted-password "$1$ZUlES4dp$OUwWo1g7cLoV/aMWpHUnC/"; ## SECRET-DATA; } name-server { 192.168.400.1; } login { class superuser-local { permissions all; } user aviva { class superuser; } user mike { class superuser; } }

You can see from this output that the user mike is now in the [edit system] section of the candidate configuration. Again, remember to use the commit command to activate these changes.

If the file containing the configuration for the new users is on a server, you can load and merge it directly into the configuration:

[edit] aviva@router1# show system login class superuser-local { permissions all; } user aviva { class superuser; } aviva@router1# load merge relative server1:/tmp/router-config-new-user aviva@server1's password: router-config-new-users 100% 54 0.1KB/s 00:00 load complete [edit] aviva@router1# show system login class superuser-local { permissions all; } user aviva { class superuser; } user mike { class superuser; }

The relative option in the load merge command performs the operation without needing the full hierarchy level. To use this option, the hierarchy level in the file must be clear and unambiguous.

If the file containing the configuration of the new users is on another router, you can use the same command to copy it to your router. Specify the router name instead of the server name.

Категории