BGP AD manipulation

Many a times there are situations wherein you are running two routing protocols in our case BGP and any IGP protocol and you would like to prefer the route learned by IGP over BGP. However the problem here is that by default eBGP has an AD of 20 which will take preference over the other IGP protocols (OSPF= 110, EIGRP = 90, IS-IS = 115, RIP = 120).

Lets discuss how we can make this work. There are couple of options to achieve this:

  • Changing the AD for the route learned from the specific BGP neighbor.

 

 

 

 

We will use the command: distance <AD> <neighbor> <wildcard> <optional ACL>

The ip route on the R1 :
====================


R1#show ip route
Codes: 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

Gateway of last resort is not set
100.0.0.0/24 is subnetted, 1 subnets
B 100.171.106.0 [20/0] via 20.20.20.3, 00:08:29
20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/1
8.0.0.0/24 is subnetted, 1 subnets
B 8.8.8.0 [20/0] via 20.20.20.3, 00:09:10
10.0.0.0/24 is subnetted, 1 subnets
C 10.10.10.0 is directly connected, FastEthernet0/0

R1#show ip route 100.171.106.0
Routing entry for 100.171.106.0/24
Known via “bgp 65457”, distance 20, metric 0
Tag 65000, type external
Last update from 20.20.20.3 00:08:50 ago
Routing Descriptor Blocks:
* 20.20.20.3, from 20.20.20.3, 00:08:50 ago
Route metric is 0, traffic share count is 1
AS Hops 1

After adding the distance statement in BGP on R1 and rebuilding the peering:

R1(config)#access-list 1 permit 100.171.106.0 0.0.0.255
R1(config)#router bgp 65457
R1(config-router)#distance 200 20.20.20.3 255.255.255.255 1
R1#clear ip bgp 20.20.20.3

R1#show ip route
Codes: 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
Gateway of last resort is not set100.0.0.0/24 is subnetted, 1 subnets
D 100.171.106.0 [90/30720] via 10.10.10.2, 00:00:38, FastEthernet0/0
20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/1
8.0.0.0/24 is subnetted, 1 subnets
B 8.8.8.0 [20/0] via 20.20.20.3, 00:00:10
10.0.0.0/24 is subnetted, 1 subnets
C 10.10.10.0 is directly connected, FastEthernet0/0

R1#show ip route 100.171.106.0
Routing entry for 100.171.106.0/24
Known via “eigrp 1”, distance 90, metric 30720, type internal
Redistributing via eigrp 1
Last update from 10.10.10.2 on FastEthernet0/0, 00:02:38 ago
Routing Descriptor Blocks:

* 10.10.10.2, from 10.10.10.2, 00:02:38 ago, via FastEthernet0/0
Route metric is 30720, traffic share count is 1
Total delay is 200 microseconds, minimum bandwidth is 100000 Kbit
Reliability 255/255, minimum MTU 1500 bytes
Loading 1/255, Hops 1

Please note that this can also cause asymmetric routing issues. Lets see the below example.

In the above topology we are modifying the AD at the R2 and thus following is the R2 configuration:

router ospf 1
log-adjacency-changes
summary-address 192.168.20.0 255.255.255.0
redistribute connected subnets
network 30.30.30.0 0.0.0.255 area 0
!
router bgp 2
no synchronization
bgp log-neighbor-changes
network 192.168.20.0
neighbor 20.20.20.1 remote-as 1
distance 200 0.0.0.0 255.255.255.255 1
no auto-summary

R2#show ip route
Codes: 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
Gateway of last resort is not set

20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/0
O E2 192.168.10.0/24 [110/20] via 30.30.30.3, 01:22:57, FastEthernet0/1
C 192.168.20.0/24 is directly connected, Loopback0
10.0.0.0/24 is subnetted, 1 subnets
O E2 10.10.10.0 [110/20] via 30.30.30.3, 01:28:45, FastEthernet0/1
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.30.0 is directly connected, FastEthernet0/1

R2#show ip bgp
BGP table version is 4, local router ID is 192.168.20.2
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
r> 192.168.10.0 20.20.20.1 0 1 3 i
*> 192.168.20.0 0.0.0.0 0 32768 i

