Distribute Static Route via OSPF in Cisco IOS Router

Spread the love




It is possible to have various routing protocols running in a network. Sometimes a communication between hosts that are running different routing protocol is required, and the way to accommodate the needs is by implementing route redistribution. Route redistribution is a terminology used to explain a process to distribute routes learned from one routing protocol via another routing protocol. In this article we are going to show the way to Distribute Static Route via OSPF in Cisco IOS Router because this is one of the common things that often required in a network.

How to Distribute Static Route via OSPF in Cisco IOS Router

The following network topology uses Cisco IOS Router with static route for connection between R1-R2 and R2-R4 while the connection between R2-R3 is using OSPF. Ping from R2 to all other routers works, but due to different routing protocol used, neither R1 nor R4 loopback is able to reach R3 loopback and vice versa.

Distribute Static Route via OSPF in Cisco IOS Router

R3#ping 1.1.1.1 source 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 3.3.3.3
.....
Success rate is 0 percent (0/5)
R3#ping 4.4.4.4 source 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 4.4.4.4, timeout is 2 seconds:
Packet sent with a source address of 3.3.3.3
.....
Success rate is 0 percent (0/5)

The routing configuration for each router are shown below.

R1#show run | s ip route
ip route 0.0.0.0 0.0.0.0 10.12.12.2
R2#show run | s router ospf|ip route
router ospf 1
 network 2.2.2.2 0.0.0.0 area 0
 network 10.23.23.2 0.0.0.0 area 0
ip route 1.1.1.1 255.255.255.255 10.12.12.1
ip route 4.4.4.4 255.255.255.255 10.24.24.4
R3#show run | s router ospf
router ospf 11
 network 3.3.3.3 0.0.0.0 area 0
 network 10.23.23.3 0.0.0.0 area 0
R4#show run | s ip route
ip route 0.0.0.0 0.0.0.0 10.24.24.2

As can be seen on the configuration above, both R1 and R4 already have default static route via R2 and there should be no problem with them reaching out to anywhere as long as they can reach R2. Below are routing table of R1 and R4:



R1#show ip route | b Gate
Gateway of last resort is 10.12.12.2 to network 0.0.0.0

S* 0.0.0.0/0 [1/0] via 10.12.12.2
   1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
   10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 10.12.12.0/24 is directly connected, FastEthernet0/0
L 10.12.12.1/32 is directly connected, FastEthernet0/0
R4#sh ip route | b Gate
Gateway of last resort is 10.24.24.2 to network 0.0.0.0

S* 0.0.0.0/0 [1/0] via 10.24.24.2
   4.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 4.4.4.0/24 is directly connected, Loopback0
L 4.4.4.4/32 is directly connected, Loopback0
   10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 10.24.24.0/24 is directly connected, FastEthernet0/0
L 10.24.24.4/32 is directly connected, FastEthernet0/0

Also from the configuration above, it can be seen that R2 is the only router on this topology that knows the routes to all destination. Below is the routing table on R2:

R2#show ip route | b Gate
Gateway of last resort is not set

   1.0.0.0/32 is subnetted, 1 subnets
S 1.1.1.1 [1/0] via 10.12.12.1
   2.0.0.0/32 is subnetted, 1 subnets
C 2.2.2.2 is directly connected, Loopback0
   3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/2] via 10.23.23.3, 00:05:12, FastEthernet0/1
   4.0.0.0/32 is subnetted, 1 subnets
S 4.4.4.4 [1/0] via 10.24.24.4
   10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
C 10.12.12.0/24 is directly connected, FastEthernet0/0
L 10.12.12.2/32 is directly connected, FastEthernet0/0
C 10.23.23.0/24 is directly connected, FastEthernet0/1
L 10.23.23.2/32 is directly connected, FastEthernet0/1
C 10.24.24.0/24 is directly connected, FastEthernet1/0
L 10.24.24.2/32 is directly connected, FastEthernet1/0

However, at this point of configuration R3 doesn’t know how to reach R1 and R4 loopback because R2 doesn’t forward this information to R3 due to different routing protocol between R1/R4 and R3. Below is the routing table on R3:

R3#sh ip route | b Gate
Gateway of last resort is not set

   2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/2] via 10.23.23.2, 00:06:56, FastEthernet0/0
   3.0.0.0/32 is subnetted, 1 subnets
C 3.3.3.3 is directly connected, Loopback0
   10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 10.23.23.0/24 is directly connected, FastEthernet0/0
L 10.23.23.3/32 is directly connected, FastEthernet0/0

