Sunday, October 28, 2012

BGP Next-Hop-Self & Changing Local Pref with default command



Below is the configuration for the topology above. IBGP and EBGP peers are setup using the loopback addresses. R4 and R3 advertise network 172.12.34.0.

R1#config t
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#int fa0/0
R1(config-if)#ip add 10.1.1.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#
*Mar  1 00:01:30.575: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar  1 00:01:31.575: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1(config-if)#int lo0
R1(config-if)#ip add 1.1.1.1 255.255.255.255
R1(config-if)#router bgp 12
R1(config-router)#neighbor 2.2.2.2 remote-as 12
R1(config-router)#neighbor 2.2.2.2 update-source loopback 0
R1(config-router)#neighbor 3.3.3.3 remote-as 34
R1(config-router)#neighbor 3.3.3.3 update-source loopback 0
R1(config-router)#neighbor 3.3.3.3 ebgp-multihop 2
R1(config-router)#exit
R1(config)#ip route 2.2.2.2 255.255.255.255 10.1.1.2
R1(config)#ip route 3.3.3.3 255.255.255.255 10.1.1.3
R1(config)#^Z
R1#wr


R2#config t
Enter configuration commands, one per line.  End with CNTL/Z.
R2(config)#int lo0
R2(config-if)#ip add 2.2.2.2 255.255.255.255
R2(config-if)#int fa0/0
R2(config-if)#ip add 10.1.1.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#
*Mar  1 00:04:53.971: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar  1 00:04:54.971: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R2(config-if)#router bgp 12
R2(config-router)#neighbor 1.1.1.1 remote-as 12
R2(config-router)#neighbor 1.1.1.1 update-source loopback 0
R2(config-router)#neighbor 4.4.4.4 remote-as 34
R2(config-router)#neighbor 4.4.4.4 update-source loopback 0
R2(config-router)#neighbor 4.4.4.4 ebgp-multihop 2
R2(config-router)#exit
R2(config)#ip route 1.1.1.1 255.255.255.255 10.1.1.1
*Mar  1 00:06:15.935: %BGP-5-ADJCHANGE: neighbor 1.1.1.1 Up
R2(config)#ip route 4.4.4.4 255.255.255.255 10.1.1.4


R3#config t
Enter configuration commands, one per line.  End with CNTL/Z.
R3(config)#int lo0
R3(config-if)#ip add 3.3.3.3 255.255.255.255
R3(config-if)#int fa 0/0
R3(config-if)#ip add 10.1.1.3 255.255.255.0
R3(config-if)#no shut
R3(config-if)#
*Mar  1 00:09:07.383: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar  1 00:09:08.383: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R3(config-if)#router bgp 34
R3(config-router)#neighbor 1.1.1.1 remote-as 12
R3(config-router)#neighbor 1.1.1.1 update-source loopback 0
R3(config-router)#neighbor 1.1.1.1 ebgp-multihop 2
R3(config-router)#neighbor 4.4.4.4 remote-as 34
R3(config-router)#neighbor 4.4.4.4 update-source loopback 0
R3(config-router)#network 172.12.34.0 mask 255.255.255.0
R3(config-router)#exit
R3(config)#int s0/0
R3(config-if)#ip add
R3(config-if)#ip address 172.12.34.3 255.255.255.0
R3(config-if)#no shut
R3(config-if)#exit
R3(config)#
*Mar  1 00:10:56.303: %LINK-3-UPDOWN: Interface Serial0/0, changed state to up
*Mar  1 00:10:57.303: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
R3(config)#
R3(config)#ip route 1.1.1.1 255.255.255.255 10.1.1.1
R3(config)#ip route 4.4.4.4 255.255.25
*Mar  1 00:11:14.607: %BGP-5-ADJCHANGE: neighbor 1.1.1.1 Up
R3(config)#ip route 4.4.4.4 255.255.255.255 10.1.1.4

R3(config)#^Z
R3#wr


