BGP seleccion de ruta LocalPreference

Tenemos un escenario como el siguiente

Queremos forzar que un link sea el principal y otro el secundario, con LocalPreference podemos cambiar el "peso" de las rutas y ese valor se anuncia a los routers iBGP, con lo que el peso con el que uno marque la ruta entrante así lo verán todos. El valor por defecto es 100, y si no pone nada tambien es 100 (no 0, no confundir).
Vamos a ver las configuraciones de los 4 routers.

La de R1
R1#sh run | s bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.2 remote-as 300
 neighbor 20.0.0.2 remote-as 100
 neighbor 20.0.0.2 next-hop-self
 no auto-summary

La de R2
R2#sh run | s bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.6 remote-as 200
 neighbor 20.0.0.1 remote-as 100
 neighbor 20.0.0.1 next-hop-self
 no auto-summary

La de R3
R3#sh run | s bgp
router bgp 300
 no synchronization
 bgp log-neighbor-changes
 redistribute static
 neighbor 10.0.0.1 remote-as 100
 default-information originate
 no auto-summary

La de R4
R4#sh run | s bgp
router bgp 200
 no synchronization
 bgp log-neighbor-changes
 redistribute static
 neighbor 10.0.0.5 remote-as 100
 default-information originate
 no auto-summary

Desde R1 le pondremos un valor de LocalPrefrence 200 a las rutas aprendias por el AS300 y desde R2 un valor de LocalPrefernce 150 a las rutas aprendidas por el AS200 de tal forma que en ambos dos routers se reflejen los valores establecidos y R1 sea el enlace principal y R2 el de backup.
Veamos que añadimos en R1

En R1 añadiremos
route-map Local permit 10
 set local-preference 200

router bgp 100
 neighbor 10.0.0.2 route-map Local in

En R2 añadiremos
route-map Local permit 10
 set local-preference 150

router bgp 100
 neighbor 10.0.0.6 route-map Local in

Veremos el resultado de las rutas BGP en R1, no inserta la ruta de backup poque la considera dupicada, en caso de caer el link con el router 10.0.0.2 actualizará la ruta con la de R2
R1#sh ip bgp


   Network          Next Hop            Metric LocPrf Weight Path
*> 0.0.0.0          10.0.0.2                 0    200      0 300 ?

R2 ve las dos rutas la que el anuncia a través de R4 y la que le anuncia R1 la cual marca como instalada en la tabla de rutas puesto que le llega con valor Local-Preference más alto.
R2#sh ip bgp


   Network          Next Hop            Metric LocPrf Weight Path
*>i0.0.0.0          20.0.0.1                 0    200      0 300 ?
*                   10.0.0.6                 0    150      0 200 ?

BGP seleccion de ruta WEIGHT

Vamos a utilizar el parámetro weight para forzar el camino hacia una cierta ruta y utilice otro enlace de bakcup.
Utilizaremos el siguiente ejemplo


El valor weight en BGP es propietario de Cisco Systems y es significativo solo localmente en el router, no se propaga en el dominio BGP.

Vamos a ver como aprende las rutas

La config de R1
R1#sh run | s bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.2 remote-as 200
 neighbor 10.0.0.6 remote-as 300
 no auto-summary

La config de R2
R2#sh run | s bgp
router bgp 200
 no synchronization
 bgp log-neighbor-changes
 redistribute static
 neighbor 10.0.0.1 remote-as 100
 default-information originate
 no auto-summary

La config de R3
R3#sh run | s bgp
router bgp 300
 no synchronization
 bgp log-neighbor-changes
 redistribute static
 neighbor 10.0.0.5 remote-as 100
 default-information originate
 no auto-summary

Vamos a configurar nuestro route R1 para que aumente el valor Weith de las rutas aprendidas por R2 para que actue como enlace principal y R3 como enlace de backup
R1#sh run | s bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.2 remote-as 200
 neighbor 10.0.0.2 weight 100
 neighbor 10.0.0.6 remote-as 300
 neighbor 10.0.0.6 weight 50
 no auto-summary

Forzamos un soft reconfiguracion y vemos como quedan las rutas aprendias
R1#clear ip bgp * soft in
R1#sh ip bgp



   Network          Next Hop            Metric LocPrf Weight Path
*  0.0.0.0          10.0.0.6                 0            50 300 ?
*>                  10.0.0.2                 0           100 200 ?
El valor de Weight por defecto es 0 para todas las rutas aprendidas y 32768 para todas las rutas localmente anunciadas, a mayor valor más prioridad para que sea la ruta desada.

