Code-
from netmiko import ConnectHandler
devices = [
{"name": "R1", "port": 5000},
{"name": "R2", "port": 5001},
{"name": "R3", "port": 5002},
{"name": "R4", "port": 5003},
]
configs = {
"R1": [
"hostname R1",
"int f1/0",
"ip address [Link] [Link]",
"bandwidth 128",
"no shutdown",
"int f1/1",
"ip address [Link] [Link]",
"bandwidth 128",
"no shutdown",
"int f0/0",
"ip address [Link] [Link]",
"no shutdown",
"router eigrp 1",
"network [Link]",
"network [Link]",
"network [Link]",
"no auto-summary"
],
"R2": [
"hostname R2",
"int f1/0",
"ip address [Link] [Link]",
"bandwidth 128",
"no shutdown",
"int f1/1",
"ip address [Link] [Link]",
"bandwidth 64",
"no shutdown",
"int f0/0",
"ip address [Link] [Link]",
"no shutdown",
"router eigrp 1",
"network [Link]",
"network [Link]",
"network [Link]",
"no auto-summary"
],
"R3": [
"hostname R3",
"int f1/0",
"ip address [Link] [Link]",
"bandwidth 128",
"no shutdown",
"int f1/1",
"ip address [Link] [Link]",
"bandwidth 64",
"no shutdown",
"int se3/0",
"ip address [Link] [Link]",
"bandwidth 64",
"no shutdown",
# PBR
"ip access-list standard PBR-PC3",
"permit [Link] [Link]",
"exit",
"route-map PBR permit 10",
"match ip address PBR-PC3",
"set ip next-hop [Link]",
"exit",
"int se3/0",
"ip policy route-map PBR",
"router eigrp 1",
"network [Link]",
"network [Link]",
"network [Link]",
"no auto-summary"
],
"R4": [
"hostname R4",
"int se3/0",
"ip address [Link] [Link]",
"bandwidth 64",
"no shutdown",
"int f0/0",
"ip address [Link] [Link]",
"no shutdown",
"router eigrp 1",
"network [Link]",
"network [Link]",
"no auto-summary"
]
for dev in devices:
print(f"\n Connecting to {dev['name']}...")
router = {
"device_type": "cisco_ios_telnet",
"host": "[Link]",
"port": dev["port"],
"username": "",
"password": "",
"secret": "",
"fast_cli": False # (prevents command skipping)
}
conn = ConnectHandler(**router)
[Link]()
output = conn.send_config_set(configs[dev["name"]])
print(output)
conn.save_config()
[Link]()
print("\n ALL ROUTERS CONFIGURED SUCCESSFULLY!")
Steps:= ⚙️Step 5: Define Device Parameters
In script:
Specify:
o Device type → cisco_ios_telnet
o Host → [Link]
o Ports → (5000–5003)
🧠 Step 6: Configure Routers via Script
Script performs:
🔹 R1, R2, R4:
Hostname configuration
Interface IP assignment
Bandwidth configuration
EIGRP routing
🔹 R3:
Interface configuration
EIGRP routing
PBR Configuration:
o ACL creation
o Route-map creation
o Applying policy on interface
🔁 Step 7: Run the Script
In terminal:
python pbr_setup.py
📊 Step 8: Output Verification
After execution:
Script connects to each router
Applies configuration
Displays CLI output
Saves configuration
🔍 Step 9: Verify in GNS3
Run on routers:
show ip route
show ip policy
show route-map
🧪 Step 10: Test PBR
From R4:
traceroute [Link]
✅ Expected Result:
Traffic follows path based on PBR:
Controlled via R3