OSPF routing
1.OSPF routing
1.1 Introduction to OSPF
OSPF (Open Shortest Path First) routing protocol is another commonly used routing protocol. It advertises the status of network interfaces between routers and uses the shortest path algorithm to establish routing tables. When generating a routing table, the OSPF protocol gives priority to factors such as line speed (cost), but the number of hops passed is not a key reference condition.
The OSPF routing protocol can support running within an autonomous area or between multiple autonomous areas.
The following mainly introduces the configuration method of OSPF in a single area.
As shown in Figure 1, in the network topology diagram, each router uses the OSPF protocol to generate a routing table. The rate of the line between RouterO and Router3 is relatively slow (the cost is relatively high, 100), while the rates of the other three lines are relatively Fast (the fee is relatively small, 10 per item).
2. PC device configuration
2.1 PC device information and interface configuration
Configure the interface information of the PC device, as shown in Table 1-1.
equipment |
connected router |
IP address |
subnet mask |
Gateway address |
PC1 |
R1 |
192.168.1.2 |
255.255.255.0 |
192.168.1.1 |
PC2 |
R1 |
192.168.2.2 |
255.255.255.0 |
192.168.2.1 |
PC3 |
R2 |
172.16.0.2 |
255.255.0.0 |
172.16.0.1 |
PC4 |
R3 |
172.18.0.2 |
255.255.0.0 |
172.18.0.1 |
PC5 |
R4 |
172.17.0.2 |
255.255.0.0 |
172.17.0.1 |
Table 1-1
3. Router interface configuration
3.1 Router interface information and configuration
Configure the interface information of the router device, as shown in Table 1-2.
router |
interface |
IP address |
subnet mask |
OSPF fees |
Connect devices |
R1 |
GigabitEthernet0/0/0 |
192.168.1.1 |
255.255.255.0 |
- |
Connect to device PC1 |
R1 |
GigabitEthernet0/0/1 |
192.168.2.1 |
255.255.255.0 |
- |
Connect to device PC2 |
R1 |
Serial0/1/0 |
13.0.0.2 |
255.0.0.0 |
100 |
Connect to device R4 |
R1 |
Serial0/1/1 |
10.0.0.1 |
255.0.0.0 |
10 |
Connect to device R2 |
R2 |
GigabitEthernet0/0/0 |
172.16.0.1 |
255.255.0.0 |
- |
Connect to device PC3 |
R2 |
Serial0/1/0 |
11.0.0.1 |
255.0.0.0 |
10 |
Connect to device R3 |
R2 |
Serial0/1/1 |
10.0.0.2 |
255.0.0.0 |
10 |
Connect to device R1 |
R3 |
GigabitEthernet0/0/0 |
172.18.0.1 |
255.255.0.0 |
- |
Connect to device PC4 |
R3 |
Serial0/1/1 |
11.0.0.2 |
255.0.0.0 |
10 |
Connect to device R2 |
R3 |
Serial0/1/0 |
12.0.0.1 |
255.0.0.0 |
10 |
Connect to device R4 |
R4 |
GigabitEthernet0/0/0 |
172.17.0.1 |
255.255.0.0 |
- |
Connect to device PC5 |
R4 |
Serial0/1/1 |
13.0.0.1 |
255.0.0.0 |
- |
Connect to device R1 |
R4 |
Serial0/1/0 |
12.0.0.2 |
255.0.0.0 |
- |
Connect to device R3 |
Table 1-2
Figure 1 Network topology diagram using OSPF to generate routing tables
4.OSPF configuration
4.1 OSPF fee configuration
Then in the configuration mode of the specified interface, use the "ip ospf cost cost" command to configure the cost for the line on each interface.
I configured the interface in Router0, where the line fee connected to the Se1/0 interface is 100, and the cost of Se0/0 is 10.
R1(config)#interface s0/0R1(config-if) #ip ospf cost 10
R1(config-if)#exit
R1(config) #interface s1/0
R1(config-if)#ip ospf cost 100
The cost of configuring all interfaces in R2 is 10.
R2(config)#interface s0/0
R2(config-if)#ip ospf cost 10
R2(config-if)#exit
Routerl(config)#interface s1/0
Routerl(config-if)#ip ospf cost 10
The cost of configuring all interfaces in R3 is 10.
R3(config) #interface s0/0R3(config-if)#ip ospf cost 10
R3(config-if)#exit
R3(config)#interface s1/0
R3(config-if)#ip ospf cost 10
4.2 OSPF network configuration
Finally, use the router ospf command in each router. After it, you need to specify a number as the process number of the OSPF process, so that you can enter the OSPF configuration environment with the specified process number. In this configuration environment, network is also used to broadcast the network IP address directly connected to the local router. The subsequent parameter is not the subnet mask, but uses the "area area number" as the last parameter (since the instance is in an area, That is a single area, so its area numbers are all set to 1).
Configure the OSPF protocol in router R1.
R1(config)# router ospf 1
R1(config-router)#network 192.168.1.0 0.0.0.255 area 1R1(config-router)#network 192.168.2.0 0.0.0.255 area 1
R1(config-router)#network 10.0.0.0 0.255.255.255 area 1
R1(config-router)#network 11.0.0.0 0.255.255.255 area 1
Configure the OSPF protocol in Router.
R2(config) #router ospf 1
Routerl(config-router)#network 172.16.0.0 0.0.255.255 area 1Roüterl(config-router)#network 10.0.0.0 0.255.255.255 area 1
Routerl(config-router)#network 11.0.0.0 0.255.255.255 area 1
Configure the OSPF protocol in router R3.
outer(config)#router ospf 1
R3(config-router)#network 172.17.0.0 0.0.255.255 area 1R3(config-router)#network 11.0.0.00.255.255.255 area 1
R3(config-router)#network 12.0.0.0 0.255.255.255 area 1
5. View routing table
5.1 View routing table
Check the routing table in router R1. The routing records starting with O are all calculated by the OSPF protocol
.
R1#show ip route ospf
O 11.0.0.0 [110/20] via 10.0.0.2, 00:30:17, Serial0/1/1
O 12.0.0.0 [110/30] via 10.0.0.2, 00:30:07, Serial0/1/1
O 172.16.0.0 [110/11] via 10.0.0.2, 00:30:17, Serial0/1/1
O 172.17.0.0 [110/31] via 10.0.0.2, 00:30:07, Serial0/1/1
O 172.18.0.0 [110/21] via 10.0.0.2, 00:30:07, Serial0/1/1
R1#
Combined with the cost of the line, the OSPF protocol does not use the line between R1 and R4, but uses the R1→R2→R3→R4 path (the next hop route to the 172.17.0.0 network is R2, and its entry address is 10.0.0.2 ).
Use the tracert command on PC1 to check whether the actual path matches the record in the routing table.
Cisco Packet Tracer PC Command Line 1.0
C:\>tracert 172.18.0.2
Tracing route to 172.18.0.2 over a maximum of 30 hops:
1 0 ms 0 ms 0 ms 192.168.2.1
2 0 ms 0 ms 5 ms 10.0.0.2
3 0 ms 20 ms 1 ms 11.0.0.2
4 * 11 ms 0 ms 172.18.0.2
Trace complete.
C:\>
The router also provides multiple commands for viewing detailed information of the OSPF protocol.
Show ip ospf neighbor can display the information of local routing OSPF neighbors, including their router ID, interface address and IP address.
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 0 FULL/ - 00:00:30 10.0.0.2 Serial0/1/1
4.4.4.4 0 FULL/ - 00:00:31 13.0.0.1 Serial0/1/0
R1#
Show ip ospf database is used to display the contents of the OSPF database of local routes (similar to the contents of the routing table).
R1#show ip ospf database
OSPF Router with ID (1.1.1.1) (Process ID 1)
Router Link States (Area 1)
Link ID ADV Router Age Seq# Checksum Link count
1.1.1.1 1.1.1.1 607 0x80000008 0x00ac4f 6
4.4.4.4 4.4.4.4 608 0x80000007 0x009f4e 5
3.3.3.3 3.3.3.3 607 0x80000007 0x00cbfd 5
2.2.2.2 2.2.2.2 607 0x80000007 0x006679 5
R1#
The Show ip protocols command is used to display parameters and timer information related to routing protocols. This command can also be used on routers that enable the RIP routing protocol.
R1#show ip protocols
Routing Protocol is "ospf 1"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 1.1.1.1
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
192.168.1.0 0.0.0.255 area 1
192.168.2.0 0.0.0.255 area 1
10.0.0.0 0.0.0.255 area 1
13.0.0.0 0.0.0.255 area 1
Routing Information Sources:
Gateway Distance Last Update
1.1.1.1 110 00:15:02
2.2.2.2 110 00:15:01
3.3.3.3 110 00:15:03
4.4.4.4 110 00:15:03
Distance: (default is 110)
R1#
6. Experimental script
6.1 Script example
//R1
en
conf t
hostn R1
int g0/0/0
ip add 192.168.1.1 255.255.255.0
no sh
int g0/0/1
ip add 192.168.2.1 255.255.255.0
no sh
int s0/1/0
ip add 13.0.0.2 255.0.0.0
no sh
ip ospf cost 100
int s0/1/1
ip add 10.0.0.1 255.0.0.0
no sh
ip ospf cost 10
exit
router ospf 1
router-id 1.1.1.1
network 192.168.1.0 0.0.0.255 area 1
network 192.168.2.0 0.0.0.255 area 1
network 10.0.0.0 255.255.255.0 area 1
network 13.0.0.0 255.255.255.0 area 1
end
w
!
//R2
en
conf t
hostn R2
int g0/0/0
ip add 172.16.0.1 255.255.0.0
no sh
int s0/1/0
ip add 11.0.0.1 255.0.0.0
no sh
ip ospf cost 10
int s0/1/1
ip add 10.0.0.2 255.0.0.0
no sh
ip ospf cost 10
exit
router ospf 1
router-id 2.2.2.2
network 172.16.0.0 0.0.255.255 area 1
network 11.0.0.0 255.255.255.0 area 1
network 10.0.0.0 255.255.255.0 area 1
end
w
!
//R3
en
conf t
hostn R3
int g0/0/0
ip add 172.18.0.1 255.255.0.0
no sh
int s0/1/1
ip add 11.0.0.2 255.0.0.0
no sh
ip ospf cost 10
int s0/1/0
ip add 12.0.0.1 255.0.0.0
no sh
ip ospf cost 10
exit
router ospf 1
router-id 3.3.3.3
network 172.18.0.0 0.0.255.255 area 1
network 11.0.0.0 255.255.255.0 area 1
network 12.0.0.0 255.255.255.0 area 1
end
w
!
//R4
en
conf t
hostn R4
int g0/0/0
ip add 172.17.0.1 255.255.0.0
no sh
int s0/1/1
ip add 13.0.0.1 255.0.0.0
no sh
int s0/1/0
ip add 12.0.0.2 255.0.0.0
no sh
exit
router ospf 1
router-id 4.4.4.4
network 172.17.0.0 0.0.255.255 area 1
network 12.0.0.0 255.255.255.0 area 1
network 13.0.0.0 255.255.255.0 area 1
end
w
!
When faced with challenges, don't be afraid of failure because every failure is a step toward success. Believe in yourself and move forward bravely, you can overcome everything!