Preparing the Configuration File

A configuration file that you create must follow the same syntax rules as the startup-config file the device creates.

  • The configuration file is a script containing CLI configuration commands. The CLI reacts to each command entered from the file in the same way the CLI reacts to the command if you enter it. For example, if the command results in an error message or a change to the CLI configuration mode, the software responds by displaying the message or changing the CLI mode.
  • The software retains the running-config that is currently on the device, and changes the running-config only by adding new commands from the configuration file. If the running config already contains a command that is also in the configuration file you are loading, the CLI rejects the new command as a duplicate and displays an error message. For example, if the running-config already contains a a command that configures ACL 1, the software rejects ACL 1 in the configuration file, and displays a message that ACL 1 is already configured.
  • The file can contain global configuration commands or configuration commands for interfaces, routing protocols, and so on. You cannot enter User EXEC or privileged EXEC commands.
  • The default CLI configuration mode in a configuration file is the global configuration model. Thus, the first command in the file must be a global configuration command or " ! ". The ! (exclamation point) character means "return to the global configuration mode".
Note: You can enter text following " ! " as a comment. However, the " !" is not a comment marker. It returns the CLI to the global configuration mode.
Note: If you copy-and-paste a configuration into a management session, the CLI ignores the " ! " instead of changing the CLI to the global configuration mode. As a result, you might get different results if you copy-and-paste a configuration instead of loading the configuration using TFTP.
  • Make sure you enter each command in the correct CLI mode. Since some commands have identical forms at both the global configuration mode and individual configuration modes, if the CLI response to the configuration file results in the CLI entering a configuration mode you did not intend, then you can get unexpected results.

For example, if a trunk group is active on the device, and the configuration file contains a command to disable STP on one of the secondary ports in the trunk group, the CLI rejects the commands to enter the interface configuration mode for the port and moves on to the next command in the file you are loading. If the next command is a spanning-tree command with syntax that is valid in global confiiguration mode as well as interface configuration mode, then the software applies the command globally. Here is an example.

The configuration file contains these commands.

interface ethernet 1/1/2
no spanning-tree

The CLI responds like this.

device(config)# interface ethernet 1/1/2 
Error - cannot configure secondary ports of a trunk
device(config)# no spanning-tree
device(config)#
  • If the file contains commands that must be entered in a specific order, the commands must appear in the file in the required order. For example, if you want to use the file to replace an IP address on an interface, you must first remove the old address using "no" in front of the ip address command, then add the new address. Otherwise, the CLI displays an error message and does not implement the command. Here is an example.

The configuration file contains these commands.

interface ethernet 1/1/2
ip address 10.10.10.10/24

The running-config already has a command to add an address to port 1/1/2, so the CLI responds like this.

device(config)# interface ethernet 1/1/2 
device(config-if-e1000-11)# ip add 10.10.10.10/24
Error: can only assign one primary ip address per subnet
device(config-if-e1000-1/1/2)#

To successfully replace the address, enter commands into the file as follows.

interface ethernet 1/1/2
no ip address 10.20.20.20/24
ip address 10.10.10.10/24

This time, the CLI accepts the command, and no error message is displayed.

device(config)# interface ethernet 1/1/2
device(config-if-e1000-1/1/2)# no ip add 10.20.20.20/24
device(config-if-e1000-1/1/2)# ip add 10.10.10.10/24
device(config-if-e1000-1/1/2)#
Note: Always use the end command at the end of the file. The end command must appear on the last line of the file, by itself.