R4#config t
Enter configuration commands, one per line.  End with CNTL/Z.
R4(config)#int lo0
R4(config-if)#ip add 4.4.4.4 255.255.255.255
R4(config-if)#int fa0/0
R4(config-if)#ip add 10.1.1.4 255.255.255.0
R4(config-if)# no shut
R4(config-if)#int s0/0
R4(config-if)#ip add 172.12.34.4 255.255.255.0
R4(config-if)#no shut
R4(config-if)#
*Mar  1 00:12:36.843: %LINK-3-UPDOWN: Interface Serial0/0, changed state to up
*Mar  1 00:12:37.843: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
R4(config-if)#
R4(config-if)#router bgp 34
R4(config-router)#neighbor 2.2.2.2 remote-as 12
R4(config-router)#neighbor 2.2.2.2 update-source loopback 0
R4(config-router)#neighbor 2.2.2.2 ebgp-multihop 2
R4(config-router)#neighbor 3.3.3.3 remote 34
R4(config-router)#neighbor 3.3.3.3 update-source loopback 0
R4(config-router)#network 172.12.34.0 mask 255.255.255.0
R4(config-router)#^Z
R4#config t
*Mar  1 00:13:48.447: %SYS-5-CONFIG_I: Configured from console by console
R4#config t
Enter configuration commands, one per line.  End with CNTL/Z.
R4(config)#ip route 2.2.2.2 255.255.255.255 10.1.1.2
R4(config)#ip route 3.3.3.3 255.255.255.255 10.1.1.3
R4(config)#
*Mar  1 00:15:41.507: %BGP-5-ADJCHANGE: neighbor 3.3.3.3 Up
*Mar  1 00:15:41.671: %BGP-5-ADJCHANGE: neighbor 2.2.2.2 Up


We can see that R3 is the next hop for network 172.12.34.0 and this is vaild because all attributes are the same, weight, as-path,local prf  and med except for the next in the list which is ebgp over ibgp. Let's say we want the route to go through R2 instead because it is the faster link, we can change the local prf so that BGP chooses that route. 



R1#show ip bgp
BGP table version is 2, local router ID is 1.1.1.1
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
* i172.12.34.0/24   4.4.4.4                  0    100      0 34 i
*>                  3.3.3.3                  0             0 34 i

R1#show ip bgp 172.12.34.0
BGP routing table entry for 172.12.34.0/24, version 2
Paths: (2 available, best #2, table Default-IP-Routing-Table)
  Advertised to non peer-group peers:
  2.2.2.2
  34
    4.4.4.4 (inaccessible) from 2.2.2.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, internal
  34
    3.3.3.3 from 3.3.3.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external, best

The local prf needs to be changed on the router advising the route we want to use. First we have to make the route to R3 accessible, currently it's not because an ebgp route advised into a ibgp retains the hop from the route it was learned from which is R4. The next-hop-self command allows R2 to make itself the next hop address for ebgp routes.


R2(config)#router bgp 12
R2(config-router)#neighbor 1.1.1.1 next-hop-self

Now that both routes are accessible , I will change the local prf  of 2.2.2.2 learned route. 

R1#show ip bgp 172.12.34.0
BGP routing table entry for 172.12.34.0/24, version 2
Paths: (2 available, best #2, table Default-IP-Routing-Table)
  Advertised to non peer-group peers:
  2.2.2.2
  34
    2.2.2.2 from 2.2.2.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, internal
  34
    3.3.3.3 from 3.3.3.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external, best

Local prf is viable within an AS not only between two routers, we can change the default or use a route map to change the local prf, first we will do the default command. The higher the local prf the more preferred unlike the MED which is the lowest value.

R2(config)#router bgp 12
R2(config-router)#bgp default local-preference 200


R1#show ip bgp 172.12.34.0
BGP routing table entry for 172.12.34.0/24, version 3
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Flag: 0x800
  Advertised to update-groups:
        2
  34
    2.2.2.2 from 2.2.2.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 200, valid, internal, best
  34
    3.3.3.3 from 3.3.3.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external


R2 is now the valid and best route for the network 172.12.34.0

No comments:

Post a Comment