OSPF configuration guide: from basic principles to practical exercises

OSPF (Open Shortest Path First) is a very important dynamic routing protocol. It is an interior gateway protocol (IGP) used to make routing decisions within a single autonomous system (AS). It is suitable for small, medium, and large-scale networks.

Compared with RIP (Routing Information Protocol), OSPF has faster convergence speed, higher scalability, and more accurate routing calculation capabilities. It runs based on the link state, uses the Dijkstra shortest path first (SPF) algorithm to calculate the optimal path, and improves network scalability through area division.


1. OSPF Protocol Overview
1. OSPF Core Features
Based on Link State Database (LSDB): Each OSPF router maintains the topology information of the entire autonomous system, instead of just storing the next hop information like RIP.
Using SPF (Shortest Path First) algorithm: Ensure that packets always take the best path, avoiding hop count limit issues like RIP.
Support VLSM and CIDR: Compared with RIP, OSPF can use Variable Length Subnet Mask (VLSM) to improve address utilization.
Fast convergence speed: When the network topology changes, OSPF will only update the changed part, instead of broadcasting the entire routing table regularly like RIP.
Support area division: Large OSPF networks can be divided into multiple areas, reducing the computing and storage burden of routers and improving scalability.

Support multi-path load balancing:

Yī, OSPF

Multiple paths can be used simultaneously for data forwarding to improve bandwidth utilization.

2. Working principle of OSPF

OSPF uses five different types of packets (Hello, DBD, LSR, LSU, LSAck) to perform neighbor discovery, link status update and route calculation. The specific process is as follows:

(1) Neighbor discovery (Hello message)

OSPF routers discover neighbors on the network through Hello packets and establish OSPF neighbor relationships.

(2) Establish neighbor relationships (DBD, LSR, LSU, LSAck)

Exchange database description packets (DBD) to understand each other's topology database.
Exchange complete LSDB information through link state requests (LSR) and link state updates (LSU).
Use Link State Acknowledgement (LSAck) to confirm whether the updated information is correct.

(3) Calculate the optimal path (Dijkstra SPF algorithm)

Each OSPF router will execute the SPF algorithm to calculate the optimal path and update the local routing table.

(4) Link State Update (LSU Triggered Update)

When the topology changes, OSPF will only propagate updates of the affected parts instead of periodically broadcasting the entire routing table.

II. Typical OSPF Topology Example
In order to better understand OSPF, we use Huawei ENSP to build a simple OSPF network topology:
OSPF related commands:

III. OSPF configuration steps
1. Enable OSPF and enter the OSPF process
Execute on R1, R2, and R3 respectively:

2. Set up the OSPF network area
Add the corresponding network to OSPF on each router:

Tips: After the configuration is completed, you can view it through display ospf routing

For R2, R3, and R4, execute similar commands:
OK, the next step is the acceptance phase.

(1) Let’s first check R1’s routing table. We have already learned all the routes.

(2) Test OSPF interoperability: PING R4’s 192.168.2.2 on R1

If the connection is normal, it means OSPF is set up successfully!

(3) Check the OSPF neighbors of router R1

(4) Display the OSPF routing information of router R1
The above is the basic configuration of OSPF. Have you learned it?