This article describes 3 different techniques to filter inbound BGP routes.
Let's consider a scenario where we have 2 different companies. The first company has its own DC running OSPF internally with everything in area 0, its own ASN and BGP peering to ISP A. The second company has another DC, which is also running OSPF internally in area 0, with a different ASN and BGP peering to ISP A.
In order to resolve this issue, we need to have some mechanisms in place that prevents routes announced from DC1 to ISP A via eBGP to be learned via BGP and injected back into OSPF in the DC2 and vice versa. You can find the lab file at the end of this post.
Method 1: The traditional way of doing it
R1-DC01# show ip route 80.80.200.0Routing entry for 80.80.200.0/24 Known via "ospf 1", distance 110, metric 1 Tag 65100, type extern 2, forward metric 20 Last update from 10.100.12.2 on Ethernet0/0, 00:03:57 ago Routing Descriptor Blocks: * 10.100.12.2, from 10.100.100.2, 00:03:57 ago, via Ethernet0/0 Route metric is 1, traffic share count is 1 Route tag 65100
R2-DC01# show ip route 80.80.200.0Routing entry for 80.80.200.0/24 Known via "bgp 65001", distance 20, metric 0 Tag 65100, type external Redistributing via ospf 1 Advertised by ospf 1 subnets Last update from 100.100.23.3 00:04:42 ago Routing Descriptor Blocks: * 100.100.23.3, from 100.100.23.3, 00:04:42 ago Route metric is 0, traffic share count is 1 AS Hops 2 Route tag 65100
R5-DC02#show ip route 80.80.100.0Routing entry for 80.80.100.0/24 Known via "bgp 65002", distance 20, metric 0 Tag 65100, type external Last update from 100.100.45.4 00:10:10 ago Routing Descriptor Blocks: * 100.100.45.4, from 100.100.45.4, 00:10:10 ago Route metric is 0, traffic share count is 1 AS Hops 2 Route tag 65100
R6-DC02#show ip route 80.80.100.0Routing entry for 80.80.100.0/24 Known via "ospf 1", distance 110, metric 1 Tag 65100, type extern 2, forward metric 20 Last update from 10.200.56.5 on Ethernet0/0, 00:00:17 ago Routing Descriptor Blocks: * 10.200.56.5, from 10.200.200.5, 00:00:17 ago, via Ethernet0/0 Route metric is 1, traffic share count is 1 Route tag 65100
R2-DC01#ip prefix-list INTERNAL seq 10 permit 80.80.0.0/16 ge 24route-map FILTER-IN deny 10 match ip address prefix-list INTERNALroute-map FILTER-IN permit 20
router bgp 65001 bgp log-neighbor-changes neighbor 100.100.23.3 remote-as 65100 address-family ipv4 network 80.80.100.0 mask 255.255.255.0 neighbor 100.100.23.3 activate neighbor 100.100.23.3 route-map FILTER-IN in
R5-DC02#ip prefix-list INTERNAL seq 10 permit 80.80.0.0/16 ge 24route-map FILTER-IN deny 10 match ip address prefix-list INTERNALroute-map FILTER-IN permit 20
router bgp 65002 neighbor 100.100.45.4 remote-as 65100 address-family ipv4 network 80.80.200.0 mask 255.255.255.0 neighbor 100.100.45.4 activate neighbor 100.100.45.4 route-map FILTER-IN in
R1-DC01#show ip route 80.80.200.0Routing entry for 80.80.200.0/24 Known via "ospf 1", distance 110, metric 20, type extern 2, forward metric 10 Last update from 10.100.200.6 on Ethernet0/1, 00:05:04 ago Routing Descriptor Blocks: * 10.100.200.6, from 10.200.200.6, 00:05:04 ago, via Ethernet0/1 Route metric is 20, traffic share count is 1
R2-DC01#show ip route 80.80.200.0Routing entry for 80.80.200.0/24 Known via "ospf 1", distance 110, metric 20, type extern 2, forward metric 20 Last update from 10.100.12.1 on Ethernet0/0, 00:05:45 ago Routing Descriptor Blocks: * 10.100.12.1, from 10.200.200.6, 00:05:45 ago, via Ethernet0/0 Route metric is 20, traffic share count is 1
R5-DC02#show ip route 80.80.100.0Routing entry for 80.80.100.0/24 Known via "ospf 1", distance 110, metric 20, type extern 2, forward metric 20 Last update from 10.200.56.6 on Ethernet0/0, 00:08:54 ago Routing Descriptor Blocks: * 10.200.56.6, from 10.100.100.1, 00:08:54 ago, via Ethernet0/0 Route metric is 20, traffic share count is 1
R6-DC02#show ip route 80.80.100.0Routing entry for 80.80.100.0/24 Known via "ospf 1", distance 110, metric 20, type extern 2, forward metric 10 Last update from 10.100.200.1 on Ethernet0/1, 00:09:50 ago Routing Descriptor Blocks: * 10.100.200.1, from 10.100.100.1, 00:09:50 ago, via Ethernet0/1 Route metric is 20, traffic share count is 1
Method 2: The well known attribute
R2-DC01#ip as-path access-list 1 deny ^65002$ip as-path access-list 1 permit .*
router bgp 65001 address-family ipv4 neighbor 100.100.23.3 filter-list 1 in exit-address-family
R5-DC02#ip as-path access-list 1 deny ^65001$ip as-path access-list 1 permit .*
router bgp 65002 address-family ipv4 neighbor 100.100.45.4 filter-list 1 in
Method 3: Some magic?
R2-DC01#show ip bgp 80.80.200.0BGP routing table entry for 80.80.200.0/24, version 13Paths: (1 available, best #1, table default) Not advertised to any peer Refresh Epoch 1 65100 65002 100.100.23.3 from 100.100.23.3 (100.100.100.3) Origin IGP, localpref 100, valid, external, best rx pathid: 0, tx pathid: 0x0
R5-DC02#show ip bgp 80.80.100.0BGP routing table entry for 80.80.100.0/24, version 22Paths: (1 available, best #1, table default) Not advertised to any peer Refresh Epoch 1 65100 65001 100.100.45.4 from 100.100.45.4 (100.100.100.4) Origin IGP, localpref 100, valid, external, best rx pathid: 0, tx pathid: 0x0
R5-DC02#show run | se router bgprouter bgp 65001 bgp log-neighbor-changes neighbor 100.100.45.4 remote-as 65100 neighbor 100.100.45.4 local-as 65002 ! address-family ipv4 neighbor 100.100.45.4 activate exit-address-family
R3-ISP# show ip bgp 80.80.200.0BGP routing table entry for 80.80.200.0/24, version 17Paths: (1 available, best #1, table default) Advertised to update-groups: 10 Refresh Epoch 1 65002 65001 100.100.34.4 from 100.100.34.4 (100.100.100.4) Origin IGP, metric 20, localpref 100, valid, internal, best
R2-DC01#show ip route 80.80.200.0Routing entry for 80.80.200.0/24 Known via "ospf 1", distance 110, metric 20, type extern 2, forward metric 20 Last update from 10.100.12.1 on Ethernet0/0, 00:11:02 ago Routing Descriptor Blocks: * 10.100.12.1, from 10.200.200.6, 00:11:02 ago, via Ethernet0/0 Route metric is 20, traffic share count is 1
R5-DC02#show ip route 80.80.100.0Routing entry for 80.80.100.0/24 Known via "ospf 1", distance 110, metric 20, type extern 2, forward metric 20 Last update from 10.200.56.6 on Ethernet0/0, 00:10:07 ago Routing Descriptor Blocks: * 10.200.56.6, from 10.100.100.1, 00:10:07 ago, via Ethernet0/0 Route metric is 20, traffic share count is 1