Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
632 views

Automation Lab2 (Python OSPF Script) v3

The document discusses configuring OSPF on routers R1 and R2 using a Python script. Key steps include preparing the routers for telnet access, running the Python script to configure OSPF and loopback interfaces on each router, and verifying OSPF neighbor status and connectivity between the routers.

Uploaded by

Dhmi yassin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
632 views

Automation Lab2 (Python OSPF Script) v3

The document discusses configuring OSPF on routers R1 and R2 using a Python script. Key steps include preparing the routers for telnet access, running the Python script to configure OSPF and loopback interfaces on each router, and verifying OSPF neighbor status and connectivity between the routers.

Uploaded by

Dhmi yassin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Automation Lab2 (OSPF

configuration using Python)


Network Walks Academy

Cisco Certifications www.networkwalks.com info@networkwalks.com


Automation Lab2
(OSPF Configuration using Python Script)

Topology Diagram

Task
TASK: Configure OSPF & below parameters on R1 & R2 using Python script through Local PC.
R1 should be able to ping R2 after your configuration.

‐ Configure Hostname as: nw_Router1


‐ Configure Hostname as: nw_Router2
‐ Configure Loopback0 on R1 with IP: 1.1.1.1 /32

1 www.networkwalks.com info@networkwalks.com
‐ Configure Loopback0 on R2 with IP: 2.2.2.2 /32
‐ OSPF Process ID on both R1 & R2: 1

The IP addresses on Router interface fa0/0 & your local PC are shown in the topology above

Solution
1. Configure local Loopback on your Laptop (follow the guide shared with you separately
for this)

2. Configure below IP address & subnet mask on this local loopback interface:

2 www.networkwalks.com info@networkwalks.com
3. Prepare R1 to be accessed via Telnet from our Local PC/Laptop
These steps are necessary for preparing the Router to be accessed via Telnet from our Local PC/Laptop.

i. Login to R1 & configure the IP address on its fa0/0:


nw_R1> enable
nw_R1# configure terminal
nw_R1(config)# interface fa0/0
nw_R1(config)# ip address 192.168.1.1 255.255.255.0

ii. Configure the enable password on R1:


nw_R1(config)# enable password nw

iii. Configure a user on R1 for remote access:


nw_R1(config)# username john privilege 15 password nw

iv. Configure the Telnet access (vty lines):


nw_R1(config)# line vty 0 15
nw_R1(config-if)# login local
nw_R1(config-if)# password nw
nw_R1(config-if)# exit

v. Save the configuration


nw_R1# copy running-config startup-config

4. Prepare R2 to be accessed via Telnet from our Local PC/Laptop


These steps are necessary for preparing the Router to be accessed via Telnet from our Local PC/Laptop.

vi. Login to R2 & configure the IP address on its fa0/0:


nw_R2> enable
nw_R2# configure terminal
nw_R2(config)# interface fa0/0

3 www.networkwalks.com info@networkwalks.com
nw_R2(config)# ip address 192.168.1.3 255.255.255.0

vii. Configure the enable password on R2:


nw_R2(config)# enable password nw

viii. Configure a user on R2 for remote access:


nw_R2(config)# username john privilege 15 password nw

ix. Configure the Telnet access (vty lines):


nw_R2(config)# line vty 0 15
nw_R2(config-if)# login local
nw_R2(config-if)# password nw
nw_R2(config-if)# exit

x. Save the configuration


nw_R2# copy running-config startup-config

5. Run the following Python Script in the interpreter (Pycharm is used in this lab)
Enter username & password as configure in above step#3 & 4
Username: john
Password: nw

Instructor will explain to you each line of code in below & guide you on each step
import getpass

import sys

import telnetlib

from telnetlib import Telnet

#R1

4 www.networkwalks.com info@networkwalks.com
user = input("Enter your telnet username for R1:")

password = getpass.getpass()

tn = telnetlib.Telnet("192.168.1.1")

tn.read_until(b"Username: ")

tn.write(user.encode('ascii') + b"\n")

if password:

tn.read_until(b"Password: ")

tn.write(password.encode('ascii') + b"\n")

tn.write(b"enable\n")

tn.write(b"conf t\n")

tn.write(b"hostname nw_Router1\n")

tn.write(b"int loop 0\n")

tn.write(b"ip address 1.1.1.1 255.255.255.255\n")

tn.write(b"router ospf 1\n")

tn.write(b"network 192.168.1.0 0.0.0.255 area 0\n")

tn.write(b"network 1.1.1.1 0.0.0.0 area 0\n")

tn.write(b"exit\n")

tn.write(b"exit\n")

tn.write(b"logout\n")

print(tn.read_all().decode('ascii'))

5 www.networkwalks.com info@networkwalks.com
#R2

user = input("Enter your telnet username for R2:")

password = getpass.getpass()

tn = telnetlib.Telnet("192.168.1.3")

tn.read_until(b"Username: ")

tn.write(user.encode('ascii') + b"\n")

if password:

tn.read_until(b"Password: ")

tn.write(password.encode('ascii') + b"\n")

tn.write(b"enable\n")

tn.write(b"conf t\n")

tn.write(b"hostname nw_Router2\n")

tn.write(b"int loop 0\n")

tn.write(b"ip address 2.2.2.2 255.255.255.255\n")

tn.write(b"router ospf 1\n")

tn.write(b"network 192.168.1.0 0.0.0.255 area 0\n")

tn.write(b"network 2.2.2.2 0.0.0.0 area 0\n")

tn.write(b"exit\n")

tn.write(b"exit\n")

6 www.networkwalks.com info@networkwalks.com
tn.write(b"logout\n")

print(tn.read_all().decode('ascii'))

Verification

6. Check on R1 whether R2 is an OSPF neighbor or not

Check on R1 whether there is any OSPF route

7 www.networkwalks.com info@networkwalks.com
7. Check on R1 whether R2 is an OSPF neighbor or not

Check on R1 whether there is any OSPF route:

8. Ping R2’s Loopback from R1:

8 www.networkwalks.com info@networkwalks.com
9. Ping R1’s Loopback from R2:

References / Comments
*Please follow the below important points to avoid errors in opening the attached GNS3 topology:
✓ The image name should match (c7200-adventerprisek9-mz.152-4.S7.image)
✓ The Local Loopback Interface name should match (Local LB NW)

© All Rights are reserved, Network Walks Academy


Leave your feedback at: info@networkwalks.com. Your Technical Questions, comments & suggestions are always Welcomed.
www.networkwalks.com

9 www.networkwalks.com info@networkwalks.com

You might also like