This is the root cause of why R3 is unable to communicate with neither R1 nor R4 and vice versa. To fix this, R3 needs to be informed from R2 about the routes to R1 and R4 loopback address, and that means R2 needs to distribute its static routes to R3. The command to distribute static route via OSPF in Cisco IOS Router is “redistribute static subnets” and the way we applied this in the example is:

R2(config)#router ospf 1
R2(config-router)#redistribute static subnets

Now after the redistribution command is applied, R3 will have the knowledge of how to reach R1 and R4 loopback address, as shown in the updated routing table below:

R3#sh ip route | b Gate
Gateway of last resort is not set

   1.0.0.0/32 is subnetted, 1 subnets
O E2 1.1.1.1 [110/20] via 10.23.23.2, 00:00:27, FastEthernet0/0
   2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/2] via 10.23.23.2, 00:00:51, FastEthernet0/0
   3.0.0.0/32 is subnetted, 1 subnets
C 3.3.3.3 is directly connected, Loopback0
   4.0.0.0/32 is subnetted, 1 subnets
O E2 4.4.4.4 [110/20] via 10.23.23.2, 00:00:32, FastEthernet0/0
   10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 10.23.23.0/24 is directly connected, FastEthernet0/0
L 10.23.23.3/32 is directly connected, FastEthernet0/0
R3#ping 1.1.1.1 source 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 3.3.3.3
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 36/41/48 ms
R3#ping 4.4.4.4 source 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 4.4.4.4, timeout is 2 seconds:
Packet sent with a source address of 3.3.3.3
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/40/60 ms

The routes to R1 and R4 are shown as an external OSPF routes and it also can be seen that ping from R3 to both R1 and R4 are now success.

Filtered Distribution of Static Route via OSPF with Route-Map

Note that the behavior of a redistribute static command is to pass over all static routes to the other party. This can be a problem if there is a need to filter out some static routes from being known be the other party. For example, on the above scenario, what if there is a requirement that only allows R3 to know routes to reach R1 but not R4? To do that, a route-map needs to be implemented in the redistribute static command as shown in the example below.

Before applying this new command, first remove the previous redistribute static command on R2:

R2(config)#router ospf 1
R2(config-router)#no redistribute static subnets
R2(config-router)#exit

Then, create the access-list on R2 that contains only R1 loopback address (access-list can be standard or extended as long as it fits the requirement):

R2(config)#ip access-list extended R1_Loopback
R2(config-ext-nacl)#permit ip host 1.1.1.1 any
R2(config-ext-nacl)#exit

And next, add that access-list to route-map command:

R2(config)#route-map Permit_to_Distribute
R2(config-route-map)#match ip address R1_Loopback
R2(config-route-map)#exit

This route-map basically tells which routes that are permitted to be distributed, which is only R1 loopback route. Lastly, apply that route-map along with the redistribute static command on R2:

R2(config)#router ospf 1
R2(config-router)#redistribute static subnets route-map Permit_to_Distribute

With this way, R3 will only receive the static route to R1 loopback address as specified in the access-list and that can be proven by looking at R3’s routing table:

R3#sh ip route | b Gate
Gateway of last resort is not set

   1.0.0.0/32 is subnetted, 1 subnets
O E2 1.1.1.1 [110/20] via 10.23.23.2, 00:00:04, FastEthernet0/0
   2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/2] via 10.23.23.2, 00:22:34, FastEthernet0/0
   3.0.0.0/32 is subnetted, 1 subnets
C 3.3.3.3 is directly connected, Loopback0
   10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 10.23.23.0/24 is directly connected, FastEthernet0/0
L 10.23.23.3/32 is directly connected, FastEthernet0/0

Now R3 can reach only R1, but not R4.

R3#ping 1.1.1.1 source 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 3.3.3.3
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/42/64 ms
R3#ping 4.4.4.4 source 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 4.4.4.4, timeout is 2 seconds:
Packet sent with a source address of 3.3.3.3
.....
Success rate is 0 percent (0/5)

And that is pretty much all the basics you need to know to Distribute Static Route via OSPF in Cisco IOS Router.




The following two tabs change content below.

Arranda Saputra

ITIL Certified, CCNA, CCDA, VCP6-DCV, MCSA Administering Windows Server 2012
I am IT practitioner in real life with specialization in network and server infrastructure. I have years of experience in design, analysis, operation, and optimization of infrastructure solutions for enterprise-scaled network. You can send me a message on LinkedIn or email to arranda.saputra@outlook.com for further inquiry regarding stuffs that I wrote or opportunity to collaborate in a project.

Latest posts by Arranda Saputra (see all)

scroll to top