BGP Sumarizando rutas inject-map

Si tenemos el siguiente esquema y necesitamos que R2 anuncie una ruta que ya está sumarizada, y queremos que reciba R3.


Vemos las configuraciones iniciales:
R1#sh run | s bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 network 192.168.0.0
 network 192.168.1.0
 network 192.168.3.0
 aggregate-address 192.168.0.0 255.255.252.0 summary-only
 neighbor 10.0.0.2 remote-as 200
 no auto-summary
R2#sh run | s bgp
router bgp 200
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.1 remote-as 100
 neighbor 10.0.0.6 remote-as 300
 no auto-summary
R3#sh run | s bgp
router bgp 300
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.5 remote-as 200
 no auto-summary
Ahora en R2 para inyectar la ruta 192.168.2.0/24 tenemos que añadir unas cuantas cosas, primero añadiremos en la configuración de BGP de R2
bgp inject-map INJECTED exist-map LEARNED
donde INJECTED y LEARNED son dos route maps, los cuales se basan en 3 prefix-list, una para las rutas aprendidas
ip prefix-list INJECTED seq 5 permit 192.168.0.0/30
Otra para la ruta a inyectar
ip prefix-list LEARNED seq 5 permit 192.168.0.0/22
Y la última que marca el vecino del cual aprendemos la ruta sumarizada
ip prefix-list VECINO seq 5 permit 10.0.0.1/32
Y creamos el route-map INJECTED y el route-map LEARNED
route-map INJECTED permit 10
 set ip address prefix-list INJECTED
!
route-map LEARNED permit 10
 match ip address prefix-list LEARNED
 match ip route-source prefix-list VECINO
y en R3 deberemos ver la ruta más específica inyectada en la tabla bgp
R3#sh ip bgp
BGP table version is 5, local router ID is 10.0.0.6
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.0.0/22   10.0.0.5                               0 200 100 i
*> 192.168.2.0      10.0.0.5                               0 200 ?

BGP Sumarizando rutas II unsupress-map

Utilizaremos el siguiente dibujo
Queremos que la red 192.168.2.0 no esté sumarizada aunque se suprima con el summary-only. La configuración de R1 será la siguiente
R1#sh run |  s bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 network 192.168.0.0
 network 192.168.1.0 network 192.168.2.0
 network 192.168.3.0
 aggregate-address 192.168.0.0 255.255.252.0 summary-only
 neighbor 10.0.0.2 remote-as 200
 no auto-summary

R2 verá una única ruta
R2#sh ip bgp

   Network          Next Hop            Metric LocPrf Weight Path

*> 192.168.0.0/22   10.0.0.1                 0             0 100 i

Ahora crearemos una ACL o un PREFIX-LIST para marcar la ruta que se va a anunciar con su propia máscara más específica
ip access-list standard UNSUPRESS
 permit 192.168.2.0 0.0.0.255
 deny   any
Aplicaremos esa access-list o prefix-list a un route-map
route-map UNSUPRESS permit 10
 match ip address UNSUPRESS

Y aplicaremos el route-map al neighbor
neighbor 10.0.0.2 unsuppress-map UNSUPRESS

Ahora vemos que rutas recibe R2 con la ruta 192.168.2.0/24
R2#sh ip bgp

   Network          Next Hop            Metric LocPrf Weight Path

*> 192.168.0.0/22   10.0.0.1                 0             0 100 i

*> 192.168.2.0      10.0.0.1                 0             0 100 i

BGP Filtrando por AS regular expressions

Tenemos un router al que le llegan rutas de distintos sistemas autónomos y con distintos recorridos

R2#sh ip bgp

   Network          Next Hop            Metric LocPrf Weight Path
*> 192.168.0.0      10.0.0.1                 0             0 100 1 2 3 4 5 i
*> 192.168.1.0      10.0.0.1                 0             0 100 10 20 30 40 50 i
*> 192.168.2.0      10.0.0.1                 0             0 100 22 33 44 55 66 i
*> 192.168.3.0      10.0.0.1                 0             0 100 17 77 71 i

Podemos filtrar que rutas recibir o reenviar utilizando las expresiones regulares y los route-maps, en el siguiente gráfico se puede ver como utilizar los caracteres especiales


