Saving, Erasing, Restoring and Backing up Configuration
As you already know, any change to the configuration is made to the running-config, which is different from the startup-config that is loaded at the boot up. What this means is that if you do not save the running-config to the NVRAM as startup-config, all changes will be lost on reboot!
To save the running-configuration to NVRAM, you can use the copy command in the privileged exec mode. The copy command expects two parameters – the source and the destination. In this case, the source is the running-config and the destination is the startup-config, so the command that you will need to use is copy running-config startup-config as shown below:
Now consider a situation where you made changes to the running-config but want to discard them. Remember that changes to the running-config are immediate. So either you can negate all changes one by one or simply copy the startup config to running-config using the copy command. This time, simply reverse the source and destination as shown below:
Apart from copying the config between running and startup, you can also copy the config to a TFTP server in the network for backup purpose. You need to backup the config so that you have a copy to use in case the router crashes and you need to replace it. You can again use the copy command by replacing the destination with tftp: as shown below:
Notice in the example above that after the command, you are prompted for the IP address of the TFTP server and the file name. You can press enter to use the default file name or provide a different one.
Similarly, you can copy the config from a TFTP server to the running-config by reversing the above command as shown below:
If you want to clear the configuration and start afresh, you can erase the startup-config and reload the router. To erase the startup-config, use the erase startup-config command in the privilege exec mode as shown below:
To reboot the device, use the reload command in the privilege exec mode as shown below:
If the configuration is not saved, the router will prompt you to save the configuration when you enter the reload command. Type no and press enter to not save the configuration and reload with an empty NVRAM. When the devices comes up, there will be no configuration on it and you can start over.
Working with IOS files and IOS File System (IFS)
Similar to how the configuration can be copied around, the IOS file that is used by devices can be backed up or restored or simply changed using the copy command. Remember that IOS file is saved in the flash memory. To copy the file currently used by the router to a TFTP server, use the copy flash: tftp: command as shown below:
To copy an image from the TFTP server to the flash memory, reverse the above command as shown below:
Notice the error in the above output? It shows that the file was not copied because there is no space left in the flash memory. So before copying the new file, you will need to free up some space. You can check the contents of the flash memory using the dir command in the privileged exec mode as shown below:
To free up some space you can delete some the existing files using the delete command. Since there is only a single file in the flash currently, it has to be deleted as shown below:
Now that you have free space, try the copy command again:
The two commands that you used above, dir and delete are examples of commands that are used to manage the IOS File System (IFS). Even copy is similarly a command to manage the IFS. There are various other commands that can be used to manage the IFS. Some of them are discussed below:
- show file – This command will give you few details such as file type and size about any file in the IFS. An example is shown below:
- erase – This command as you already know, can be used to delete the contents of the NVRAM.
- format – This command is used to erase ALL contents of the flash.
- mkdir – This command is used to create a sub-directory in the IFS. An example is shown below:
- cd – This command is used to move to a sub-directory or move back to parent directory on IFS. For example, cd test will take you inside the sub-directory created above.
- pwd – This command can be used to find the name of directory you are currently in. An example is shown below:
- rmdir – This command can be used to delete a directory.
- copy – Similar to how you copied an IOS file to the flash (IFS), you can copy any file to IFS. For example, you can copy the running-config to the IFS as shown below:
- more – This command can be used to read the contents of a text file that exists on the IFS. For example, you can read the contents of the backup.conf file created in the previous step as shown below:
In case you have enough free space in the flash memory, you can have multiple IOS files there. By default, the first file that the system encounters is used for booting. You can specify the IOS file that want the system to load to boot up, using the boot system command in the global configuration mode as shown below: