This document describes the behavior of Open Shortest Path First (OSPF) to Border Gateway Protocol (BGP) redistribution on Cisco routers.
Cisco recommends that you have knowledge of OSPF route types, BGP fundamentals, and route redistribution before you use this document.
This document is not restricted to specific software and hardware versions.
Note: The examples in this document use Cisco IOS Software command syntax.
The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your network is live, ensure that you understand the potential impact of any command.
This Tech Note explains the behavior of the OSPF to BGP redistribution on Cisco routers. RFC 1403 documents historical guidance for interaction between OSPF and BGP.
There are several types of OSPF routes:
Intra-Area — In a multi-area OSPF network, routes that originate within an area are known by the routers in the same area as Intra-Area routes. These routes are flagged as O in the show ip route command output.
Inter-Area — When a route crosses an OSPF Area Border Router (ABR), the route is known as an OSPF Inter-Area route. These routes are flagged as O IA in the show ip route command output.
Both Intra- and Inter-Area routes are also called OSPF Internal routes, as they represent prefixes originated within the OSPF domain rather than routes redistributed into OSPF.
External Type-2 or External Type-1 — Routes that were redistributed into OSPF, such as Connected, Static, or other Routing Protocol, are known as External Type-2 or External Type-1. These routes are flagged as O E2 or O E1 in the show ip route command output.
NSSA External Type-2 or NSSA External Type 1 — When an area is configured as a Not-So-Stub Area (NSSA), and routes are redistributed into OSPF, the routes are known as NSSA External Type-2 or NSSA External Type-1. These routes are flagged as O N2 or O N1 in the show ip route command output.
The explanation of the differences between External and NSSA Type 2 or 1 is beyond the scope of this document — refer to the OSPF Design Guide for more information.
The default behavior is not to redistribute any routes from OSPF into BGP. Redistribution must be configured. You can use the route-map command to filter routes during OSPF to BGP redistribution. In order to select route types explicitly, use the applicable match internal, match external, or match nssa-external option. Without match options, redistribute ospf redistributes OSPF internal routes by default.
This document discusses five primary OSPF-to-BGP redistribution cases. Topology A applies to the first four cases. Topology B applies to the NSSA-external route case described in the Redistribute OSPF NSSA-External Routes into BGP section.
Redistribution OSPF to BGP Topology A
If you configure the redistribution of OSPF into BGP without keywords, only OSPF intra-area and inter-area routes are redistributed into BGP, by default. In order to redistribute OSPF Intra-area and Inter-area routes, you can use the internal keyword with the redistribute command under router bgp.
This Router B (RTB) configuration redistributes the OSPF internal prefixes 10.2.2.0/24, 10.108.1.0/24, and 10.108.2.0/24 into BGP:
| RTB |
|---|
hostname RTB ! |
Router B redistributes only OSPF Internal routes:
RTB#show ip bgp BGP table version is 12, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.2.2.0/24 0.0.0.0 0 32768 ? *> 10.108.1.0/24 10.2.2.2 3 32768 ? *> 10.108.2.0/24 10.2.2.2 2 32768 ? RTB#
Router C learns these routes from BGP:
RTC#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks B 10.2.2.0/24 [20/0] via 10.3.3.1, 00:07:07 C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.2/32 is directly connected, GigabitEthernet0/0 B 10.108.1.0/24 [20/3] via 10.3.3.1, 00:07:07 B 10.108.2.0/24 [20/2] via 10.3.3.1, 00:07:07 RTC# RTC#show ip bgp BGP table version is 8, local router ID is 10.3.3.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.2.2.0/24 10.3.3.1 0 0 100 ? *> 10.108.1.0/24 10.3.3.1 3 0 100 ? *> 10.108.2.0/24 10.3.3.1 2 0 100 ? RTC#
In order to redistribute OSPF external routes into BGP, use the external keyword with the redistribute command under router bgp. With the external keyword, you have three choices:
Redistribute both External Type-1 and Type-2 (Default)
Redistribute Type-1
Redistribute Type-2
Enter the commands in the configuration mode as described here:
RTB(config)#router bgp 100 RTB(config-router)#redistribute ospf 1 match external
This Router B configuration redistributes only OSPF external routes, including both type 1 and type 2 routes:
| RTB |
|---|
|
Router B redistributes only the OSPF external routes:
RTB#show ip bgp BGP table version is 25, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.2.2.2 20 32768 ? *> 192.168.2.0 10.2.2.2 23 32768 ? RTB#
Router C learns about these two OSPF external routes from BGP:
RTC#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.2/32 is directly connected, GigabitEthernet0/0 B 192.168.1.0/24 [20/20] via 10.3.3.1, 00:02:16 B 192.168.2.0/24 [20/23] via 10.3.3.1, 00:02:16
RTC#show ip bgp BGP table version is 21, local router ID is 10.3.3.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.3.3.1 20 0 100 ? *> 192.168.2.0 10.3.3.1 23 0 100 ? RTC#
In order to redistribute only OSPF external type 1 routes, enter this command under router bgp 100 on Router B:
RTB(config)#router bgp 100RTB(config-router)#redistribute ospf 1 match external 1
With the previous configuration, the Router B (RTB) BGP table shows that Router B redistributes only external type 1 routes into BGP, and all other OSPF routes are not redistributed into BGP:
RTB#show ip bgp BGP table version is 28, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.2.0 10.2.2.2 23 32768 ? RTB#
In order to redistribute only OSPF external type 2 routes, enter this command under router bgp 100 on Router B:
RTB(config)#router bgp 100RTB(config-router)#redistribute ospf 1 match external 2
In this case, OSPF internal routes and OSPF external type 1 and type 2 routes are redistributed into BGP with the internal and external match options, as shown in this Router B configuration:
| RTB |
|---|
|
Again, external is replaced with external 1 external 2 in the configuration. This is normal unless you specify which specific external routes you want to redistribute into BGP. After the configuration change, Router B redistributes the selected internal and external routes, and Router C learns them through BGP:
RTB#show ip bgp BGP table version is 6, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.2.2.0/24 0.0.0.0 0 32768 ? *> 10.108.1.0/24 10.2.2.2 3 32768 ? *> 10.108.2.0/24 10.2.2.2 2 32768 ? *> 192.168.1.0 10.2.2.2 20 32768 ? *> 192.168.2.0 10.2.2.2 23 32768 ? RTB#RTC#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks B 10.2.2.0/24 [20/0] via 10.3.3.1, 00:03:27 C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.2/32 is directly connected, GigabitEthernet0/0 B 10.108.1.0/24 [20/3] via 10.3.3.1, 00:03:27 B 10.108.2.0/24 [20/2] via 10.3.3.1, 00:03:27 B 192.168.1.0/24 [20/20] via 10.3.3.1, 00:03:27 B 192.168.2.0/24 [20/23] via 10.3.3.1, 00:03:27 RTC#
This is a special case in which only NSSA routes are redistributed into BGP. This case is very similar to the case described in the Redistribute Only OSPF External (Type 1 and 2) Routes into BGP section. The only difference is that OSPF now matches NSSA-external routes instead of just external routes. The routing table of Router B shows these OSPF NSSA-external routes:
RTB#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks C 10.2.2.0/24 is directly connected, GigabitEthernet0/1 L 10.2.2.3/32 is directly connected, GigabitEthernet0/1 C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.1/32 is directly connected, GigabitEthernet0/0 O IA 10.108.1.0/24 [110/3] via 10.2.2.2, 00:05:00, GigabitEthernet0/1 O 10.108.2.0/24 [110/2] via 10.2.2.2, 00:05:00, GigabitEthernet0/1 O N2 192.168.1.0/24 [110/20] via 10.2.2.1, 00:10:14, GigabitEthernet0/1 O N1 192.168.2.0/24 [110/22] via 10.2.2.2, 00:03:43, GigabitEthernet0/1 RTB#
This network diagram is used for this case:
Redistribution OSPF to BGP Topology B
The network diagram shows that Router B receives both OSPF N1 and N2 routes. The default behavior is to redistribute both N1 and N2 routes if only the nssa-external keyword is used. This configuration allows RTB to redistribute OSPF N2 (192.168.1.0/24) and OSPF N1 (192.168.2.0/24) routes into BGP:
| RTB |
|---|
|
After the configuration change on Router B, it redistributes OSPF NSSA-external routes, and Router C learns OSPF NSSA-external routes from BGP:
RTB#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks C 10.2.2.0/24 is directly connected, GigabitEthernet0/1 L 10.2.2.3/32 is directly connected, GigabitEthernet0/1 C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.1/32 is directly connected, GigabitEthernet0/0 O IA 10.108.1.0/24 [110/3] via 10.2.2.2, 00:09:40, GigabitEthernet0/1 O 10.108.2.0/24 [110/2] via 10.2.2.2, 00:09:40, GigabitEthernet0/1 O N2 192.168.1.0/24 [110/20] via 10.2.2.1, 00:14:54, GigabitEthernet0/1 O N1 192.168.2.0/24 [110/22] via 10.2.2.2, 00:08:23, GigabitEthernet0/1 RTB# RTB#show ip bgp BGP table version is 17, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.2.2.1 20 32768 ? *> 192.168.2.0 10.2.2.2 22 32768 ? RTB#RTC#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.2/32 is directly connected, GigabitEthernet0/0 B 192.168.1.0/24 [20/20] via 10.3.3.1, 00:01:29 B 192.168.2.0/24 [20/22] via 10.3.3.1, 00:01:29 RTC# RTC#show ip bgp BGP table version is 41, local router ID is 10.3.3.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.3.3.1 20 0 100 ? *> 192.168.2.0 10.3.3.1 22 0 100 ? RTC#
In the same way as with OSPF External routes, to redistribute only OSPF N1 routes, enter this command under router BGP 100 on Router B:
RTB(config)#router bgp 100
RTB(config-router)#redistribute ospf 1 match nssa-external 1
!--- This redistributes only OSPF NSSA-external Type-1 routes into BGP.
In order to redistribute only OSPF N2 routes, enter this command under router bgp 100 on Router B:
RTB(config)#router bgp 100redistribute ospf 1 match nssa-external 2
RTB(config-router)#
!--- This redistributes only OSPF NSSA-external Type-2 routes into BGP.
It is important to understand how successive configuration change alters your configuration. A new command with the match option does not overwrite the previous one but is added to it. The next example explains how the configuration command sequence can have an impact on redistribution:
R4#configure terminal R4(config)#router bgp 100 R4(config-router)#redistribute ospf 1 match internal R4(config-router)#^Z !--- Initially, you redistribute internal OSPF routes into BGP 100. R4#show run | include redistribute ospf redistribute ospf 1 match internal R4#configure terminal R4(config)#router bgp 100 R4(config-router)#redistribute ospf 1 match external R4(config-router)#^Z !--- With this second command, you tell BGP to also redistribute external OSPF routes. R4#show run | include redistribute ospf redistribute ospf 1 match internal external 1 external 2 R4# R4#configure terminal R4(config)#router bgp 100 R4(config-router)#no redistribute ospf 1 match external 2 R4(config-router)#^Z !--- With this no command, you only disable the redistribution of external type 2 into BGP.
!--- All other types of routes previously configured remain. R4#show run | include redistribute ospf redistribute ospf 1 match internal external 1 !--- As you can see, internal and external type 1 remain. R4#configure terminal R4(config)#router bgp 100 R4(config-router)#no redistribute ospf 1 match internal external 1 R4(config-router)#^Z !--- This no command removes all explicit match options but does not disable redistribution
!--- The remaining redistribute ospf 1 command uses the default behavior and redistributes
!--- internal routes only. R4#show run | include redistribute ospf redistribute ospf 1 R4#configure terminal R4(config)#router bgp 100 R4(config-router)#no redistribute ospf 1 !--- Use no redistribute ospf <process> command in order to disable OSPF-to-BGP redistribution completely. R4(config-router)# ^Z R4#show run | include redistribute ospf R4#
Route redistribution propagates routes learned through one protocol into another routing protocol. When BGP is redistributed into an IGP, only eBGP-learned routes are redistributed by default. The iBGP learned routes known on the router are not introduced into the IGP in order to prevent the creation of routing loops.
By default, the iBGP redistribution into IGP is disabled. Run the bgp redistribute-internal command in order to enable redistribution of iBGP routes into an IGP. Precautions need to be taken to redistribute specific routes with the use of route maps into IGP.
A sample configuration for redistribution of iBGP routes into OSPF is shown here:
Router(config)#router bgp 65345 Router(config-router)#bgp redistribute-internal ! Router(config)#router ospf 100 Router(config-router)#redistribute bgp 65345 subnets
Caution: Redistribution of iBGP-learned routes into an IGP can create routing loops within the autonomous system. Redistribute only explicitly approved prefixes with a route map.
In order to redistribute an OSPF-learned default route into BGP, permit only 0.0.0.0/0 in a route map, apply the route map to OSPF redistribution, and enable redistribution of the default route with default-information originate:
! route-map map_default_only permit 10 match ip address acl_default_only ! ip access-list standard acl_default_only permit 0.0.0.0 ! router bgp 64601 redistribute ospf 1 route-map map_default_only default-information originate !
!--- Distributes the default route in bgp
The network 0.0.0.0 command is a separate origination method and requires an exact default route in the routing table:
!
router bgp 64601
network 0.0.0.0
!
After the configuration, verify the default route with show ip bgp 0.0.0.0 and verify its advertisement with show ip bgp neighbors <neighbor-address> advertised-routes.
Note: BGP normally advertises the new route without a session reset. In order to request an immediate, nondisruptive update exchange, run clear ip bgp * soft command. This command keeps the BGP sessions established.
| Revision | Publish Date | Comments |
|---|---|---|
3.0 |
08-Sep-2026
|
Recertification - Updated SEO and Formatting |
2.0 |
22-Apr-2025
|
Titles, headers, and formatting. |
1.0 |
11-Oct-2001
|
Initial Release |