haremos un ejemplo creamos un as-path acl y la aplicamos a un rotue map
ip as-path access-list 1 permit _71_
!
route-map MYMAP permit 10
 match as-path 1

El route-map lo aplicamos a los anuncios recividos del vecino y ya tenemos un filtro que solo permite tráfico que haya transitado el AS 71
router bgp 200
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.1 remote-as 100
 neighbor 10.0.0.1 route-map MYMAP in
 no auto-summary

R2#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*> 192.168.3.0      10.0.0.1                 0             0 100 17 77 71 i

BGP Sumarizando rutas

Utilizaremos el siguiente esquema

La configuración de R1 será la siguiente
R1#sh run | s bgp
   router bgp 100
   no synchronization
   bgp log-neighbor-changes
   network 192.168.0.0
   network 192.168.1.0
   network 192.168.2.0
   network 192.168.3.0
   neighbor 10.0.0.2 remote-as 200
   no auto-summary
Anunciamos todas las rutas por BGP al vecino, y vemos como las recibe R2
R2#sh ip bgp
BGP table version is 5, local router ID is 10.0.0.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

*> 192.168.0.0      10.0.0.1                 0             0 100 i
*> 192.168.1.0      10.0.0.1                 0             0 100 i
*> 192.168.2.0      10.0.0.1                 0             0 100 i
*> 192.168.3.0      10.0.0.1                 0             0 100 i
Ahora en R1 vamos a tratar de sumarizar las rutas en una red 192.168.0.0/22 para ello dentro de router bgp 100 haremos lo siguiente
R1(config-router)#aggregate-address 192.168.0.0 255.255.252.0
Volvemos a R2 a ver como ve la ruta sumarizada
R2#sh ip bgp
BGP table version is 6, local router ID is 10.0.0.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

*> 192.168.0.0      10.0.0.1                 0             0 100 i
*> 192.168.0.0/22   10.0.0.1                 0             0 100 i
*> 192.168.1.0      10.0.0.1                 0             0 100 i
*> 192.168.2.0      10.0.0.1                 0             0 100 i
*> 192.168.3.0      10.0.0.1                 0             0 100 i
No hemos ganado nada puesto que en la tabla de rutas se inserta la ruta con máscara más grande y la 24 es más grande que la 22, luego tenemos que eliminar las rutas /24 redundadas, para ello modificaremos la manera de sumarizar en R1 así

R1(config-router)#aggregate-address 192.168.0.0 255.255.252.0 summary-only
Y volvemos a comprobar que queda en R2

R2#sh ip bgp
BGP table version is 10, local router ID is 10.0.0.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
*> 192.168.0.0/22   10.0.0.1                 0             0 100 i

BGP Filtrando rutas con prefix-list

Veamos el siguiente ejemplo


La configuración de R1 quedaría así
R1#sh run | s bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 network 192.168.0.0
 network 192.168.1.0
 network 192.168.2.0
 network 192.168.3.0
 neighbor 10.0.0.2 remote-as 200
 no auto-summary

La configuración de R2 quedaría así
R2#sh run | s bgp
router bgp 200
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.1 remote-as 100
 neighbor 10.0.0.6 remote-as 300
 no auto-summary 

La configuración de R3 quedaría así
R3#sh run | s bgp
router bgp 300
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.5 remote-as 200
 no auto-summary

Las rutas en R2 y R3 serian iguales puesto que no hay ningún prefix-list aplicado
   Network          Next Hop            Metric LocPrf Weight Path

*> 192.168.0.0      10.0.0.5                               0 200 100 i

*> 192.168.1.0      10.0.0.5                               0 200 100 i

*> 192.168.2.0      10.0.0.5                               0 200 100 i

*> 192.168.3.0      10.0.0.5                               0 200 100 i

Para crear un prefix list en R2 haremos los siguiente
R2(config)#ip prefix-list MYLIST seq 5 permit 192.168.1.0/24

Donde MYLIST es una etiqueta seq es el número de secuencia y luego va la red con la máscara, donde podemos especificar después de la máscara ge /mascara o le/mascara para incluir igual o mas grande o igual y menor.


Para aplicar la prefix-list sin utilizar router-map haremos lo siguiente en R2 en sentido del anuncio a R3
R2(config-router)#neighbor 10.0.0.6 prefix-list MYLIST out

Con lo que R3 qeudará solamente con la ruta que se permita
R3#sh ip bgp
BGP table version is 8, local router ID is 10.0.0.6
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.1.0      10.0.0.5                               0 200 100 i