Networking Magic: Automating IP Routing Protocols With One Click

Suppose I ask you to configure either OSPF, EIGRP, or RIP. If you configure it manually, then it will take time to complete its configuration. We can simplify it through Python script within a single execution. In this way, we can automate IP routing protocols. We will give an option to the user whether he/she wants to run either OSPF, EIGRP, or RIP.  You can ask from a user via choice, which commands you want to run. We will use the netmiko library for this task. In the netmiko library, we will further import the ConnectHandler method.

Lab Topology for Automating IP Routing Protocols

We will use the following lab. The cloud has three Microsoft KM-TEST Loopback Adapters, which are ethernet5, ethernet10, and ethernet9. Check the IP addresses of the routers in the below screenshot. First check connectivity between routers and your machine (PC, Laptop), then run your script to automate IP routing protocols.

Lab topology for Automating IP Routing Protocols

Basic configuration of R1, R2 and R3.

R1

R1 configuration

In the same way, configure R2 and R3. R2 IP address 192.168.20.17/24 and R3’s IP address is 192.168.20.8/24. Also, configure the domain name marwat and generate the rsa key. Create username ‘user1’ in both routers R2 and R2.

Python Script to Run OSPF EIGRP and RIP

First,, we are writing the basic script that we are using from the previous articles. In the screenshot, there are three IP addresses. After a for loop has been used in the Script, which uses a variable My Device, which will iterate IP addresses in the ‘machines’ list. It will execute all three IP addresses to automate OSPF EIGRP and RIP.

script first part

After the first part of a script, we are using another 2nd part of a script. Both parts are the same script, but we divided it for simplicity.

            It has a variable User_choice, which will take either 1,2, or 3 from a user. The full statement of an User_choice is [User_choice = int(input(‘Welcome to the Routing. Please enter your choice.\n No.1:- OSPF Configuration\n No.2:-EIGRP Configuration\n No.3:- RIP Configuration\n Enter your choice here: ‘))]. As 1,2 and 3 are integer values, so we add the int data type before the input method. User_choice has further used the if-else statements to compare 1,2 or 3 values with User_choice.

 If the user enters 1, then we will configure OSPF on routers. Similarly, if a user inputs 2, then it will configure EIGRP on all routers. In the same way, if he enters 3, then RIP will be configured. At the last, else statement will run, that if a user inputs any value other than 1,2 or 3, then a message will appear as “You have selected the wrong value, please try again: “ will be displayed.

script 2nd part

Combine both parts of the script

Python script to automate OSPF EIGRP and RIP

Python script for Automating IP Routing Protocols

RUN OSPF

Check confirmation, whether OSPF has been configured or not on R1, R2, and R3. We only check for R1.

This time we will input 2, and it will configure EIGRP on all routers.

Check the script configuration on R1 whether EIGRP is running or not. By the use of ‘show ip protocol’.

In the same way, we will enter 3, configuring the RIP routing protocol.

At the last check, its configuration is on R1.

So we have run the routing protocols one by one. We ran all the tasks successfully within a single execution. By the way, we learned how to automate IP routing protocols.

Similar Posts

Leave a Reply

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