R2#show ip bgp 192.168.10.0
BGP routing table entry for 192.168.10.0/24, version 4
Paths: (1 available, best #1, table Default-IP-Routing-Table, RIB-failure(17))
Not advertised to any peer
1 3
20.20.20.1 from 20.20.20.1 (20.20.20.1)
Origin IGP, localpref 100, valid, external, best

R2#traceroute 192.168.10.3
Type escape sequence to abort.
Tracing the route to 192.168.10.3

1 30.30.30.3 12 msec 28 msec 28 msec

On R3 we still see it preferring BGP route over IGP:

R3#show ip route
Codes: 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
Gateway of last resort is not set

20.0.0.0/24 is subnetted, 1 subnets
O E2 20.20.20.0 [110/20] via 30.30.30.2, 01:33:45, FastEthernet0/1
C 192.168.10.0/24 is directly connected, Loopback0
B 192.168.20.0/24 [20/0] via 10.10.10.1, 01:27:13
10.0.0.0/24 is subnetted, 1 subnets
C 10.10.10.0 is directly connected, FastEthernet0/0
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.30.0 is directly connected, FastEthernet0/1

R3#show ip bgp
BGP table version is 5, local router ID is 30.30.30.3
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
*> 192.168.10.0 0.0.0.0 0 32768 i
*> 192.168.20.0 10.10.10.1 0 1 2 i

R3#show ip bgp
R3#show ip bgp 192.168.20.0
BGP routing table entry for 192.168.20.0/24, version 5
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Not advertised to any peer
1 2
10.10.10.1 from 10.10.10.1 (20.20.20.1)
Origin IGP, localpref 100, valid, external, best

R3#traceroute 192.168.20.2
Type escape sequence to abort.
Tracing the route to 192.168.20.2

1 10.10.10.1 28 msec 20 msec 16 msec
2 20.20.20.2 16 msec 20 msec 20 msec

You need to take care of asymmetric routing as this can be an issue for many applications.

  • Changing the BGP AD per address family.

 

By default, BGP has these distances:
External distance—20
Internal distance—200
Local distance—200

 

You can change the AD of all routes in the unicast, multicast or vrf address-family. This is done under the address-family section of the BGP process with the command, to change the default distance:

 

distance bgp <ebgp> <ibgp> <local routes>

 

This is not very scalable as all future BGP routes in that address-family will have their AD altered.
 Going back to our second topology, we see that the R2 router prefers BGP to reach to the network 192.168.10.0/24.

 

router bgp 2
no synchronization
bgp log-neighbor-changes
network 192.168.20.0
neighbor 20.20.20.1 remote-as 1
no auto-summary

 

R2#show ip route
Codes: 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

Gateway of last resort is not set
20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/0
B 192.168.10.0/24 [20/0] via 20.20.20.1, 00:01:01
C 192.168.20.0/24 is directly connected, Loopback0
10.0.0.0/24 is subnetted, 1 subnets
O E2 10.10.10.0 [110/20] via 30.30.30.3, 17:41:21, FastEthernet0/1
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.30.0 is directly connected, FastEthernet0/1

 

Lets modify the default ADs for the BGP routes.

 

R2(config-router)#distance bgp ?
<1-255> Distance for routes external to the AS
R2(config-router)#distance bgp 120 ?
<1-255> Distance for routes internal to the AS
R2(config-router)#distance bgp 120 220 ?
<1-255> Distance for local routes
R2(config-router)#distance bgp 120 220 210 ?
<cr>

R2(config-router)#distance bgp 120 220 210

 

router bgp 2
no synchronization
bgp log-neighbor-changes
network 192.168.20.0
neighbor 20.20.20.1 remote-as 1
distance bgp 120 220 210
no auto-summary
!

R2#show ip protocols
Routing Protocol is “bgp 2”
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
IGP synchronization is disabled
Automatic route summarization is disabled
Neighbor(s):
Address FiltIn FiltOut DistIn DistOut Weight RouteMap
20.20.20.1
Maximum path: 1
Routing Information Sources:
Gateway Distance Last Update
20.20.20.1 20 00:02:35
Distance: external 120 internal 220 local 210

R2#show ip route
Codes: 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
Gateway of last resort is not set20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/0
O E2 192.168.10.0/24 [110/20] via 30.30.30.3, 00:04:55, FastEthernet0/1
C 192.168.20.0/24 is directly connected, Loopback0
10.0.0.0/24 is subnetted, 1 subnets
O E2 10.10.10.0 [110/20] via 30.30.30.3, 17:49:14, FastEthernet0/1
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.30.0 is directly connected, FastEthernet0/1

 

R2#show ip bgp 192.168.10.0
BGP routing table entry for 192.168.10.0/24, version 3
Paths: (1 available, best #1, table Default-IP-Routing-Table, RIB-failure(17))
Not advertised to any peer
1 3
20.20.20.1 from 20.20.20.1 (20.20.20.1)
Origin IGP, localpref 100, valid, external, best

 

R2#show ip bgp rib-failure
Network Next Hop RIB-failure RIB-NH Matches
192.168.10.0 20.20.20.1 Higher admin distance n/a

 

  • Using the BGP Backdoor :

 

With BGP Backdoor, BGP treats that network as a locally assigned network and thus changes the AD from 20 to 200. However it does not advertise that specific network into the BGP updates.

 

network <network> mask <network mask> backdoor

 

Some useful information on the following link:

 

 

 

R2#show ip route
Codes: 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

Gateway of last resort is not set
20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/0
192.168.10.0/32 is subnetted, 1 subnets
B 192.168.10.3 [20/0] via 20.20.20.1, 00:06:13
192.168.20.0/32 is subnetted, 1 subnets
C 192.168.20.2 is directly connected, Loopback0
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.30.0 is directly connected, FastEthernet0/1

 

router bgp 2
no synchronization
bgp log-neighbor-changes
network 192.168.10.3 mask 255.255.255.255 backdoor
network 192.168.20.2 mask 255.255.255.255
neighbor 20.20.20.1 remote-as 1
no auto-summary

 

R2#show ip route
Codes: 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
Gateway of last resort is not set20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/0
192.168.10.0/32 is subnetted, 1 subnets
O 192.168.10.3 [110/2] via 30.30.30.3, 00:00:32, FastEthernet0/1
192.168.20.0/32 is subnetted, 1 subnets
C 192.168.20.2 is directly connected, Loopback0
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.30.0 is directly connected, FastEthernet0/1

 

R2#show ip bgp
BGP table version is 4, local router ID is 192.168.20.2
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
r> 192.168.10.3/32 20.20.20.1 0 1 3 i
*> 192.168.20.2/32 0.0.0.0 0 32768 i

 

R2#show ip bgp 192.168.10.3/32
BGP routing table entry for 192.168.10.3/32, version 4
Paths: (1 available, best #1, table Default-IP-Routing-Table, RIB-failure(17))
Not advertised to any peer
1 3
20.20.20.1 from 20.20.20.1 (20.20.20.1)
Origin IGP, localpref 100, valid, external, best

 

R2#show ip bgp rib-failure
Network Next Hop RIB-failure RIB-NH Matches
192.168.10.3/32 20.20.20.1 Higher admin distance n/a

 

  • Changing the AD of IGP :

 

We can also modify the AD of IGP to make it prefer  over BGP:

R2#show ip route
Codes: 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

Gateway of last resort is not set
20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/0
192.168.10.0/32 is subnetted, 1 subnets
B 192.168.10.3 [20/0] via 20.20.20.1, 00:00:05
192.168.20.0/32 is subnetted, 1 subnets
C 192.168.20.2 is directly connected, Loopback0
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.30.0 is directly connected, FastEthernet0/1

R2(config)#access-list 10 permit 192.168.10.0 0.0.0.255
R2(config)#router ospf 1
R2(config-router)#distan
R2(config-router)#distance 15 30.30.30.3 255.255.255.255 10

router ospf 1
log-adjacency-changes
redistribute connected
network 30.30.30.0 0.0.0.255 area 0
network 192.168.20.0 0.0.0.255 area 0
distance 15 0.0.0.0 255.255.255.255 10

R2#show ip route
Codes: 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
Gateway of last resort is not set20.0.0.0/24 is subnetted, 1 subnets
C 20.20.20.0 is directly connected, FastEthernet0/0
192.168.10.0/32 is subnetted, 1 subnets
O 192.168.10.3 [15/2] via 30.30.30.3, 00:01:35, FastEthernet0/1
192.168.20.0/32 is subnetted, 1 subnets
C 192.168.20.2 is directly connected, Loopback0
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.30.0 is directly connected, FastEthernet0/1

 

 

Thanks….

One thought on “BGP AD manipulation

Leave a Reply

Your email address will not be published. Required fields are marked *