Saturday, 1 February 2020

BGP Next hop self


R6#sh ip bgp
BGP table version is 4, local router ID is 150.6.6.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
*> 6.1.0.0/16       0.0.0.0                  0         32768 i
*> 6.2.0.0/16       0.0.0.0                  0         32768 i
*> 6.3.0.0/16       0.0.0.0                  0         32768 i

 R6 will send the update to its eBGP peer R1 lets check on R1.

R1#sh ip bgp
BGP table version is 4, local router ID is 150.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
*> 6.1.0.0/16       155.1.16.6               0             0 600 i
*> 6.2.0.0/16       155.1.16.6               0             0 600 i
*> 6.3.0.0/16       155.1.16.6               0             0 600 i

Here we got all the update form R6 note it says best path and valid route.
Then R1 is fully meshed with R2 ad R3 these updates will be updated to R2 and R3.
R2#sh ip bgp
BGP table version is 1, local router ID is 150.2.2.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
* i6.1.0.0/16       155.1.16.6               0    100      0 600 i
* i6.2.0.0/16       155.1.16.6               0    100      0 600 i
* i6.3.0.0/16       155.1.16.6               0    100      0 600 i

R3#sh ip bgp
BGP table version is 1, local router ID is 150.3.3.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
* i6.1.0.0/16       155.1.16.6               0    100      0 600 i
* i6.2.0.0/16       155.1.16.6               0    100      0 600 i
* i6.3.0.0/16       155.1.16.6               0    100      0 600 i

Note we are getting the update but its not marked as best route. But why ?? Huh the next hop.

What we read in iBGP peer?? BGP rule says the next hop value can only be changed by eBGP by default iBGP peer wont modify the next hop address.

We can solve this using 3 method.

Method 1:  Advertise the transit link  into the ospf.

R6(config)#router ospf 1
R6(config-router)#network 155.1.16.0 0.0.0.255 area 1

R1(config)#router ospf 1
R1(config-router)#network 155.1.16.0 0.0.0.255 area 1

Now lets check on R2 and R3 is the received routes are marked as best route.
R2#sh ip bgp
BGP table version is 4, local router ID is 150.2.2.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
*>i6.1.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.2.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.3.0.0/16       155.1.16.6               0    100      0 600 i

R3#sh ip bgp
BGP table version is 4, local router ID is 150.3.3.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
*>i6.1.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.2.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.3.0.0/16       155.1.16.6               0    100      0 600 i

R2#sh ip route 6.1.0.1
Routing entry for 6.1.0.0/16
  Known via "bgp 100", distance 200, metric 0
  Tag 600, type internal
  Last update from 155.1.16.6 00:03:54 ago
  Routing Descriptor Blocks:
  * 155.1.16.6, from 150.1.1.1, 00:03:54 ago
      Route metric is 0, traffic share count is 1
      AS Hops 1
      Route tag 600
Its learned via BGP next hop is 155.1.16.6

R2#sh ip route 155.1.16.6
Routing entry for 155.1.16.0/24
  Known via "ospf 1", distance 110, metric 65, type inter area
  Last update from 155.1.123.1 on FastEthernet1/0, 00:04:08 ago
  Routing Descriptor Blocks:
  * 155.1.123.1, from 150.1.1.1, 00:04:08 ago, via FastEthernet1/0
      Route metric is 65, traffic share count is 1

Its learned via OSPF next hop is 155.1.123.1

R2#sh ip route 155.1.123.1
Routing entry for 155.1.123.0/24
  Known via "connected", distance 0, metric 0 (connected, via interface)
  Routing Descriptor Blocks:
  * directly connected, via FastEthernet1/0
      Route metric is 0, traffic share count is 1

R2#sh ip cef 6.1.0.1
6.1.0.0/16, version 26, epoch 0, cached adjacency 155.1.123.1
0 packets, 0 bytes
  via 155.1.16.6, 0 dependencies, recursive
    next hop 155.1.123.1, FastEthernet1/0 via 155.1.16.0/24
    valid cached adjacency



Method 2: Now lets have a look on R5 advertised network.

R5#sh ip bgp  | in 0.0.0.0
*> 5.1.0.0/24       0.0.0.0                  0         32768 i
*> 5.2.0.0/24       0.0.0.0                  0         32768 i
*> 5.3.0.0/24       0.0.0.0                  0         32768 i

