34. Configuring BGP Local Preference

1、理解掌握 BGP 的本地优选属性概念和配置方法。

2、本地优选的属性默认值为 100,较高值的路径会被优先选择。

3、本地优先属性,决定离开本自治系统最佳的路径。

 

网络图: 

image.png

配置好各路由器的IP地址等基本信息,测试互连可达。

配置好基本的BGP协议,BGP收敛时间较长,等待一小段时间后继续。

 

查看R3路由表

R3#show ip route

Gateway of last resort is not set

     172.16.0.0/24 is subnetted, 1 subnets

B       172.16.1.0 [20/0] via 192.168.1.1, 00:10:05

     10.0.0.0/24 is subnetted, 1 subnets

C       10.1.1.0 is directly connected, Serial0/1

     130.130.0.0/24 is subnetted, 1 subnets

B       130.130.1.0 [20/0] via 192.168.1.1, 00:10:05  ---->记录下一跳

C    192.168.1.0/24 is directly connected, Serial0/0

B    192.168.2.0/24 [200/0] via 10.1.1.2, 00:07:11

 

查看R4路由表

R4#show ip route

Gateway of last resort is not set

     172.16.0.0/24 is subnetted, 1 subnets

B       172.16.1.0 [20/0] via 192.168.2.2, 00:11:50

     10.0.0.0/24 is subnetted, 1 subnets

C       10.1.1.0 is directly connected, Serial0/1

     130.130.0.0/24 is subnetted, 1 subnets

B       130.130.1.0 [20/0] via 192.168.2.2, 00:11:50    ---->记录下一跳

B    192.168.1.0/24 [200/0] via 10.1.1.1, 00:11:50

C    192.168.2.0/24 is directly connected, Serial0/0

 

理论上BGP选择的都是最佳路由,但是假如R4和R1之间的链路是快速以太网链路,速度是100Mpbs,而R3目前选择到达130.130.1.0/24的网络下一跳是192.168.1.1,其需要通过两条广域网的串口链路,假设串口链路的速度是2Mpbs的DDN专线,则R3选择的是次佳路由。

其主要原因是:BGP在选择最佳路由时,并不会考虑链路的具体带宽。为了解决这一问题,可以在本地配置本地优先来确定数据流如何流出本自治系统

 

查看R3的BGP数据库信息表:

R3#show ip bgp

BGP table version is 7, local router ID is 192.168.1.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

* i10.1.1.0/24      10.1.1.2                 0    100      0 i

*>                  0.0.0.0                  0         32768 i

* i130.130.1.0/24   192.168.2.2              0    100      0 64512 i ---->100为默认本地优先属性值

*>                  192.168.1.1                            0 64512 i

* i172.16.1.0/24    192.168.2.2              0    100      0 64512 i

*>                  192.168.1.1              0             0 64512 i

*  192.168.1.0      192.168.1.1              0             0 64512 i

*>                  0.0.0.0                  0         32768 i

*>i192.168.2.0      10.1.1.2                 0    100      0 i

*                   192.168.1.1                            0 64512 i

 

查看R4的BGP数据库信息表:

R4#show ip bgp

BGP table version is 8, local router ID is 192.168.2.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

* i10.1.1.0/24      10.1.1.1                 0    100      0 i

*>                  0.0.0.0                  0         32768 i

* i130.130.1.0/24   192.168.1.1              0    100      0 64512 i

*>                  192.168.2.2              0             0 64512 i

* i172.16.1.0/24    192.168.1.1              0    100      0 64512 i

*>                  192.168.2.2              0             0 64512 i

*>i192.168.1.0      10.1.1.1                 0    100      0 i

*                   192.168.2.2                            0 64512 i

*> 192.168.2.0      0.0.0.0                  0         32768 i

*                   192.168.2.2              0             0 64512 i

 

通过以上的对比只需要修改R4路由器所学习到的所有路由的本地优先值属性。

因为BGP会优先选择本地优先属性较高的路由。

 

配置R4路由器,调整本地优先值属性为200:

R4(config)#router bgp 64513

R4(config-router)#bgp default local-preference 200  --->调整为200

R4(config-router)#end

 

等待一段时间,再观察,即使使用clear ip bgp * 命令也不会立即看到最后结果,如果改完后立即观察的话会看到一些奇怪的结果,期间路由没有马上改变。

 

查看R3的BGP数据库:

R3#show ip bgp      

BGP table version is 8, local router ID is 192.168.1.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

*> 10.1.1.0/24      0.0.0.0                  0         32768 i

* i                 10.1.1.2                 0    200      0 i

*  130.130.1.0/24   192.168.1.1                            0 64512 i

*>i                 192.168.2.2              0    200      0 64512 i  --->192.168.2.2已经是下一跳

*  172.16.1.0/24    192.168.1.1              0             0 64512 i

*>i                 192.168.2.2              0    200      0 64512 i

*  192.168.1.0      192.168.1.1              0             0 64512 i

*>                  0.0.0.0                  0         32768 i

* i                 192.168.2.2              0    200      0 64512 i

*  192.168.2.0      192.168.1.1                            0 64512 i

*>i                 10.1.1.2                 0    200      0 i

 

查看R3路由表

R3#show ip route    

Gateway of last resort is not set

     172.16.0.0/24 is subnetted, 1 subnets

B       172.16.1.0 [200/0] via 192.168.2.2, 00:01:40

     10.0.0.0/24 is subnetted, 1 subnets

C       10.1.1.0 is directly connected, Serial0/1

     130.130.0.0/24 is subnetted, 1 subnets

B       130.130.1.0 [200/0] via 192.168.2.2, 00:01:40  ---->下一跳和上面的对比已经改变

C    192.168.1.0/24 is directly connected, Serial0/0

B    192.168.2.0/24 [200/0] via 10.1.1.2, 00:01:45

 

在R3上的130.130.1.0/24的下一跳是192.168.2.2,是因为BGP在向IBGP对等体通告路由时,其下一跳不变,这种机制被称为BGP的下一跳属性。

为了能够在R3上真实反映路由变化,可以在R4上配置通告给R3的路由,其下一跳是R4自己。

 

R4上的配置如下

R4(config)#router bgp 64513

R4(config-router)#neighbor 10.1.1.1 next-hop-self

R4(config-router)#exit

 

查看R3路由表确认配置生效

R3#show ip route

Gateway of last resort is not set

     172.16.0.0/24 is subnetted, 1 subnets

B       172.16.1.0 [200/0] via 10.1.1.2, 00:00:59

     10.0.0.0/24 is subnetted, 1 subnets

C       10.1.1.0 is directly connected, Serial0/1

     130.130.0.0/24 is subnetted, 1 subnets

B       130.130.1.0 [200/0] via 10.1.1.2, 00:00:59

C    192.168.1.0/24 is directly connected, Serial0/0

B    192.168.2.0/24 [200/0] via 10.1.1.2, 00:10:16

 

下一跳全部变成了10.1.1.2,即去往R4,即使是对于R3只有一线之隔的172.16.1.0/24网络也从R4经过,但是它是设备的互连地址,在调整链路中它们的流量几乎可以忽略不计。

 

在R3上跟踪查看路径:

R3#traceroute 130.130.1.1

Type escape sequence to abort.

Tracing the route to 130.130.1.1

  1 10.1.1.2 36 msec 60 msec 28 msec

  2 192.168.2.2 76 msec *  44 msec

 

按设定的路径通过,一切正常。


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

桂ICP备19000498号-3