Here’s yet another way to generate loopback interfaces using Tcl. This time we add interfaces from a custom list of subnet IDs.
We will use the following Tcl script:
set i "0" foreach subnet { 48 50 52 54 } { puts "interface loopback $i" puts " ip address 192.168.$subnet.1 255.255.255.0" incr i 1 }
Using this script we can do the following:
Router# Router#tclsh Router(tcl)#set i "0" 0 Router(tcl)#foreach subnet { +> 48 +> 50 +> 52 +> 54 +>} { +> puts "interface loopback $i" +> puts " ip address 192.168.$subnet.1 255.255.255.0" +> incr i 1 +>} interface loopback 0 ip address 192.168.48.1 255.255.255.0 interface loopback 1 ip address 192.168.50.1 255.255.255.0 interface loopback 2 ip address 192.168.52.1 255.255.255.0 interface loopback 3 ip address 192.168.54.1 255.255.255.0 Router(tcl)#exit
Notice how the script only sends the configuration to standard output. In order to actually create the interfaces we have to copy and paste the script output into configure terminal:
Router# Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#interface loopback 0 Router(config-if)# ip address 192.168.48.1 255.255.255.0 Router(config-if)#interface loopback 1 Router(config-if)# ip address 192.168.50.1 255.255.255.0 Router(config-if)#interface loopback 2 Router(config-if)# ip address 192.168.52.1 255.255.255.0 Router(config-if)#interface loopback 3 Router(config-if)# ip address 192.168.54.1 255.255.255.0 Router(config-if)# *Mar 1 00:01:19.331: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up *Mar 1 00:01:19.547: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback1, changed state to up *Mar 1 00:01:19.659: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback2, changed state to up *Mar 1 00:01:19.779: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback3, changed state to up Router(config-if)#end Router#sh protocols Global values: Internet Protocol routing is enabled FastEthernet0/0 is administratively down, line protocol is down FastEthernet0/1 is administratively down, line protocol is down Loopback0 is up, line protocol is up Internet address is 192.168.48.1/24 Loopback1 is up, line protocol is up Internet address is 192.168.50.1/24 Loopback2 is up, line protocol is up Internet address is 192.168.52.1/24 Loopback3 is up, line protocol is up Internet address is 192.168.54.1/24
Very handy when doing labs 🙂
Leave a Reply