R3#sh ip bgp neighbors 150.2.2.2 advertised-routes
BGP table version is 7, local router ID is 150.3.3.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
*> 5.1.0.0/24       155.1.35.5               0             0 500 i
*> 5.2.0.0/24       155.1.35.5               0             0 500 i
*> 5.3.0.0/24       155.1.35.5               0             0 500 i

R2#sh ip bgp
BGP table version is 4, local router ID is 150.2.2.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
* i5.1.0.0/24       155.1.35.5               0    100      0 500 i
* i5.2.0.0/24       155.1.35.5               0    100      0 500 i
* i5.3.0.0/24       155.1.35.5               0    100      0 500 i
*>i6.1.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.2.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.3.0.0/16       155.1.16.6               0    100      0 600 I

Note the route advertised via R3 is not chosen as the best path because the nest hop is not reachable.
Lets modify  the next hop self.

R3#sh run | sec router bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 neighbor iBGP_Peer peer-group
 neighbor iBGP_Peer remote-as 100
 neighbor iBGP_Peer update-source Loopback0
 neighbor iBGP_Peer next-hop-self ==> [Since R1 and R2 having peer with R3 using update source lo 0 the next will be changed to the lo 0 address]
 neighbor 150.1.1.1 peer-group iBGP_Peer
 neighbor 150.2.2.2 peer-group iBGP_Peer
 neighbor 155.1.34.4 remote-as 400
 neighbor 155.1.35.5 remote-as 500
 no auto-summary

R2#sh ip bgp
BGP table version is 7, local router ID is 150.2.2.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
*>i5.1.0.0/24       150.3.3.3                0    100      0 500 i
*>i5.2.0.0/24       150.3.3.3                0    100      0 500 i
*>i5.3.0.0/24       150.3.3.3                0    100      0 500 i
*>i6.1.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.2.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.3.0.0/16       155.1.16.6               0    100      0 600 I

R1#sh ip bgp
BGP table version is 10, local router ID is 150.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
*>i5.1.0.0/24       150.3.3.3                0    100      0 500 i
*>i5.2.0.0/24       150.3.3.3                0    100      0 500 i
*>i5.3.0.0/24       150.3.3.3                0    100      0 500 i
*> 6.1.0.0/16       155.1.16.6               0             0 600 i
*> 6.2.0.0/16       155.1.16.6               0             0 600 i
*> 6.3.0.0/16       155.1.16.6               0             0 600 I


R1#sh ip cef 5.1.0.1
5.1.0.0/24, version 38, epoch 0, cached adjacency 155.1.123.3
0 packets, 0 bytes
  via 150.3.3.3, 0 dependencies, recursive
    next hop 155.1.123.3, FastEthernet2/0 via 150.3.3.3/32
    valid cached adjacency

Method 3: Now lets have a look on R4 advertised network.
R4#sh ip bgp | in 0.0.0.0

*> 4.1.0.0/24       0.0.0.0                  0         32768 i
*> 4.2.0.0/24       0.0.0.0                  0         32768 i
*> 4.3.0.0/24       0.0.0.0                  0         32768 i


R3#sh ip bgp
BGP table version is 10, local router ID is 150.3.3.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
*> 4.1.0.0/24       155.1.34.4               0             0 400 i
*> 4.2.0.0/24       155.1.34.4               0             0 400 i
*> 4.3.0.0/24       155.1.34.4               0             0 400 i
*> 5.1.0.0/24       155.1.35.5               0             0 500 i
*> 5.2.0.0/24       155.1.35.5               0             0 500 i
*> 5.3.0.0/24       155.1.35.5               0             0 500 i
*>i6.1.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.2.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.3.0.0/16       155.1.16.6               0    100      0 600 i


R2#sh ip bgp
BGP table version is 10, local router ID is 150.2.2.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
*>i4.1.0.0/24       150.3.3.3                0    100      0 400 i
*>i4.2.0.0/24       150.3.3.3                0    100      0 400 i
*>i4.3.0.0/24       150.3.3.3                0    100      0 400 i
*>i5.1.0.0/24       150.3.3.3                0    100      0 500 i
*>i5.2.0.0/24       150.3.3.3                0    100      0 500 i
*>i5.3.0.0/24       150.3.3.3                0    100      0 500 i
*>i6.1.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.2.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.3.0.0/16       155.1.16.6               0    100      0 600 i

Since we have used the 2nd method i.e next-hop-self command
We can change the next hop manually.

