By Kevin Dooley, Ian J. Brown
Book Price: $59.99 USD
£42.50 GBP
PDF Price: $47.99
Cover | Table of Contents
Router1#copy tftp://172.25.1.1/NEWCONFIG running-config Destination filename [running-config]? <enter> Accessing tftp://172.25.1.1/NEWCONFIG... Loading NEWCONFIG from 172.25.1.1 (via FastEthernet0/0.1): ! [OK - 24 bytes] 24 bytes copied in 0.192 secs (125 bytes/sec) Router1#
NEWCONFIG from the server at 172.25.1.1 by using the Trivial File Transfer Protocol (TFTP). The router will copy the entire file via TFTP before entering the commands into the running configuration. This is extremely useful because sometimes some commands in the middle of a configuration could disrupt your access to the router, but the rest of the commands might fix the problem. If you tried to enter them manually using TELNET and configure terminal, you would simply lock yourself out of the router and not be able to continue. A typical example of this problem happens when you replace an active access-list. When you enter the first line, the router puts an implicit deny all at the end, which could break your session. However, entering commands by using TFTP avoids this problem.Freebsd% touch /tftpboot/router1-confg Freebsd% chmod 666 /tftpboot/router1-confg Freebsd% telnet Router1 Trying 172.25.1.5... Connected to Router1. Escape character is '^]'. User Access Verification Password: <vtypassword> Router1>enable Password: <enablepassword> Router1#copy running-config tftp://172.25.1.1/router1-confg Address or name of remote host [172.25.1.1]? <enter> Destination filename [router1-confg]? <enter> !!! 9640 bytes copied in 3.956 secs (2437 bytes/sec) Router1#
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#service config Router1(config)#boot network tftp Network-auto 172.25.1.1 Router1(config)#boot host tftp Router8-auto 172.25.1.1 Router1(config)#end Router1#
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#service compress-config Router1(config)#end Router1#
Router1#copy running-config startup-config Destination filename [startup-config]? <enter> Building configuration... Compressed configuration from 9664 bytes to 4903 bytes[OK] Router1#
Router1#erase nvram: Erasing the nvram filesystem will remove all files! Continue? [confirm] <enter> [OK] Erase of nvram: complete Router1#reload System configuration has been modified. Save? [yes/no]: no Proceed with reload? [confirm] <enter>
Router1#erase startup-config Erasing the nvram filesystem will remove all files! Continue? [confirm] <enter> [OK] Erase of nvram: complete Router1#reload Proceed with reload? [confirm] <enter>
--- System Configuration Dialog --- Would you like to enter the initial configuration dialog? [yes/no]: no Would you like to terminate autoinstall? [yes]: yes Press RETURN to get started! Router>
Router#show running-config
Building configuration...
Current configuration : 431 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname Router
!
!
ip subnet-zero
!
!
!
!
interface Ethernet0
no ip address
shutdown
!
interface Ethernet1
no ip address
shutdown
!
interface Serial0
no ip address
shutdown
!
interface Serial1
no ip address
shutdown
!
ip classless
ip http server
ip pim bidir-enable
!
!
line con 0
line aux 0
line vty 0 4
!
end
Router#Router1#copy tftp://172.25.1.1/c2600-ik9o3s-mz.122-12a.bin flash: Destination filename [c2600-ik9o3s-mz.122-12a.bin]? <enter> Accessing tftp://172.25.1.1/c2600-ik9o3s-mz.122-12a.bin... Erase flash: before copying? [confirm] <enter> Erasing the flash filesystem will remove all files! Continue? [confirm] <enter> Erasing device... eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ...erased Erase of flash: complete Loading c2600-ik9o3s-mz.122-12a.bin from 172.25.1.1 (via FastEthernet0/0.1): !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! [OK - 11135588 bytes] Verifying checksum... OK (0xE643) 11135588 bytes copied in 82.236 secs (135410 bytes/sec) Router1# reload Proceed with reload? [confirm] <enter>
Router1#show flash
System flash directory:
File Length Name/status
1 11135588 c2600-ik9o3s-mz.122-12a.bin
[11135652 bytes used, 5117276 available, 16252928 total]
16384K bytes of processor board System flash (Read/Write)
Router1#Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#boot system flash:c3620-jk9o3s-mz.122-7a.bin Router1(config)#boot system flash:c3620-jos56i-l.120-11.bin Router1(config)#boot system slot0:c3620-ik9s-mz.122-13.bin Router1(config)#boot system rom Router1(config)#end
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#boot system tftp c2500-io-l.122-7a.bin 172.25.1.1 Router1(config)#boot system flash Router1(config)#end Router1#
Freebsd% touch /tftpboot/c2600-ik9o3s-mz.122-12a.bin Freebsd% chmod 666 /tftpboot/c2600-ik9o3s-mz.122-12a.bin Freebsd% telnet Router1 Trying 172.25.1.5... Connected to Router1. Escape character is '^]'. User Access Verification Password: <vtypassword> Router1>enable Password: <enablepassword> Router1#copy flash:c2600-ik9o3s-mz.122-12a.bin tftp Address or name of remote host []? 172.25.1.1 Destination filename [c2600-ik9o3s-mz.122-12a.bin]? <enter> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 11135588 bytes copied in 52.588 secs (211752 bytes/sec) Router1#
Router1#copy xmodem: slot1: **** WARNING **** x/ymodem is a slow transfer protocol limited to the current speed settings of the auxiliary/console ports. The use of the auxilary port for this download is strongly recommended. During the course of the download no exec input/output will be available. ---- ******* ---- Proceed? [confirm] <enter> Destination filename []? c3620-ik9s-mz.122-12a.bin Erase slot1: before copying? [confirm] <enter> Use crc block checksumming? [confirm] <enter> Max Retry Count [10]: <enter> Perform image validation checks? [confirm] <enter> Xmodem download using crc checksumming with image validation Continue? [confirm] <enter> Ready to receive file...........CC <start xmodem file transfer here> 4294967295 bytes copied in 1450.848 secs (1271445669961 bytes/sec) Router1#
Router1#erase slot1: Erasing the slot1 filesystem will remove all files! Continue? [confirm] <enter> Erasing device... eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ...erased Erase of slot1: complete Router1#
Router1#delete slot1:c3620-ik9s-mz.122-13.bin Delete filename [c3620-ik9s-mz.122-13.bin]? <enter> Delete slot1:c3620-ik9s-mz.122-13.bin? [confirm] <enter> Router1#
| Router type | Filesystem type |
|---|---|
| 7000 (RSP) | Class A |
| 7500 (RSP 2 ,4, and 8) | Class A |
| 12000 | Class A |
| Route Switch Module (RSM) | Class A |
| 1600 | Class B |
| 2500 | Class B |
| 3600 | Class B |
| 4000 | Class B |
| AS5300 | Class B |
| AS5800 | Class C |
| 7100 | Class C |
| 7200 | Class C |
| Command | Filesystem | Description |
|---|---|---|
| Delete | All | Marks the files as deleted, but does not permanently remove them from flash. |
| Squeeze | A | Permanently removes all files that have been marked as deleted. |
| Format | A and C | Erases the entire flash device. |
| Verify | All | Verifies that the IOS file’s checksum matches the value encoded in the image. |
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#partition slot1: 2 8 8 Router1(config)#end Router1#
Router1#show slot1:
PCMCIA Slot1 flash directory, partition 1:
File Length Name/status
1 7723664 c3620-ajs56i-mz.120-25.bin
[7723728 bytes used, 664880 available, 8388608 total]
8192K bytes of processor board PCMCIA Slot1 flash (Read/Write)
PCMCIA Slot1 flash directory, partition 2:
File Length Name/status
1 7723664 c3620-ajs56i-mz.120-25.bin
[7723728 bytes used, 402736 available, 8126464 total]
8192K bytes of processor board PCMCIA Slot1 flash (Read/Write)
Router1#
Router1#erase slot1:2: Erasing the slot1:2 filesystem will remove all files! Continue? [confirm]
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#tftp-server flash:c2600-ik9o3s-mz.122-12a.bin Router1(config)#end Router1#
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#access-list 99 permit 172.25.1.0 0.0.0.255 Router1(config)#access-list 99 deny any Router1(config)#tftp-server flash:c2600-ik9o3s-mz.122-12a.bin 99 Router1(config)#end Router1#
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#ip ftp username ijbrown Router1(config)#ip ftp password ianpassword Router1(config)#end Router1#copy ftp: running-config Address or name of remote host [172.25.1.1]? 172.25.1.1 Source filename []? test Destination filename [running-config]? <enter> Accessing ftp://172.25.1.1/test... Loading /test [OK - 24/4096 bytes] 24 bytes copied in 0.276 secs (87 bytes/sec) Router1#
Router1#copy ftp://ijbrown:ianpassword@172.25.1.1/c3620-ik9s-mz.122-10a.bin slot1: Destination filename [c3620-ik9s-mz.122-10a.bin]? <enter> Accessing ftp://ijbrown:ianpassword@172.25.1.1/c3620-ik9s-mz.122-10a.bin... Loading pub/c3620-ik9s-mz.122-10a.bin !!!! Erase slot1: before copying? [confirm]
#!/usr/local/bin/perl
#
$template_file_name="rtr-template.txt";
while(<>) {
($location, $name, $lo0ip, $frameip, $framedlci, $eth0ip, $x)
= split (/,/);
open(TFILE, "< $template_file_name") || die "config template file $template_file_name: $!\n";
$ofile_name = $name . ".txt";
open(OFILE, "> $ofile_name") || die "output config file $ofile_name: $!\n";
while (<TFILE>) {
s/##location##/$location/;
s/##rtrname##/$name/;
s/##eth0-ip##/$eth0ip/;
s/##loop0-ip##/$lo0ip/;
s/##frame-ip##/$frameip/;
s/##frame-DLCI##/$framedlci/;
printf OFILE $_;
}
}
RTR-DATA.CSV, you would run the script as follows:Freebsd% create-configs.pl <#!/usr/local/bin/expect
#
# rtrcfg.exp -- a script to perform mass configuration changes to
# a list of routers using telnet and Expect
#
#
# Set Behavior
set tftp "172.25.1.1"
set workingdir /home/cisco/rtr
#
puts stdout "Enter user name:"
gets stdin userid
system stty -echo
puts stdout "Enter login password:"
gets stdin vtypasswd
puts stdout "\nEnter enable password:"
gets stdin enablepwd
system stty echo
system "cp $workingdir/NEWCONFIG /tftpboot/NEWCONFIG"
set RTR [open "$workingdir/RTR_LIST" r]
set LOG [open "$workingdir/RESULT" w]
while {[gets $RTR router] != -1} {
if {[ string range $router 0 0 ] != "#"} {
set timeout 10
spawn telnet; expect "telnet>"; send "open $router\n"
expect {
{Username} { send "$userid\r"
expect {
{*Password*} { send "$vtypasswd\r" }
}
}
{Password} { send "$vtypasswd\r" }
timeout { puts $LOG "$router - telnet failed"
close; wait; continue
}
}
expect {
{Password} { puts $LOG "$router - vty login failed"
close; wait; continue
}
{Username} { puts $LOG "$router - vty login failed"
close; wait; continue
}
{>} { puts $LOG "$router - vty login ok" }
timeout { puts $LOG "$router - vty login failed"
close; wait; continue
}
}
send "enable\r"
expect "Password"
send "$enablepwd\r"
#
expect {
{*#} { puts $LOG "$router - enable login ok" }
{*>} { puts $LOG "$router - enable login failed"
close; wait; continue
}
timeout { puts $LOG "$router - enable login failed"
close; wait; continue
}
}
# CMDs
set timeout 30
send "copy tftp://$tftp/NEWCONFIG running-config\r"
expect "running-config"
send "\r"
expect {
{OK} { puts $LOG "$router - TFTP successful"}
timeout { puts $LOG "$router - TFTP failed"
close; wait; continue }
}
send "copy running-config startup-config\r\r\r"
expect {
{OK} { puts $LOG "$router - config saved"}
timeout { puts $LOG "$router - config failed"
close; wait; continue }
}
#CMDs
send "exit\r"; close; wait
}
}
close $RTR; close $LOG
system "rm /tftpboot/NEWCONFIG"#!/bin/sh
#
# inventory.sh -- a script to extract valuable information
# from a list of routers. (Name, Type, IOS version)
#
#
# Set behaviour
public="ORARO"
workingdir="/home/cisco"
#
LOG=$workingdir/RESULT.csv
infile=$workingdir/RTR_LIST
snmp="/usr/local/bin/snmpget -v1 -c $public"
#
while read device
do
$snmp $device sysName.0 > /dev/null
if [ "$?" = "0" ] ; then
rtr=\Q$snmp $device .1.3.6.1.4.1.9.2.1.3.0 | cut -f2 -d\" \Q
type2=\Q$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.3 | cut -f2 -d$ \Q
ios=\Q$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.5 | cut -f2 -d$ \Q
prot=\Q$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.4 | cut -f2 -d$ \Q
echo "$device, $rtr, $type2, $ios, $prot" >> $LOG
fi
done < $infile
RESULT.csv.#!/usr/local/bin/perl
#
# backup.pl -- a script to automatically backup a list of
# router configuraton files on a nightly basis.
#
#
# Set behavior
$workingdir="/home/cisco/bkup";
$snmprw="ORARW";
$ipaddress="172.25.1.1";
$days="30";
#
#
$rtrlist="$workingdir/RTR_LIST";
$storage="$workingdir/storage";
$latest="$storage/LATEST";
$prev="$storage/PREV";
if (! -d $storage) {mkdir ($storage, 0755)};
if (! -d $prev) {mkdir ($prev, 0755)};
if (! -d $latest) {mkdir ($latest, 0755)};
($sec, $min, $hr, $mday, $mon, $year, @etc) = localtime(time);
$mon++; $year=$year+1900;
$today1=sprintf("%.4d_%.2d_%.2d", $year, $mon, $mday);
$today="$storage/$today1";
system("cp -p $latest/* $prev/");
unlink <$latest/*>;
mkdir ($today, 0755);
open (RTR, "$rtrlist") || die "Can't open $rtrlist file";
open (LOG, ">$workingdir/RESULT") || die "Can't open $workingdir/RESULT file";
print LOG "Router Configuration Backup Report for $year/$mon/$mday\n";
print LOG "======================================================\n";
print LOG "Device Name Status\n";
print LOG "======================================================\n";
while (<RTR>) {
chomp($rtr="$_");
$oid=".1.3.6.1.4.1.9.2.1.55.$ipaddress";
$snmpset ="/usr/local/bin/snmpset -v1 -c $snmprw -t60 -r2 $rtr";
$rtrfile="/tftpboot/$rtr.cfg";
unlink $rtrfile;
open (CFG, ">$rtrfile"); print CFG " ";close CFG;
chmod 0666, $rtrfile;
chop ($status=\Q$snmpset $oid s $rtr.cfg\Q);
$status=~/.+ = "(.+)".*$/;
if($1 eq "$rtr.cfg") {
if( -z "$rtrfile" ) {
$result="not ok (File empty)";
unlink $rtrfile;
}
else {
$result="ok";
chmod 0444, $rtrfile;
system("mv $rtrfile $latest");
}
}
else {
$result="not ok";
unlink $rtrfile;
}
printf LOG ("%-28s %-28s\n", $rtr,$result);
}
system ("cp -p $latest/*cfg $today");
$time=$days*86400;
print "$time\n";
($sec, $min, $hr, $mday, $mon, $year, @etc) = localtime(time-$time);
$mon++; $year=$year+1900;
$rmdir=sprintf("%s/%.4d_%.2d_%.2d",$configs, $year, $mon, $mday);
system ("rm -r -f $storage/$rmdir");Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#warm-reboot Router1(config)#end Router1#
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#warm-reboot Router1(config)#end Router1#reload warm file slot0:c3745-ipbasek9-mz.124-7.bin
Router1#reload warm file slot0:c3745-ipbasek9-mz.124-7.bin Proceed with reload? [confirm] <enter> Decompressing the image : ############################################################################################################################################################ [OK] <Removed for brevity>