Scaling Network Configuration: Automating OSPF, EIGRP, and Static Routing with Netmiko

By Admin | 08-02-2026

Abstract:

Routing protocol, such as OSPF and EIGRP across twenty to fifty routers in a single maintenance window, is quite difficult when it must be done manually. Automation is a king in today’s networks operation enabling efficiency, consistency, reliability and predictability. This blog post is going to show you an example of how Netmiko can be used to automate common verification tasks such as pre-checks, configuration application and post checks on 50 routers in a consistent way.

Utilizing Python scripts and SSH automation using Netmiko, the network engineers can really switch a lot in less time; reduce chances of human errors; and standardize deployments. The automation process consists of a connection to several devices based on an inventory list, gathering operational baseline information, pushing OSPF and EIGRP configurations simultaneously, and validating neighbor adjacency and routing tables after deployment. Tasks that traditionally take hours of manual effort can be completed in minutes using parallel execution techniques.

This approach highlights how network automation not only accelerates large-scale configuration changes but also strengthens operational confidence through automated validation and logging. Netmiko provides a simple yet powerful foundation for engineers beginning their journey into network automation and helps bridge the gap between traditional CLI-based operations and programmable network infrastructure.

 

Let’s dig and down to automate this script by below scenario.

Scenario-

Eric, a NOC engineer at Verizon, receives a customer request to configure dynamic routing protocols such as OSPF and EIGRP, along with static routes, across 50 routers within a limited maintenance window. Performing this task manually would be time-consuming and prone to configuration errors. To address this challenge, Eric decides to use network automation with Python and the Netmiko library to complete the deployment efficiently and consistently.
 

As a demonstration, this example illustrates the automation workflow using three routers from different OSPF areas, showing how pre-checks, configuration deployment, and post-validation can be executed automatically. This approach can then be scaled easily to configure all 50 routers within minutes instead of hours.

Here R1 router placed at Boston location under area 10.

While R2 acts as an ABR at New Jersey location.

R3 router placed at Panjde location under area 20. 

 

How to automate script please follow below steps:

Step-1: Install the Netmiko SSH library in VS Code using Python so the script can connect to network devices automatically.

Step-2: Use the getpass library to securely enter the enable/secret password without displaying it on the screen.

Step-3: Define the router inventory details, including management IP address, username, and password, so the script knows which devices to connect to.

Step-4: Provide user-driven options to select the required configuration tasks, such as:

  • Number of interfaces to configure
  • Static routing configuration
  • EIGRP configuration
  • OSPF configuration

Step-5: Based on the user’s selection, the script prepares the appropriate configuration commands using conditional logic (if-elif statements) and pushes them to the routers.

 

Note: Prepare a management IP address list for all 50 routers in an Excel sheet, including the device type (cisco_ios) for each router. Then save the file in CSV format (for example, routers.csv). After that, import and read the CSV file in your Python script using the csv module in VS Code so the automation script can connect to all routers dynamically.

 

from netmiko import ConnectHandler
from getpass import getpass
r_username = input("Enter your username: ")
r_password = input("Enter your password: ")
router_details = {
   'ip' : '192.168.184.131',
   'device_type' : 'cisco_ios',
   'username' : r_username,
   'password' : r_password
}
router_details = {
   'ip' : '192.168.184.132',
   'device_type' : 'cisco_ios',
   'username' : r_username,
   'password' : r_password
}
router_details = {
   'ip' : '192.168.184.133',
   'device_type' : 'cisco_ios',
   'username' : r_username,
   'password' : r_password
}
ssh = ConnectHandler(**router_details)
print("ssh connection established successfully")
user_choice = int(input("Welcome to the router configuration utility.what would you like to configure: \n1. Interface configuration\n2.static route configuration\n3.EIGRP\n4.OSPF\n please make a choice(1/2/3/4):"))

if user_choice == 1:
   print ("You Have selected interface configurations..")
   user_input = int(input("How many interface would you like to configure ?"))
   for int_conf in range(0,user_input):
     int_name = input("Enter the interface name")
     int_ip = input ("Enter ip details")
     int_mask = input ("Enter subnet mask")
     int_description = input ("enter description")

   
   commands = [f'interface{int_name}',f'ip address{int_ip}{int_mask}',f'desc{int_description}','no shutdown']
   int_conf = ssh.send_config_set(commands)
   print(int_conf)
   int_details = ssh.send.command('show ip interface brief')
   print(int_details)
   ssh.save_config()
