If you have ever tried to setup something similar to production in you network lab then you might have come across this problem that you don’t have enough routes in the routing table. This can be solved easily with traffic generators like Ixia/Spirent/Pagent etc, but you may not be having this in your home lab.We can overcome this by creating number of loopback interfaces and giving them a distinct IP address. These loopbacks can be easily advertised into IGP or BGP etc to increase the size to routing table. But we still have a problem to solve which is the huge manual task involved to create loopback interfaces, it can take a good amount of your time. For example if you need to create 1000 loopbacks , you need to give 1000 different IP address which is a very time consuming task.
Thankfully, we have a python module to help us here. “Ipaddress” is a python module which gives you many options to play with the IP address (v4 and v6). You can get more information on this module in below link.
https://docs.python.org/3/howto/ipaddress.html
I have used this module to create a small script which can help me in creating configuration for number of loopbacks. Here is the summary of things I have done in my script.
- Create 10-1000 loopbacks
- Assign IP address to all loopbacks
- Advertise all these loopbacks to ISIS
- Put this config file in a text file so that we can easily copy paste to router.
from contextlib import redirect_stdout
import ipaddress
net = ipaddress.ip_network('200.0.0.0/16')
with open('ipout.txt', 'w') as f:
with redirect_stdout(f):
for i in range (10,1000):
x=net[i]
print ("interface loop", i)
print ("ip address",x ,"", "255.255.255.255")
print ("ip router isis LAB")
Output will look something like this.
interface loop 10
ip address 200.0.0.10 255.255.255.255
ip router isis LAB
interface loop 11
ip address 200.0.0.11 255.255.255.255
ip router isis LAB
interface loop 12
ip address 200.0.0.12 255.255.255.255
ip router isis LAB
interface loop 13
ip address 200.0.0.13 255.255.255.255
ip router isis LAB
.....
.....
interface loop 999
ip address 200.0.3.231 255.255.255.255
ip router isis LAB