R3#sh route-map
route-map nexthop, permit, sequence 10
  Match clauses:
  Set clauses:
    ip next-hop 155.1.123.3
  Policy routing matches: 0 packets, 0 bytes

R3#sh run | s router bgp
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 neighbor iBGP_Peer peer-group
 neighbor iBGP_Peer remote-as 100
 neighbor iBGP_Peer update-source Loopback0
 neighbor iBGP_Peer next-hop-self
 neighbor iBGP_Peer route-map nexthop out
 neighbor 150.1.1.1 peer-group iBGP_Peer
 neighbor 150.2.2.2 peer-group iBGP_Peer
 neighbor 155.1.34.4 remote-as 400
 neighbor 155.1.35.5 remote-as 500
 no auto-summary

R2#sh ip bgp
BGP table version is 16, local router ID is 150.2.2.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
*>i4.1.0.0/24       155.1.123.3              0    100      0 400 i
*>i4.2.0.0/24       155.1.123.3              0    100      0 400 i
*>i4.3.0.0/24       155.1.123.3              0    100      0 400 i
*>i5.1.0.0/24       155.1.123.3              0    100      0 500 i
*>i5.2.0.0/24       155.1.123.3              0    100      0 500 i
*>i5.3.0.0/24       155.1.123.3              0    100      0 500 i
*>i6.1.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.2.0.0/16       155.1.16.6               0    100      0 600 i
*>i6.3.0.0/16       155.1.16.6               0    100      0 600 I


R1#sh ip bgp
BGP table version is 19, local router ID is 150.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
*>i4.1.0.0/24       155.1.123.3              0    100      0 400 i
*>i4.2.0.0/24       155.1.123.3              0    100      0 400 i
*>i4.3.0.0/24       155.1.123.3              0    100      0 400 i
*>i5.1.0.0/24       155.1.123.3              0    100      0 500 i
*>i5.2.0.0/24       155.1.123.3              0    100      0 500 i
*>i5.3.0.0/24       155.1.123.3              0    100      0 500 i
*> 6.1.0.0/16       155.1.16.6               0             0 600 i
*> 6.2.0.0/16       155.1.16.6               0             0 600 i
*> 6.3.0.0/16       155.1.16.6               0             0 600 i

BGP Advertisement


Now On R6 and R5 we are going to advertise some prefix.

R6#sh run | sec router bgp
router bgp 600
 no synchronization
 bgp log-neighbor-changes
 network 6.1.0.0 mask 255.255.0.0
 network 6.2.0.0 mask 255.255.0.0
 network 6.3.0.0 mask 255.255.0.0
 neighbor 155.1.16.1 remote-as 100
 no auto-summary

R5#sh run | s router bgp
router bgp 500
 no synchronization
 bgp log-neighbor-changes
 network 5.1.0.0 mask 255.255.255.0
 network 5.2.0.0 mask 255.255.255.0
 network 5.3.0.0 mask 255.255.255.0
 neighbor 150.4.4.4 remote-as 400
 neighbor 150.4.4.4 ttl-security hops 2
 neighbor 150.4.4.4 update-source Loopback0
 neighbor 155.1.35.3 remote-as 100
 no auto-summary

R4#sh run | s router bgp
router bgp 400
 no synchronization
 bgp log-neighbor-changes
 network 4.1.0.0 mask 255.255.255.0
 network 4.2.0.0 mask 255.255.255.0
 network 4.3.0.0 mask 255.255.255.0
 neighbor 150.5.5.5 remote-as 500
 neighbor 150.5.5.5 ttl-security hops 2
 neighbor 150.5.5.5 update-source Loopback0
 neighbor 155.1.34.3 remote-as 100
 no auto-summary

BGP peer group


We can minimize the neighbor command and memory process by using the peer group. With the help of peer group we can reduce the shortest path finding process also.

Now let have a iBGP peer between R1 - R2,  R1 - R3 and R2 - R3. Full mesh

R1(Config)#router bgp 100
R1(config-router)#neighbor iBGP_Peer peer-group
R1(config-router)#neighbor iBGP_Peer remote-as 100
R1(config-router)#neighbor iBGP_Peer update-source loopback 0
R1(config-router)#neighbor 150.2.2.2 peer-group iBGP_Peer
R1(config-router)#neighbor 150.3.3.3 peer-group iBGP_Peer