elif user_choice == 2:
  print("You have selected static route configuration")
  user_input = int(input("Enter the no of static routes that you wish to configure: "))
 
  for static_conf in range(0,user_input):
    
    network_id = input ("Enter the destination network id:")
    subnet_mask = input ("Enter subnet mask:")
    next_hop = input ("Enter next hop address of exit interface ")
    commands = [f'ip route {network_id} {subnet_mask} {next_hop}']
    static_conf = ssh.send_config_set(commands)
    print(static_conf)
    static_details = ssh.send_command("show run | inc ip route")
    print(static_details)
    ssh.save_config()
elif user_choice == 3:
  
  print("You have selected EIGRP configuration")
  eigrp_as = input("Enter the EIGRP ASN:")
  no_of_nw = int(input("How many networks you want to add under EIGRP: "))

  for EIGRP_conf in range(0,no_of_nw):
     network_id = input("Enter the network id:")
     wildcard_mask = input("Enter the wildcard mask:")
     commands =[f'router eigrp{eigrp_as}',f'network{network_id} {wildcard_mask}']
         
     eigrp_configs= ssh.send_config_set(commands)        
     print(eigrp_configs)
 
     eigrp_details = ssh.send_command('show run | sec eigrp')
     print(eigrp_details)
     ssh.save_config()


elif user_choice == 4:
        print("OSPF configuration selected")
        commands = []

        process = input("OSPF process ID: ")
        commands.append(f"router ospf {process}")

        count = int(input("Number of networks: "))

        for _ in range(count):
            network = input("Network ID: ")
            wildcard = input("Wildcard mask: ")
            area = input("Area ID: ")
            commands.append(f"network {network} {wildcard} area {area}")

        print(ssh.send_config_set(commands))
        print(ssh.send_command("show ip ospf neighbor"))

    else:
        print("Invalid option selected")

    ssh.save_config()
    ssh.disconnect()

print("\nAutomation completed successfully.")

Please find output as below in terminal 

Enter your username: admin
Enter your password:
Welcome to the router configuration utility.
1. Interface configuration
2. Static route configuration
3. EIGRP
4. OSPF
Please make a choice (1/2/3/4): 4

Connecting to 192.168.184.131...
OSPF configuration selected
Enter the OSPF process ID: 1
Number of networks: 1
Network ID: 10.1.1.0
Wildcard mask: 0.0.0.255
Area ID: 0

config term
router ospf 1
network 10.1.1.0 0.0.0.255 area 0
end

Neighbor ID     Pri   State           Dead Time   Address         Interface

------------------------------------------------------------

Connecting to 192.168.184.132...
OSPF configuration selected

config term
router ospf 1
network 10.1.1.0 0.0.0.255 area 0
end

Neighbor ID     Pri   State           Dead Time   Address         Interface

------------------------------------------------------------

Connecting to 192.168.184.133...
OSPF configuration selected

config term
router ospf 1
network 10.1.1.0 0.0.0.255 area 0
end

Neighbor ID     Pri   State           Dead Time   Address         Interface

------------------------------------------------------------

Automation completed successfully.
 

Conclusion:

If you are not a fan of zero-touch provisioning and want to configure routing protocols on multiple routers in your organization using only one or two hours of interaction, then doing so manually may be difficult. In this example, we showed how Python network automation with the Netmiko library greatly reduces the amount of work required when connecting to multiple routers and configuring OSPF automatically and validating our work.

With an inventory-based approach and reusable Python logic the same workflow above can scale from 3 routers up to 50 or more devices with no increase in operational overhead. This change from managing devices manually to employing automation reduces the time it takes to configure a network from hours down to minutes and removes the potential for error that comes with a decline in consistency or repeatability with each manual configurations modification.

Netmiko, Python scripting and structured device inventories are becoming a requirement for NOC and network engineers as networks scale in size and complexity. Even simple automation scripts like the one demonstrated here can significantly improve efficiency during configuration deployments, migrations, and maintenance activities.

Network automation is no longer optional — it is becoming a core operational capability for modern network engineering.