BGP prefix injection: Redistribution
A prefix can be advertised in BGP if it is present in the RIB by using the redistribute command. The type of redistributed route depends on the redistributed protocol selected: connected routes, static route or IGP routes. Using the redistribute command the injecting peer sets the following attributes:
– Weight as 32768 (making it locally always preferred, unless otherwise configured);
– Local Pref unchanged;
– AS Path as usual;
– Origin as Incomplete (basically this makes, by default, a route injected via the network command preferred);
– MED zero or unset;
– Sets the next hop as itself (0.0.0.0).
1720a(config)#ip prefix-list ONLY_41 seq 100 permit 10.41.0.0/16
1720a(config)#ip prefix-list ONLY_41 seq 500 deny 0.0.0.0/0 ge 1
1720a(config)#route-map ALLOW_ONLY_41
1720a(config-route-map)#match ip address prefix-list ONLY_41
1720a(config)#router bgp 400
1720a(config-router)#redistribute connected route-map ALLOW_ONLY_41
1720a#sh ip bgp
BGP table version is 5, local router ID is 192.168.0.2
Status codes: s suppressed, d damped, h history, valid, > best, i – internal,
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
10.22.0.0/16 192.168.103.2 0 100 200 i
> 192.168.104.254 0 100 200 i
192.168.102.2 0 100 200 i
>i10.40.0.0/16 192.168.0.1 0 100 0 i
> 10.41.0.0/16 0.0.0.0 0 32768 ?
1720a#sh ip bgp 10.41.0.0
BGP routing table entry for 10.41.0.0/16, version 5
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
Advertised to peer-groups:
eBGP_to_AS100
Advertised to non peer-group peers:
192.168.0.1
Local
0.0.0.0 from 0.0.0.0 (192.168.0.2)
Origin incomplete, metric 0, localpref 100, weight 32768, valid, sourced, best
Redistribution of an IGP has the same effect:
1600b(config)#ip prefix-list ONLY_11 seq 100 permit 10.11.0.0/16
1600b(config)#ip prefix-list ONLY_11 seq 500 deny 0.0.0.0/0 ge 1
1600b(config)#route-map ALLOW_ONLY_11
1600b(config-route-map)#match ip address prefix-list ONLY_11
1600b(config-route-map)#router bgp 100
1600b(config-router)#redistribute rip route-map ALLOW_ONLY_11
1600b#clear ip bgp soft in
1600b#sh ip bgp
BGP table version is 8, local router ID is 192.168.0.5
Status codes: s suppressed, d damped, h history, valid, > best, i – internal
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
> 10.0.0.0 0.0.0.0 0 32768 ?
> 10.22.0.0/16 192.168.109.2 130816 0 200 i
i10.40.0.0/16 192.168.102.1 0 100 0 400 i
i 192.168.107.1 0 100 0 400 i
> 192.168.104.1 0 0 400 i
i10.41.0.0/16 192.168.102.1 0 100 0 400 ?
> 192.168.104.1 0 0 400 ?
i 192.168.103.1 0 100 0 400 ?
1600b#sh ip bgp 10.0.0.0
BGP routing table entry for 10.0.0.0/8, version 8
Paths: (1 available, best #1)
Flag: 0x820
Advertised to peer-groups:
iBGP_peers
Advertised to non peer-group peers:
192.168.104.1 192.168.109.2
Local
0.0.0.0 from 0.0.0.0 (192.168.0.5)
Origin incomplete, metric 0, localpref 100, weight 32768, valid, sourced, best
hostname 1720a
!
interface Loopback400
ip address 10.41.0.1 255.255.0.0
!
interface Loopback999
ip address 192.168.0.2 255.255.255.255
!
interface Ethernet0
description to switch02 – remote port 0/4
ip address 192.168.103.1 255.255.255.0
half-duplex
!
interface FastEthernet0
description to switch1 remote port 0/23 – utp cable n.10
ip address 192.168.102.1 255.255.255.0
speed auto
!
interface Serial0
description to 1720B – remote port s0 – cable n.7
ip address 192.168.104.1 255.255.255.0
encapsulation frame-relay
ip ospf network point-to-multipoint
clockrate 64000
no arp frame-relay
frame-relay map ip 192.168.104.254 407 broadcast
frame-relay map ip 192.168.104.2 407 broadcast
no frame-relay inverse-arp
!
interface Serial1
description to 2610b s0/1
ip address 192.168.101.2 255.255.255.0
clockrate 2000000
!
router bgp 400
no synchronization
bgp router-id 192.168.0.2
bgp log-neighbor-changes
timers bgp 30 90
redistribute connected route-map ALLOW_ONLY_41
neighbor eBGP_to_AS100 peer-group
neighbor eBGP_to_AS100 remote-as 100
neighbor eBGP_to_AS100 route-map set_MED out
neighbor 192.168.0.1 remote-as 400
neighbor 192.168.0.1 update-source Loopback999
neighbor 192.168.102.2 peer-group eBGP_to_AS100
neighbor 192.168.103.2 peer-group eBGP_to_AS100
neighbor 192.168.104.254 peer-group eBGP_to_AS100
no auto-summary
!
ip prefix-list ONLY_41 seq 100 permit 10.41.0.0/16
ip prefix-list ONLY_41 seq 500 deny 0.0.0.0/0 ge 1
!
route-map ALLOW_ONLY_41 permit 10
match ip address prefix-list ONLY_41
!
route-map set_MED permit 500
set metric 0
!
end
hostname 1600b
!
interface Loopback350
ip address 10.32.11.1 255.255.255.0
!
interface Loopback400
ip address 10.11.0.1 255.255.0.0
!
interface Loopback999
ip address 192.168.0.5 255.255.255.255
!
interface Ethernet0
ip address 192.168.109.1 255.255.255.252
!
interface Serial0
encapsulation frame-relay
!
interface Serial0.1 point-to-point
ip address 192.168.105.2 255.255.255.0
frame-relay interface-dlci 701
!
interface Serial0.2 multipoint
ip address 192.168.104.254 255.255.255.0
no ip split-horizon eigrp 1
ip ospf network point-to-multipoint
frame-relay map ip 192.168.104.1 704 broadcast
frame-relay map ip 192.168.104.2 706 broadcast
!
router ospf 1
router-id 192.168.0.5
log-adjacency-changes
redistribute rip subnets
passive-interface Loopback999
network 192.168.0.5 0.0.0.0 area 101
network 192.168.104.254 0.0.0.0 area 101
default-metric 100
distribute-list 10 out
!
router rip
version 2
redistribute ospf 1
passive-interface Loopback400
network 10.0.0.0
network 192.168.105.0
network 192.168.109.0
default-metric 8
distribute-list 10 out
no auto-summary
!
router bgp 100
no synchronization
bgp router-id 192.168.0.5
bgp cluster-id 3232263425
bgp log-neighbor-changes
network 10.32.11.0 mask 255.255.255.0 route-map Set_Community
timers bgp 30 90
redistribute rip route-map ALLOW_ONLY_11
neighbor iBGP_peers peer-group
neighbor iBGP_peers remote-as 100
neighbor iBGP_peers password test_pswd
neighbor iBGP_peers update-source Loopback999
neighbor iBGP_peers route-map Prevent_11 out
neighbor 192.168.0.3 peer-group iBGP_peers
neighbor 192.168.0.6 peer-group iBGP_peers
neighbor 192.168.104.1 remote-as 400
neighbor 192.168.104.1 route-map Prevent_11 out
neighbor 192.168.109.2 remote-as 200
!
ip community-list 10 permit 6553611
!
ip prefix-list ONLY_11 seq 100 permit 10.11.0.0/16
ip prefix-list ONLY_11 seq 500 deny 0.0.0.0/0 ge 1
!
access-list 10 deny 10.32.11.0 0.0.0.255
access-list 10 permit any
!
route-map Prevent_11 deny 10
match community 10
!
route-map Prevent_11 permit 20
!
route-map ALLOW_ONLY_11 permit 10
match ip address prefix-list ONLY_11
!
route-map Set_Community permit 10
set community 6553611 additive
!
end
BGP prefix injection: Default Originate
The “neighbor default-originate” command allows the peer to inject a default route in the network WITHOUT requiring the presence of 0.0.0.0 in the local router or in its BGP table (thus, no requirement applicable). To conditionally inject it a route map can be used to return a positive match based on a matches clause (address with ACL). The route is injected with no MED, and with origin as IGP (?!!?). It can be sent to iBGP or eBGP neighbors.
=> NOTE: the route injected is advertised to the selected neighbor but is NOT inserted in the local BGP table!!
=> neighbor {ip-address | peer-group-name} default-originate [route-map map-name]
Important: using the network or redistribute command the 0.0.0.0/0 network can be advertised as well. In this case there is a implict dependence with the network or redistribute command as usual.
2514a(config-router)#neighbor 192.168.111.1 default-originate
2514a#clear ip bgp soft out
2514a#sh ip bgp
BGP table version is 10, local router ID is 192.168.0.8
Status codes: s suppressed, d damped, h history, valid, > best, i – internal,
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
>i10.0.0.0 192.168.109.1 0 100 0 100 ?
192.168.111.1 0 300 100 ?
> 10.22.0.0/16 0.0.0.0 0 32768 i
>i10.40.0.0/16 192.168.109.1 0 100 0 100 400 i
192.168.111.1 0 300 100 400 i
>i10.41.0.0/16 192.168.109.1 0 100 0 100 400 ?
192.168.111.1 0 300 100 400 ?
2514b#sh ip bgp
BGP table version is 9, local router ID is 192.168.0.7
Status codes: s suppressed, d damped, h history, valid, > best, i – internal,
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
> 0.0.0.0 192.168.111.2 0 200 i
10.0.0.0 192.168.111.2 0 200 100 ?
>i 192.168.106.1 0 100 0 100 ?
> 10.22.0.0/16 192.168.111.2 0 0 200 i
10.40.0.0/16 192.168.111.2 0 200 100 400 i
>i 192.168.106.1 0 100 0 100 400 i
10.41.0.0/16 192.168.111.2 0 200 100 400 ?
>i 192.168.106.1 0 100 0 100 400 ?
2514b#sh ip bgp 0.0.0.0
BGP routing table entry for 0.0.0.0/0, version 9
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
192.168.0.4
200
192.168.111.2 from 192.168.111.2 (192.168.0.8)
Origin IGP, localpref 100, valid, external, best
Adding a Route Map Condition (only ACL is supported, no prefix-ist):
2514a(config)#ip access-list standard PREFIX_CONDITION
2514a(config-std-nacl)#permit 192.168.108.0 0.0.0.3
2514a(config-std-nacl)#deny any
2514a(config-std-nacl)#route-map IF_Clause_Verified
2514a(config-route-map)#match ip address PREFIX_CONDITION
2514a(config-route-map)#set local-preference 200
2514a(config-route-map)#router bgp 200
2514a(config-router)#neighbor 192.168.0.9 default-originate route-map IF_Clause_Verified
switch02#sh ip bgp
BGP table version is 20, local router ID is 192.168.0.9
Status codes: s suppressed, d damped, h history, valid, > best, i – internal,
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
>i0.0.0.0 192.168.0.8 200 0 i
> 10.0.0.0 192.168.109.1 0 0 100 ?
i10.22.0.0/16 192.168.0.8 0 100 0 i
> 192.168.110.2 130816 32768 i
> 10.40.0.0/16 192.168.109.1 0 100 400 i
> 10.41.0.0/16 192.168.109.1 0 100 400 ?
Note the following peer: choses the prefix based on AS PATH lenght.
1720b#sh ip bgp
BGP table version is 25, local router ID is 192.168.0.3
Status codes: s suppressed, d damped, h history, valid, > best, i – internal,
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
>i0.0.0.0 192.168.109.2 100 0 200 i
192.168.106.2 0 300 200 i
1720b#sh ip bgp 0.0.0.0
BGP routing table entry for 0.0.0.0/0, version 25
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
192.168.102.1 192.168.106.2
200
192.168.109.2 (metric 100) from 192.168.0.5 (192.168.0.5)
Origin IGP, localpref 100, valid, internal, best
300 200
192.168.106.2 from 192.168.106.2 (192.168.0.4)
Origin IGP, localpref 100, valid, external
Changing the AS PATH form the originating AS:
switch02(config)#router bgp 200
switch02(config-router)#neighbor 192.168.109.1 route-map Prepend out
switch02(config)#ip prefix-list Default_Only seq 100 permit 0.0.0.0/0
switch02(config)#route-map Prepend
switch02(config-route-map)#match ip address prefix-list Default_Only
switch02(config-route-map)#set as-path prepend 200 200
switch02#clear ip bgp soft out
1600b#clear ip bgp soft in
1600b#sh ip bgp
BGP table version is 28, local router ID is 192.168.0.5
Status codes: s suppressed, d damped, h history, valid, > best, i – internal
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
>i0.0.0.0 192.168.106.2 0 100 0 300 200 i
192.168.109.2 0 200 200 200 i
1720b#sh ip bgp
BGP table version is 29, local router ID is 192.168.0.3
Status codes: s suppressed, d damped, h history, valid, > best, i – internal,
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
> 0.0.0.0 192.168.106.2 0 300 200 i
hostname 2514a
!
interface Loopback300
ip address 10.22.0.1 255.255.0.0
!
interface Loopback350
ip address 10.32.10.1 255.255.255.0
!
interface Loopback400
ip address 10.21.0.1 255.255.0.0
!
interface Loopback999
ip address 192.168.0.8 255.255.255.255
!
interface Ethernet0
ip address 192.168.111.2 255.255.255.252
no ip redirects
no ip route-cache
no ip mroute-cache
no cdp enable
!
interface Ethernet1
ip address 192.168.110.2 255.255.255.252
no ip route-cache
no ip mroute-cache
no cdp enable
!
router eigrp 1
passive-interface Loopback300
passive-interface Loopback999
network 10.22.0.0 0.0.255.255
network 192.168.0.8 0.0.0.0
network 192.168.110.0 0.0.0.3
network 192.168.111.0 0.0.0.3
no auto-summary
!
router bgp 200
no synchronization
bgp router-id 192.168.0.8
bgp log-neighbor-changes
network 10.22.0.0 mask 255.255.0.0
network 10.32.10.0 mask 255.255.255.0
timers bgp 30 90
neighbor 192.168.0.9 remote-as 200
neighbor 192.168.0.9 update-source Loopback999
neighbor 192.168.0.9 send-community both
neighbor 192.168.0.9 default-originate route-map IF_Clause_Verified
neighbor 192.168.111.1 remote-as 300
neighbor 192.168.111.1 default-originate
no auto-summary
!
ip bgp-community new-format
!
ip access-list standard PREFIX_CONDITION
permit 192.168.108.0 0.0.0.3
deny any
!
route-map IF_Clause_Verified permit 10
match ip address PREFIX_CONDITION
set local-preference 200
!
end
hostname switch02
!
interface Loopback400
ip address 10.20.0.1 255.255.0.0
!
interface Loopback999
ip address 192.168.0.9 255.255.255.255
!
interface FastEthernet0/13
description trunk to switch01 port 0/13
no switchport
ip address 192.168.109.2 255.255.255.252
speed 100
duplex full
!
interface FastEthernet0/14
description trunk to switch01 port 0/14
switchport mode dynamic desirable
speed 100
duplex full
!
interface Vlan103
ip address 192.168.110.1 255.255.255.252
!
router eigrp 1
network 192.168.0.9 0.0.0.0
network 192.168.110.0 0.0.0.3
no auto-summary
!
router rip
version 2
network 192.168.109.0
no auto-summary
!
router bgp 200
no synchronization
bgp router-id 192.168.0.9
bgp log-neighbor-changes
network 10.22.0.0 mask 255.255.0.0
timers bgp 30 90
neighbor 192.168.0.8 remote-as 200
neighbor 192.168.0.8 update-source Loopback999
neighbor 192.168.0.8 next-hop-self
neighbor 192.168.0.8 send-community both
neighbor 192.168.0.8 route-map NO_EXPORT in
neighbor 192.168.109.1 remote-as 100
no auto-summary
!
ip bgp-community new-format
!
ip prefix-list Default_Only seq 100 permit 0.0.0.0/0
ip prefix-list TO_not_be_exported seq 10 permit 10.32.10.0/24
!
route-map Prepend permit 10
match ip address prefix-list Default_Only
set as-path prepend 200 200
!
route-map NO_EXPORT permit 10
match ip address prefix-list TO_not_be_exported
set community no-export
!
end