Menu Close

Tclsh script examples: how to generate router loop interfaces with IPv4 addresses

This example shows how to generate 254 loop interfaces with assigned ipv4 addresses 172.16.0.1/24 up to 172.16.255.1/24. The code is:

enable
tclsh
for {set i 0} {$i < 256} {incr i} {
ios_config "int loop $i" "ip address 172.16.$i.1 255.255.255.0"
}
ios_config "end"
tclquit

and you may just simply copy and paste it into a Cisco router CLI. Therefore first run tclsh within of privileged EXEC mode

enable
tclsh

and paste the code:

R3(tcl)#

R3(tcl)#for {set i 0} {$i < 256} {incr i} {
+>(tcl)#ios_config "int loop $i" "ip address 172.16.$i.1 255.255.255.0"
+>(tcl)#}

R3(tcl)#

the router starts immediatelly genereate interfaces

*Mar  1 00:01:57.083: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback176, changed state to up
*Mar  1 00:01:57.087: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback177, changed state to up

We may check it how it proceeed:

R3#sh ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES DHCP   up                    up
Serial0/0                  unassigned      YES NVRAM  administratively down down
FastEthernet0/1            unassigned      YES NVRAM  administratively down down
Serial0/1                  unassigned      YES NVRAM  administratively down down
Serial0/2                  unassigned      YES NVRAM  administratively down down
Serial0/3                  unassigned      YES NVRAM  administratively down down
Loopback0                  172.16.0.1      YES unset  up                    up
Loopback1                  172.16.1.1      YES unset  up                    up
Loopback2                  172.16.2.1      YES unset  up                    up
Loopback3                  172.16.3.1      YES unset  up                    up
...

How to delete them? Just put

enable
tclsh
for {set i 0} {$i < 256} {incr i} {
ios_config " no int loop $i"
}
ios_config "end"
tclquit
Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.