R2(Config)#router bgp 100
R2(config-router)#neighbor iBGP_Peer peer-group
R2(config-router)#neighbor iBGP_Peer remote-as 100
R2(config-router)#neighbor iBGP_Peer update-source loopback 0
R2(config-router)#neighbor 150.1.1.1 peer-group iBGP_Peer
R2(config-router)#neighbor 150.3.3.3 peer-group iBGP_Peer

R3(Config)#router bgp 100
R3(config-router)#neighbor iBGP_Peer peer-group
R3(config-router)#neighbor iBGP_Peer remote-as 100
R3(config-router)#neighbor iBGP_Peer update-source loopback 0
R3(config-router)#neighbor 150.2.2.2 peer-group iBGP_Peer
R3(config-router)#neighbor 150.1.1.1 peer-group iBGP_Peer

R1#sh bgp su
BGP router identifier 150.1.1.1, local AS number 100
BGP table version is 1, main routing table version 1

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
150.2.2.2       4   100       5       5        1    0    0 00:01:23        0
150.3.3.3       4   100       5       5        1    0    0 00:01:08        0
155.1.16.6      4   600      16      16        1    0    0 00:13:30        0

We formed iBGP neighborship :)

BGP peer with indirect link


Lets form as eBGP peer with R5 and R4 with indirect link (Loopback).

R4#sh run | sec router bgp
router bgp 400
 no synchronization
 bgp log-neighbor-changes
 neighbor 150.5.5.5 remote-as 500
 neighbor 150.5.5.5 ebgp-multihop 2
 neighbor 150.5.5.5 update-source Loopback0
 no auto-summary

R5#sh run |  sec router bgp
router bgp 500
 no synchronization
 bgp log-neighbor-changes
 neighbor 150.4.4.4 remote-as 400
 neighbor 150.4.4.4 ebgp-multihop 2
 neighbor 150.4.4.4 update-source Loopback0
 no auto-summary

Here we should use the update source and as well as ebgp multihop command.
Because By default bgp peer try to establish the bgp peer with  the source address that’s is directly connected and with a TTL value 1.
To have indirect ebgp peer we should tell the router for its update source and increase the TTL value.

R5#sh ip bgp ne | in Exter
  External BGP neighbor may be up to 2 hops away.

In this there as an attack on TCP called TCP Reset . so we have a mechanism of protecting with unwanted ebg peer establishment.

Lets configure the ttl security feature between R4 and R5.

R5(config-router)#neighbor 150.4.4.4 ttl-security hops 2
Remove ebgp-multihop before configuring ttl-security

Note: We can have ttl security or ebg-multi hop one command at a time not both together. So lets remove the ebg multihop command.

R5(config-router)# neighbor 150.4.4.4 ttl-security hops 2

R4(config-router)# neighbor 150.5.5.5 ttl-security hops 2

R5#sh ip bgp ne | in Ext|Min
  External BGP neighbor may be up to 2 hops away.
Connection is ECN Disabled, Mininum incoming TTL 253, Outgoing TTL 255

Like this form ebgp peer with R6 - R1, R3 - R5, R3 - R4 and R4 - R5.

BGP configuration



We already configured the IP address and IGP(OSPF) is enabled.
Lets form as eBGP peer with R5 and R4 with a direct link.

R4(config)#router bgp 500
R4(config-router)#neighbor 155.1.45.5 remote-as 500

R5(config)#router bgp 500
R5(config-router)#neighbor 155.1.45.4 remote-as 400

Here the R4 using process
R4#sh processes cpu | in BGP
 193          28      3596          7  0.00%  0.00%  0.00%   0 BGP Router
 194           0         1          0  0.00%  0.00%  0.00%   0 BGP I/O
 195         640       120       5333  0.00%  0.04%  0.00%   0 BGP Scanner
 196         244       115       2121  0.00%  0.00%  0.00%   0 BGP Open

R4#sh processes mem | in BGP
 193   0      24144          0      10200          2          2 BGP Router
 194   0          0          0       6972          0          0 BGP I/O
 195   0          0          0       9972          8          8 BGP Scanner
 196   0      69832      69832       6972         58         58 BGP Open

R4#sh tcp brief all
TCB       Local Address           Foreign Address        (state)
65B32764  155.1.45.4.42521        155.1.45.5.179         ESTAB


R5#sh bgp sum
BGP router identifier 150.5.5.5, local AS number 500
BGP table version is 1, main routing table version 1

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
155.1.45.4      4   400       5       5        1    0    0 00:01:54        0