We may come across on interesting issue if we get the same prefix from external BGP AS and directly via OSPF process. It may happen if we want to have another link to the destination but not neccesarily via another eBGP link. The problem that we will definetely come across on is just another variation of suboptimal routing.
Let’s have a look on below network diagram and assume that we are an administrator in AS2. We have BGP neighboorship with AS1 and we share OSPF Area0 with R3. The OSPF link may be just “super fast” Internet link with using of GRE tunnels or direct connectivity alike in our case. Router R3 advertises prefix 192.168.1.0/24 via BGP and OSPF. R2 gets this prefix from R1 and directly from R3. So far nothing fancy, but if we take into consideration that there is no router in the middle on the OSPF path and there is a BGP router on BGP path we don’t have to do calculation to come to the proper conclusion that prefered path should be OSPF. Unfortunately AD of eBGP route is 20 and OSPF 110 so we will get this prefix via BGP. We may have a couple of AS on the 192.168.1.0/24 path before it reach our AS. This is just another example of “suboptimal routing” that we would like to avoid.
BGP Backdoor network
Can we do something about that to provide desirable path to the network 192.168.1.0 via OSPF? Yes, we have to use cool BGP feature called “BGP Backdoor“. First, let’s check what we have in the routing table before utilization of “BGP backdoor” feature on R2 router.
As we see R2 router knows about 192.168.1.0/24 thanks to OSPF (show ip ospf route) but it has chosen BGP according to the lower AD (show ip route). Now, let’s use BGP backdoor with one simple command
router bgp 2
network 192.168.1.0 mask 255.255.255.0 backdoor
Now, if we check the RIB table we will see that to get 192.168.1.0/24 prefix R2 uses OSPF link with next hop of 18.104.22.168 and the paths looks in this way: