Redistribute OSPF Route into BGP in Cisco IOS Router

Usually it is not a best practice to perform redistribution especially in BGP. But some specific network deployment scenario requires us to redistribute an IGP routes like OSPF or EIGRP into BGP instead of advertising the subnet using network command in BGP. This article explains the command to Redistribute OSPF Route into BGP in Cisco IOS Router by using an example scenario below:

Redistribute OSPF Route into BGP in Cisco IOS Router

In this scenario, a company named MustBeGeek Enterprise (or “MBG” for short) has just acquire a company named X-Corp and as part of the acquisition they have to integrate their network. MBG has placed their Cisco IOS router named “RouterX” on X-Corp’s datacenter and configure it to perform eBGP peering with the border router in MBG’s datacenter, named MBG-HO-BDR. MBG’s administrator wants to keep the BGP configuration as simple as possible and avoid adding new configuration line one by one to advertise all subnets that created in the X-Corp network.

How to Redistribute OSPF Route into BGP in Cisco IOS Router

The command to redistribute OSPF route into BGP in Cisco IOS Router is “redistribute ospf [process-id]” and can be performed under BGP configuration section. Since the OSPF configuration in RouterX is using process-id 1, then the configuration to redistribute OSPF route into BGP in RouterX is as follows:

RouterX(config)#router bgp 65050
RouterX(config-router)#redistribute ospf 1

With this command, MBG-HO-BDR router can now see all the OSPF routes in X-Corp network as a BGP route:

MBG-HO-BDR#show ip route bgp | b Gate
Gateway of last resort is not set

10.0.0.0/8 is variably subnetted, 9 subnets, 3 masks
B 10.1.1.0/24 [20/2] via 10.0.254.2, 00:05:30
B 192.168.0.0/24 [20/0] via 10.0.254.2, 00:05:30

Also, everytime a new subnet is added to OSPF in X-Corp network, MBG network will automatically learn this route in BGP. To simulate this we can simply add a new subnet on any routers in X-Corp network and add it to OSPF:

X1(config)#interface loopback1
X1(config-int)#ip address 10.1.2.1 255.255.255.0
X1(config-int)#no shut
X1(config-int)#exit
X1(config)#router ospf 1
X1(config-router)#network 10.1.2.1 0.0.0.255 area 0

And see the newly created subnet also installed in the MBG-HO-BDR’s routing table without adding any new configuration in the BGP section of RouterX.

MBG-HO-BDR#show ip route bgp | b Gate
Gateway of last resort is not set

10.0.0.0/8 is variably subnetted, 10 subnets, 3 masks
B 10.1.1.0/24 [20/2] via 10.0.254.2, 00:06:06
B 10.1.2.0/24 [20/0] via 10.0.254.2, 00:00:14
B 192.168.0.0/24 [20/0] via 10.0.254.2, 00:06:06

Specifying OSPF Routes to be Redistributed in Cisco IOS Router

You may be wondering why the 10.2.1.0/24 network still don’t get installed in the BGP routing table. This is because by default OSPF redistribution in Cisco IOS router only redistribute inter-area (O) and intra area routes (O IA).

As you can see below, the 10.2.1.0/24 is an external OSPF route (O E2) in RouterX, and in the topology drawing above you can see that this route in OSPF is actually learned from other routing protocol (EIGRP). Therefore, this E2 route doesn’t get redistributed into BGP by default.

RouterX#sh ip route ospf | b Gate
Gateway of last resort is 0.0.0.0 to network 0.0.0.0

10.0.0.0/8 is variably subnetted, 8 subnets, 3 masks
O IA 10.1.1.0/24 [110/2] via 192.168.0.251, 00:02:01, FastEthernet0/0
O 10.1.2.0/24 [110/2] via 192.168.0.251, 00:01:51, FastEthernet0/0
O E2 10.2.1.0/24 [110/20] via 192.168.0.252, 00:03:15, FastEthernet0/0

To allow redistribution of external routes along with all internal routes, the keyword “match internal external” can be added into the OSPF redistribution command so the complete command is “redistribute ospf [process-id] match internal external“. The implementation in RouterX is as follows:

RouterX(config)#router bgp 65000
RouterX(config-router)#redistribute ospf 1 match internal external

Now see that the 10.2.1.0/24 route has been added to BGP routing table of MBG-HO-BDR:

MBG-HO-BDR#show ip route bgp | b Gate
Gateway of last resort is not set

10.0.0.0/8 is variably subnetted, 11 subnets, 3 masks
B 10.1.1.0/24 [20/2] via 10.0.254.2, 00:01:47
B 10.1.2.0/24 [20/2] via 10.0.254.2, 00:01:47
B 10.2.1.0/24 [20/20] via 10.0.254.2, 00:00:04
B 192.168.0.0/24 [20/0] via 10.0.254.2, 00:01:47

And that’s how you redistribute OSPF route into BGP in Cisco IOS Router. Please note to always think everything carefully before advertising any routes into BGP in the real network.

The following two tabs change content below.
Arranda Saputra

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.
scroll to top