BGP 优选短的AS号路径实践总结

BGP优选AS号短的路径作为首选路由的验证结果

1、结论:

(1)EBGP会优选AS号少的路径作为转发路径,当优选路径失效时,再选择次选路由。

(2)EBGP邻居建立在直连设备之间。

(3)IBGP邻居可以跨设备建立,此时需要指定好tcp的源ip和目的ip. 源ip就是connect-interface 的ip, 目的ip就是peer ip。

(4)由于OSPF的路由优先级比EBGP高,所以,为了验证BGP AS号短路径的效果,不能将BGP的路径引入到OSPF中。

         另外,城域网内部OSPF可以保证各个PE设备之间互通,所以,也不需要把OSPF路由引入到BGP中进行发布。

2、组网图:

3、验证结果

(1)正常情况下,从PC3 ---> PC1 的路由,走CE2 ---> CE 1 ---> PE 1 ---> PE3  ----> CE3

从PC3上查看路由:

PC>tracert 192.168.0.10

traceroute to 192.168.0.10, 8 hops max
(ICMP), press Ctrl+C to stop
1 172.16.0.1 32 ms 15 ms 16 ms
2 100.0.0.2 47 ms 47 ms 62 ms
3 60.0.0.1 63 ms 78 ms 62 ms
4 40.0.0.2 125 ms 78 ms 94 ms
5 10.0.0.1 94 ms 109 ms 110 ms
6 192.168.0.10 156 ms 125 ms 156 ms

PC>

查看此时CE2上路由信息,可见下一跳是CE之间的IBGP路径。

(2)优选路由故障情况下,走次选路由。从PC3 ---> PC1 的路由,走CE2 ---> PE2 ---> PE 4 ---> R1 ---> PE3  ----> CE3

模式链路故障:PE1 设备上关闭端口GE 0/0/3(ip地址为 40.0.0.1).

从PC3上查看路由:

PC>tracert 192.168.0.10

traceroute to 192.168.0.10, 8 hops max
(ICMP), press Ctrl+C to stop
1 172.16.0.1 16 ms 15 ms 32 ms
2 70.0.0.1 31 ms 47 ms 47 ms
3 50.0.0.1 62 ms 63 ms 78 ms
4 30.0.0.1 109 ms 63 ms 93 ms
5 20.0.0.2 125 ms 94 ms 156 ms
6 10.0.0.1 157 ms 140 ms 157 ms
7 192.168.0.10 156 ms 172 ms 187 ms

PC>

查看此时CE2上路由信息,可见下一跳是PE2之间的EBGP路径。

(3)故障恢复后,路由回切到优选路由。

结果见(1) 

4、曾经出现的问题

(1)PE2和PE3之间,建立EBGP对等体失败。

原因:EBGP邻居只能建立在直连设备间,不能跨设备建立EBGP邻居。

所以,先通过PE4和PE3建立IBGP对等体,然后在通过PE4和PE2建立EBGP对等体,从而将PE3上的路由信息告知PE2。

(2)直连的设备无法建立IBGP邻居。

原因:一般情况下,我们会使用loopback ip作为BGP 的router id. 此时要注意,建立邻居时使用的peer 地址和这个router id没有关系,此时peer ip应当设置成直连设备之间的ip即可。

bgp 65001
router-id 60.0.0.1
peer 40.0.0.2 as-number 65001

(3)非直连的设备之间无法建立IBGP邻居。

问题现象:查看bgp peer的状态,总是停在active状态,无法到达established状态。从BGP邻居的一端 ping 另

问题根源:BGP邻居的建立依赖于TCP可达,非直连的邻居必须配置相同的TCP源ip和目的ip,才能建立。源ip就是connect-interface 的ip, 目的ip就是peer ip。

以PE3、PE4为例,

PE3的配置如下:

bgp 65001
router-id 10.0.0.2
peer 30.0.0.2 as-number 65001
peer 30.0.0.2 connect-interface GigabitEthernet0/0/0     (说明: GigabitEthernet0/0/0 的ip地址= 20.0.0.2

PE4的配置如下:

bgp 65001
router-id 50.0.0.1
peer 20.0.0.2 as-number 65001
peer 20.0.0.2 connect-interface GigabitEthernet0/0/1  (说明: GigabitEthernet0/0/1 的ip地址= 30.0.0.2

(4)OSPF学习的路由优先级比BGP高,导致首选路由总是被OSPF协议优选。

曾经出现的现象,PE2、PE3上将BGP的路由引入到OSPF中,结果导致在PE1上查看 172.16.0.10 的路由下一跳为40.0.0.2, 而按照BGP短的AS号路径的语气,下一跳应当是60.0.0.2. 关闭PE2、PE3上BGP的路径引入BGP后,PE1上目的172.16.0.10的下一跳符合预期。

按照设备手册上的描述:其中,0表示直接连接的路由,255表示任何来自不可信源端的路由;数值越小表明优先级越高。

5、常用命令和调试命令。

(1)怎么看出来有两条BGP路由,优选了AS号短的路径?

关键设备是CE2,或者CE1设备,查看这两个设备的bgp路由,可以看到有两条到达相同目的ip的路由,以CE2为例,

<CE2>dis bgp routing-table 192.168.0.10

BGP local router ID : 70.0.0.2
Local AS number : 65009
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 192.168.0.0/24:
From: 100.0.0.2 (60.0.0.2)
Route Duration: 00h12m53s 
Relay IP Nexthop: 100.0.0.2
Relay IP Out-Interface: Vlanif3
Original nexthop: 60.0.0.1
Qos information : 0x0
AS-path 65001 65005, origin igp, localpref 100, pref-val 0, valid, internal, be
st, select, active, pre 255
Advertised to such 1 peers:
70.0.0.1
BGP routing table entry information of 192.168.0.0/24:
From: 70.0.0.1 (70.0.0.1)
Route Duration: 00h12m26s 
Direct Out-interface: Vlanif2
Original nexthop: 70.0.0.1
Qos information : 0x0
AS-path 65002 65001 65005, origin igp, pref-val 0, valid, external, pre 255, no
t preferred for AS-Path
Not advertised to any peer yet

<CE2>

(2)显示指定类型的协议学习的路由

<PE2>dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 5 Routes : 5

OSPF routing table status : <Active>
Destinations : 5 Routes : 5

Destination/Mask Proto Pre Cost Flags NextHop Interface

10.0.0.0/24 OSPF 10 4 D 50.0.0.1 GigabitEthernet
0/0/0
20.0.0.0/24 OSPF 10 3 D 50.0.0.1 GigabitEthernet
0/0/0
30.0.0.0/24 OSPF 10 2 D 50.0.0.1 GigabitEthernet
0/0/0
40.0.0.0/24 OSPF 10 4 D 50.0.0.1 GigabitEthernet
0/0/0
60.0.0.0/24 OSPF 10 5 D 50.0.0.1 GigabitEthernet
0/0/0

OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0

<PE2>

<PE2>dis ip routing-table protocol bgp
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : BGP
Destinations : 5 Routes : 5

BGP routing table status : <Active>
Destinations : 5 Routes : 5

Destination/Mask Proto Pre Cost Flags NextHop Interface

3.0.0.2/32 EBGP 255 0 D 50.0.0.1 GigabitEthernet
0/0/0
100.0.0.0/24 EBGP 255 0 D 70.0.0.2 GigabitEthernet
0/0/2
172.16.0.0/24 EBGP 255 0 D 70.0.0.2 GigabitEthernet
0/0/2
172.16.1.0/24 EBGP 255 0 D 70.0.0.2 GigabitEthernet
0/0/2
192.168.0.0/24 EBGP 255 0 D 50.0.0.1 GigabitEthernet
0/0/0

BGP routing table status : <Inactive>
Destinations : 0 Routes : 0

<PE2>

(3)显示BGP邻居信息

<PE2>dis bgp peer

BGP local router ID : 70.0.0.1
Local AS number : 65002
Total number of peers : 2 Peers in established state : 2

Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv

50.0.0.1 4 65001 183 315 0 02:26:04 Established
7
70.0.0.2 4 65009 161 187 0 01:21:57 Established
10
<PE2>

(4)显示BGP路由详细信息

<PE2>dis bgp routing-table

(5)显示 路由表,显示指定目的ip的路由信息。

<CE2>dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 17 Routes : 17

Destination/Mask Proto Pre Cost Flags NextHop Interface

3.0.0.2/32 IBGP 255 0 RD 60.0.0.1 Vlanif3
10.0.0.0/24 IBGP 255 0 RD 60.0.0.1 Vlanif3
20.0.0.0/24 IBGP 255 0 RD 60.0.0.1 Vlanif3
30.0.0.0/24 EBGP 255 2 D 70.0.0.1 Vlanif2
40.0.0.0/24 IBGP 255 0 RD 60.0.0.1 Vlanif3
50.0.0.0/24 EBGP 255 0 D 70.0.0.1 Vlanif2
60.0.0.0/24 IBGP 255 0 RD 100.0.0.2 Vlanif3
70.0.0.0/24 Direct 0 0 D 70.0.0.2 Vlanif2
70.0.0.2/32 Direct 0 0 D 127.0.0.1 Vlanif2
100.0.0.0/24 Direct 0 0 D 100.0.0.1 Vlanif3
100.0.0.1/32 Direct 0 0 D 127.0.0.1 Vlanif3
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
172.16.0.0/24 Direct 0 0 D 172.16.0.1 Vlanif1
172.16.0.1/32 Direct 0 0 D 127.0.0.1 Vlanif1
172.16.1.0/24 IBGP 255 0 RD 100.0.0.2 Vlanif3
192.168.0.0/24 IBGP 255 0 RD 60.0.0.1 Vlanif3

<CE2>

显示指定目的ip的优选路由

<CE2>dis ip routing-table 192.168.0.10 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface

192.168.0.0/24 IBGP 255 0 RD 60.0.0.1 Vlanif3

<CE2>

(5)定位BGP无法建立的命令

<PE2>debug bgp 50.0.0.1 all
<PE2>t d
Info: Current terminal debugging is on.
<PE2>t m
Info: Current terminal monitor is on.
<PE2>sys
Enter system view, return user view with Ctrl+Z.
[PE2]info enable
Info: Information center is enabled.
[PE2]

 6、关键配置

CE3设备配置:

#
bgp 65005
router-id 10.0.0.1
peer 10.0.0.2 as-number 65001              (与运营商PE之间建立 EBGP 邻居)
#
ipv4-family unicast
undo synchronization
network 10.0.0.0 255.255.255.0
network 192.168.0.0
peer 10.0.0.2 enable
#

PE3设备配置:

#
bgp 65001
router-id 10.0.0.2
peer 10.0.0.1 as-number 65005                                   (与客户CE之间建立 EBGP 邻居)
peer 20.0.0.1 as-number 65001                                   (与运营商PE之间建立 IBGP 邻居)
peer 30.0.0.2 as-number 65001
peer 30.0.0.2 connect-interface GigabitEthernet0/0/0
peer 40.0.0.1 as-number 65001
peer 50.0.0.2 as-number 65002                                  (与运营商PE之间建立 EBGP 邻居)
peer 50.0.0.2 connect-interface GigabitEthernet0/0/1
#
ipv4-family unicast
undo synchronization
network 3.0.0.1 255.255.255.255
network 10.0.0.0 255.255.255.0
network 20.0.0.0 255.255.255.0
network 40.0.0.0 255.255.255.0
peer 10.0.0.1 enable
peer 20.0.0.1 enable
peer 30.0.0.2 enable
peer 40.0.0.1 enable
peer 50.0.0.2 enable
#
ospf 1
area 0.0.0.0
network 10.0.0.0 0.0.0.255
network 20.0.0.0 0.0.0.255
network 40.0.0.0 0.0.0.255
#

R1设备配置:

#
bgp 65001
router-id 20.0.0.1
peer 10.0.0.2 as-number 65001
peer 30.0.0.2 as-number 65001
peer 50.0.0.2 as-number 65001
peer 50.0.0.2 connect-interface GigabitEthernet0/0/0
#
ipv4-family unicast
undo synchronization
network 20.0.0.0 255.255.255.0
network 30.0.0.0 255.255.255.0
peer 10.0.0.2 enable
peer 30.0.0.2 enable
peer 50.0.0.2 enable
#
ospf 1
area 0.0.0.0
network 20.0.0.0 0.0.0.255
network 30.0.0.0 0.0.0.255
#

PE4设备配置:

#
bgp 65001
router-id 50.0.0.1
peer 20.0.0.2 as-number 65001          (与运营商PE之间建立 IBGP 邻居)
peer 20.0.0.2 connect-interface GigabitEthernet0/0/1
peer 30.0.0.1 as-number 65001          (与运营商PE之间建立 IBGP 邻居)
peer 50.0.0.2 as-number 65002          (与运营商PE之间建立 EBGP 邻居)
#
ipv4-family unicast
undo synchronization
network 30.0.0.0 255.255.255.0
network 50.0.0.0 255.255.255.0
peer 20.0.0.2 enable
peer 30.0.0.1 enable
peer 50.0.0.2 enable
#
ospf 1
area 0.0.0.0
network 30.0.0.0 0.0.0.255
network 50.0.0.0 0.0.0.255
#

PE2设备配置:

#
bgp 65002
router-id 70.0.0.1
peer 50.0.0.1 as-number 65001             (与运营商PE之间建立 IBGP 邻居)
peer 70.0.0.2 as-number 65009             (与客户CE之间建立 EBGP 邻居)
#
ipv4-family unicast
undo synchronization
network 50.0.0.0 255.255.255.0
network 70.0.0.0 255.255.255.0
peer 50.0.0.1 enable
peer 70.0.0.2 enable
#
ospf 1
area 0.0.0.0
network 50.0.0.0 0.0.0.255
network 70.0.0.0 0.0.0.255
#

CE2设备配置:

#
bgp 65009
router-id 70.0.0.2
peer 70.0.0.1 as-number 65002              (与运营商PE之间建立EBGP邻居)
peer 100.0.0.2 as-number 65009            (与同级设备建立IBGP邻居)
#
ipv4-family unicast
undo synchronization
network 70.0.0.0 255.255.255.0
network 100.0.0.0 255.255.255.0
network 172.16.0.0 255.255.255.0
peer 70.0.0.1 enable
peer 100.0.0.2 enable
#

PE1设备配置:

#
bgp 65001
router-id 60.0.0.1
peer 40.0.0.2 as-number 65001           (与运营商PE之间建立 IBGP 邻居)
peer 60.0.0.2 as-number 65009           (与客户CE之间建立 EBGP 邻居)
#
ipv4-family unicast
undo synchronization
network 40.0.0.0 255.255.255.0
network 60.0.0.0 255.255.255.0
peer 40.0.0.2 enable
peer 60.0.0.2 enable
#
ospf 1
area 0.0.0.0
network 40.0.0.0 0.0.0.255
network 60.0.0.0 0.0.0.255
#

CE1设备配置:

#
bgp 65009
router-id 60.0.0.2
peer 60.0.0.1 as-number 65001                (与运营商PE之间建立EBGP邻居)
peer 100.0.0.1 as-number 65009              (与同级设备建立IBGP邻居)
#
ipv4-family unicast
undo synchronization
network 60.0.0.0 255.255.255.0
network 172.16.1.0 255.255.255.0
peer 60.0.0.1 enable
peer 100.0.0.1 enable
#

原文地址:https://www.cnblogs.com/zhouhaibing/p/8098933.html