TCL Script for Creating Many Loopback Interfaces

Perhaps you are like me and sometimes have the need to create many loopback interfaces to be used in your lab. So, I made a little script that can create these loopback interfaces automatically for you.

The Script

proc inf_config {x} {
for {set n 1} {$n<=$x} {incr n 1} {
puts [ ios_config "interface Loopback$n" "ip address 192.168.$n.1 255.255.255.0" ]
}
}
If you want a network other than 192.168.*.*, you can change it by changing the IP – just remember $n. $n is the number the script creates.
Executing The Script
R2#tclsh
R2(tcl)#proc inf_config {x} {
+>for {set n 1} {$n<=$x} {incr n 1} {
+>$ “interface Loopback$n” “ip address 192.168.$n.1 255.255.255.0″ ]
+>}
+>}
Router(tcl)#inf_config 2
If you want more than 2 interfaces to be created, just change the “inf_config 2″ to the number you need.
Script Results
interface Loopback1
 ip address 192.168.1.1 255.255.255.0
!
interface Loopback2
 ip address 192.168.2.1 255.255.255.0
!
and so on….
You are free to use and modify this script to suit your own needs.
About Per Mariager

Per Mariager has developed a deep knowledge of virtualization, networking, storage and Cloud in a broad perspective, but also streamlines his focus on VMware and Cisco Technology. Because of that knowledge and focus, Per works as a Network and Cloud Technologist Specialist, Data Center Architect Specialist and a Cisco Certified consultant.

Find most of his content at PacketPushers.net. Follow him on Twitter, Google Plus, LinkedIn ore his personal website.

  • http://twitter.com/pandom_ Anthony Burke

    Fantastic Per!

    Really clever!

    Puts me to shame with my notepad, copy/paste/find and replace trick.
    Thank you!- Anthony

    • Derrick

      I second your comment Tony! I too am ashamed now. Good stuff Per!! Thanks.

  • http://twitter.com/miguelinnit Miguel

    Blog ruined the formatting of your script. the is & gt; etc.

    • http://twitter.com/pandom_ Anthony Burke

      proc inf_config {x} {
      for {set n 1} {$n<=$x} {incr n 1} {
      puts [ ios_config "interface Loopback$n" "ip address 192.168.$n.1 255.255.255.0" ]
      }
      }
      inf_config 10

    • http://packetpushers.net/author/ecbanks Ethan Banks

      Ack. Just saw that. That can be repaired…will take a few moments to edit.

    • http://packetpushers.net/author/ecbanks Ethan Banks

      Okay – looking better now.

  • Orhan ERGUN

    What if i want to create more than 255 interface ?