Generating Large Numbers of Router Configurations


You need to generate hundreds of router configuration files for a big network rollout.


When building a large WAN, you will usually configure the remote branch routers similarly, according to a template. This is a good basic design principle, but it also makes it relatively easy to create the router configuration files. The Perl script in Example 1-1 merges a CSV file containing basic router information with a standard template file. It takes the CSV file as input on STDIN.

Example 1-1.

while(<>) {
 ($location, $name, $lo0ip, $frameip, $framedlci, $eth0ip, $x) 
 = split (/,/);

 open(TFILE, "< $template_file_name") || die "config template file $template_file_name: $!
 $ofile_name = $name . ".txt";
 open(OFILE, "> $ofile_name") || die "output config file $ofile_name: $!

 while () {


 printf OFILE $_;


This Perl script is a simplified version of much larger scripts that we have used to create the configuration files for some very large networks. We then loaded these configuration files into the routers and shipped them to the remote locations, along with a hard copy of the configuration, in case there were problems during shipment. The technician doing the router installation could then simply connect the appropriate cables and power on the router, and never need to even connect to the router's console unless there were unexpected problems. This methodology can save hundreds of hours in a network installation project.

The script does a relatively simple merge function. It expects the input data in CSV format on STDIN. So if the input file is named RTR-DATA.CSV, you would run the script as follows:

Freebsd% < RTR-DATA.CSV

The input file in this case might look something like this:

Toronto, Router1,,, 101,,
Boston, Router2,,, 102,,
San Francisco, Router3,,, 103,,

Using a CSV file like this is convenient because you can keep track of the entire network in a spreadsheet, and then just create a CSV file containing the data you need for the router configurations.

The template configuration needs to include unique variable names that the script will replace with values from the CSV file. For example, the template configuration file might look like this:

version 12.1
service timestamps debug datetime msec
service timestamps log datetime msec
service password-encryption
hostname ##rtrname##
enable password cisco
enable secret cisco
interface Loopback0
 ip address ##loop0-ip##
interface Serial0/0
 description Frame-Relay Circuit 
 no ip address
 encapsulation frame-relay
 ip route-cache policy
 frame-relay lmi-type ansi
 no shutdown
interface Serial0/0.1 point-to-point
 ip address ##frame-ip##
 frame-relay interface-dlci ##frame-DLCI##
interface FastEthernet0/1
 description User LAN Segment
 ip address ##eth0-ip##
 no shutdown
router eigrp 99
snmp-server location ##location##
line con 0
 password cisco
 transport input none
line aux 0
 password cisco
line vty 0 4
 password cisco
 transport input telnet

The script expects to find this template file located in the current directory with the name rtr-template.txt by default, but you can change it easily by modifying the variable called template_file_name.

Naturally, your router templates will not look like this one, and your CSV file will almost certainly contain other data that is important to your network. So we expect that this script will need significant local modification every time you use it on a new network. But the amount of time required to modify the script is usually far less than the amount of time needed to create all of the configuration files by hand.

The output of this script will be a series of files whose names are the same as the router names, but with .txt added to the end. You can then use a terminal emulator to cut and paste the router configuration files into the routers prior to shipping them to their destinations. Always remember to save the configuration to the router's NVRAM before powering it off:

Router1#copy running-config startup-config


See Also

Recipe 1.16

Cisco IOS Cookbook
Cisco IOS Cookbook (Cookbooks (OReilly))
ISBN: 0596527225
EAN: 2147483647
Year: 2004
Pages: 505
Simiral book on Amazon © 2008-2017.
If you may any questions please contact us: