转载:了解 BGP 协议

微信扫一扫,分享到朋友圈

转载:了解 BGP 协议
4
咱花了一天多终于找到一个,咱能看懂的文章了,并且说的很好的(咱太菜了)
本文转载自 : https://blog.dwx.io/about-bgp/#dampening
Author: Jason Cooper
Link: https://blog.dwx.io/about-bgp/
Copyright Notice: All articles in this blog are licensed under BSD 3-Clause "New" or "Revised" License unless stating additionally.本文

突然就想写个系列文章了就……

(Jun 9 2018) 真的写了,系列文章,更多相关文章请移步 这里

前言

BGP 全称为 Border Gateway Protocol,版本 v4,是最常学习与应用的版本。BGP 通常用于大型网络结构中,用作交换不同 AS 之间的路由信息,例如 ISP 与 ISP 之间的路由交换。BGP 的复杂性在于建立 Peers 上的一些规范,以及有大量可以影响路由结果的属性 (Attributes),要学好 BGP,需要知道如何去调整这些属性。

BGP 协议

eBGP 与 iBGP

学习任何路由协议前,第一步要先了解如何组成邻居 (Neighbors),在 BGP 中也称作 Peers。Peers 利用 TCP179 端口通信,分为 Internal BGP(iBGP) Peering 与 External BGP(eBGP) Peering 两种。

如果两个路由在同一个 AS 内组 Peers,就会成为 iBGP Peers。反之,如果两个路由在不同的 AS 之间组成 Peers,就会成为 eBGP。

我们试试组建一组简单的 BGP Peers:

上图的设置如下:R1

1
2
3
4
5
6
7
hostname R1
!
interface Ethernet0/0
ip address 192.168.12.1 255.255.255.0
!
router bgp 65500
neighbor 192.168.12.2 remote-as 65501

R2

1
2
3
4
5
6
7
8
9
10
11
hostname R2
!
interface Ethernet0/0
ip address 192.168.12.2 255.255.255.0
!
interface Ethernet0/1
ip address 192.168.23.2 255.255.255.0
!
router bgp 65501
neighbor 192.168.12.1 remote-as 65500
neighbor 192.168.23.3 remote-as 65501

R3

1
2
3
4
5
6
7
hostname R3
!
interface Ethernet0/1
ip address 192.168.23.3 255.255.255.0
!
router bgp 65501
neighbor 192.168.23.2 remote-as 65501

要知道是否成功建立 Peers,可以使用 show ip bgp summary 命令。R2 Summary

1
2
3
4
5
6
7
R2#show ip bgp summary
BGP router identifier 192.168.23.2, local AS number 65501
BGP table version is 1, main routing table version 1

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.12.1 4 65500 21 21 1 0 0 00:18:57 0
192.168.23.3 4 65501 19 19 1 0 0 00:16:27 0

这部分栏位的含义解释:

  • Neighbor
    就是 Peer Router 的 IP address。
  • V
    是 BGP 的版本,正如前面所说,现今一般都使用 Version 4 这个版本。
  • AS
    Peer Router 的 AS number。如果 AS 与第一行显示的 local AS number 相同,即代表建立了 iBGP,否则,建立的就是 eBGP 了。
  • MsgRcvd 及 MsgSent
    MsgRcvd 是从 Peer 接收到的 BGP 封包,MsgSent 则是传输到 Peer 的封包,在 default 的环境下,BGP Router 会每分钟 (因为 default keepalive time=60 秒) 传输 keepalive message 给 Peer,所以这两个数是会不断上升的。
  • TblVer
    传输给这个 Peer 的最新的 BGP Database 版本,这个稍后会再讲。
  • InQ
    显示收到而未被处理的 BGP 信息,如果这个数字很大的话,即是很多信息在排队等待处理,代表 Router 的 CPU 很忙,并未能够处理 Peer 传来 BGP 信息。
  • OutQ
    显示等待送出的 BGP 信息,如果这个数字很大的话,可能是由于 CPU 很忙或者 Bandwidth 不足够而导致 BGP 信息未能送出。
  • Up / Down
    就是这个 Connection 的维持上线或下线时间有多久了。
  • State / PfxRcd
    如果显示一个数字的话 (就算是 0 也好),代表从这个 Peer 收到的 BGP Route 的数量,即是 Peer 已成功建立。但如果是显示 Active 的话,很不幸,这代表 Peer 没有建立成功。

学习建立 Peers

建立 Peers 的状态 (State)

一般来说,如果设置没有问题的话,BGP Peers 就会成为 Established 的状态。但实际上,Peers 在进入 Established 之前会经过几个状态 (State),了解这几个 State 对 troubleshooting 很有帮助。

BGP Peers 的 6 个 State 分别是:

  • IDLE
    Router 正在搜索 Routing Table,找一条能够连接 Neighbor 的路径。(注意:不会使用 Default Route。)
  • CONNECT
    Router 已经找到连接 Neighbor 的路径了,并且完成了 TCP 3-way handshake(俗称三段式打脸握手)。
  • OPEN SENT
    已经传输了 BGP 的 OPEN 封包,告诉对方希望建立 Peers。
  • OPEN CONFIRM
    收到了 Neighbor 回传封包,对方赞成建立 Peers。
  • ESTABLISHED
    两个 Neighbor 已经成功建立了 Peers。
  • ACTIVE
    这是最不想看到的 State,代表 Router 仍然处于主动传输封包的状态,收不到对方回传,如果持续见到此状态的话,代表 Peers 并未成功建立。

如果想了解 State 的变化,可以使用 debug ip bgp,然后执行 clear ip bgp * 来让 BGP Peers 从新建立起来。R3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
R3#debug ip bgp
BGP debugging is on for address family: IPv4 Unicast
R3#clear ip bgp *
R3#
*Mar 1 02:11:24.015: BGPNSF state: 192.168.23.2 went from nsf_not_active to nsf_not_active
*Mar 1 02:11:24.019: BGP: 192.168.23.2 went from Established to Idle
*Mar 1 02:11:24.019: %BGP-5-ADJCHANGE: neighbor 192.168.23.2 Down User reset
*Mar 1 02:11:24.023: BGP: 192.168.23.2 closing
*Mar 1 02:11:24.027: BGP: 192.168.23.2 went from Idle to Active
*Mar 1 02:11:24.039: BGP: 192.168.23.2 open active, local address 192.168.23.3
*Mar 1 02:11:24.111: BGP: 192.168.23.2 went from Active to OpenSent
*Mar 1 02:11:24.111: BGP: 192.168.23.2 sending OPEN, version 4, my as: 65501, holdtime 180 seconds
*Mar 1 02:11:24.111: BGP: 192.168.23.2 send message type 1, length (incl. header) 45
*Mar 1 02:11:24.167: BGP: 192.168.23.2 rcv message type 1, length (excl. header) 26
*Mar 1 02:11:24.167: BGP: 192.168.23.2 rcv OPEN, version 4, holdtime 180 seconds
*Mar 1 02:11:24.167: BGP: 192.168.23.2 rcv OPEN w/ OPTION parameter len: 16
*Mar 1 02:11:24.167: BGP: 192.168.23.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 6
*Mar 1 02:11:24.167: BGP: 192.168.23.2 OPEN has CAPABILITY code: 1, length 4
*Mar 1 02:11:24.167: BGP: 192.168.23.2 OPEN has MP_EXT CAP for afi/safi: 1/1
*Mar 1 02:11:24.167: BGP: 192.168.23.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 2
*Mar 1 02:11:24.167: BGP: 192.168.23.2 OPEN has CAPABILITY code: 128, length 0
*Mar 1 02:11:24.167: BGP: 192.168.23.2 OPEN has ROUTE-REFRESH capability(old) for all address-families
*Mar 1 02:11:24.167: BGP: 192.168.23.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 2
*Mar 1 02:11:24.167: BGP: 192.168.23.2 OPEN has CAPABILITY code: 2, length 0
*Mar 1 02:11:24.167: BGP: 192.168.23.2 OPEN has ROUTE-REFRESH capability(new) for all address-families
BGP: 192.168.23.2 rcvd OPEN w/ remote AS 65501
*Mar 1 02:11:24.167: BGP: 192.168.23.2 went from OpenSent to OpenConfirm
*Mar 1 02:11:24.167: BGP: 192.168.23.2 went from OpenConfirm to Established
*Mar 1 02:11:24.167: %BGP-5-ADJCHANGE: neighbor 192.168.23.2 Up

用 Loopback 来建立 iBGP Peers

在一个 AS 当中,除了 BGP 之外,一般会使用 IGP (例如:OSPF, EIGRP) 来作路由交换,在这个情况下,我们会使用 Loopback interface 作为 iBGP 的 neighbor address。因为 Loopback interface 永远是 UP 的,而且 Neighbor 之间可以自己通过 IGP 来寻找到达 Loopback 的路径,这比起使用 Interface IP 来作 neighbor address 来得灵活一点,也减少了因为 Interface down 而令 BGP Table 不稳定。

举个例子:

在图中例子里,假设 R2、R3 及 R4 正运行 OSPF,如果 R2 连到 R3 的 iBGP connection 是使用 R3 e0/1 interface IP,那么当 R3 e0/1 因为某些原因而 Down 的话,iBGP 便会断开,让我们做个实验吧。R2

1
2
3
4
5
6
7
8
9
10
11
12
13
hostname R2
!
interface Ethernet0/1
ip address 192.168.23.2 255.255.255.0
!
interface Ethernet0/2
ip address 192.168.24.2 255.255.255.0
!
router ospf 1
network 0.0.0.0 255.255.255.255 area 0
!
router bgp 65501
neighbor 192.168.23.3 remote-as 65501

R3

1
2
3
4
5
6
7
8
9
10
11
12
13
hostname R3
!
interface Ethernet0/1
ip address 192.168.23.3 255.255.255.0
!
interface Ethernet0/2
ip address 192.168.34.3 255.255.255.0
!
router ospf 1
network 0.0.0.0 255.255.255.255 area 0
!
router bgp 65501
neighbor 192.168.23.2 remote-as 65501

R4

1
2
3
4
5
6
7
8
9
10
hostname R4
!
interface Ethernet0/0
ip address 192.168.24.4 255.255.255.0
!
interface Ethernet0/1
ip address 192.168.34.4 255.255.255.0
!
router ospf 1
network 0.0.0.0 255.255.255.255 area 0

正常情况下,R3 与 R2 能够建立 iBGP Peers:R3

1
2
3
4
5
6
R3#show ip bgp summary
BGP router identifier 192.168.23.3, local AS number 65501
BGP table version is 1, main routing table version 1

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.23.2 4 65501 11 15 1 0 0 00:05:22 0

但若果我们把 R3 的 e0/1 shutdown,iBGP connection 立刻断开。过了 3 分钟之后,状态变成 Active,因为 BGP default 的 holdtime 是 180 秒,如果过了 180 秒对方也没有反应,则进入 Active 状态,表示已经无法成功连接。R3

1
2
3
4
5
6
R3#show ip bgp summary
BGP router identifier 192.168.23.3, local AS number 65501
BGP table version is 1, main routing table version 1

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.23.2 4 65501 12 20 0 0 0 00:00:06 Active

看!这就是用 Interface IP 做 Neighbor 的坏处。这次我们试试更改设置,把 R2 和 R3 都改成用 Loopback 做 Neighbor IP。步骤如下:

  1. 首先在 R2 和 R3 加入 Loopback Interface,并设置 IP address
  2. 在 bgp config 里,把 neighbor 的 IP 改成对方的 Loopback address
  3. 还要加入一句 neighbor [IP] update-source [interface] 的命令

R2

1
2
3
4
5
6
7
8
hostname R2
!
interface Loopback0
ip address 2.2.2.2 255.255.255.255
!
router bgp 65501
neighbor 3.3.3.3 remote-as 65501
neighbor 3.3.3.3 update-source Loopback0

R3

1
2
3
4
5
6
7
8
hostname R3
!
interface Loopback0
ip address 3.3.3.3 255.255.255.255
!
router bgp 65501
neighbor 2.2.2.2 remote-as 65501
neighbor 2.2.2.2 update-source Loopback0

这样子,就算把 R3 的 e0/1 shutdown,iBGP 都不会有中断的情况,因为 R2 和 R3 会跟据 OSPF 提供的路由使用 R2-R4-R3 的路径来连接对方的 Loopback Interface IP。而且在 show ip bgp summary 中也看到 Neighbor IP 变成对方 Loopback 的 IP 了。R3

1
2
3
4
5
6
R3#sh ip bgp summary
BGP router identifier 192.168.23.3, local AS number 65501
BGP table version is 1, main routing table version 1

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
2.2.2.2 4 65501 13 13 1 0 0 00:09:12 0

请留意,Loopback 这个技巧通常只用在 iBGP 的 connection,甚少用于 eBGP,因为我们不会用 IGP 把两个不同的 AS 连起来。

eBGP Multihop 指令

有时候,两个 Router 中间可能有其他网络设备使到两个 BGP Neighors 不能直接连接,很大机会是防火墙,因为连接其他 AS 的位置一般是 Network 的边缘 (Edge),企业或组织通常会安装防火墙以策安全。遇到这些情况,我们需要用 ebgp multihop 来使两个 Router 连接起来。请看以下例子。

设置好图中 R1 和 R2 的 IP Address 之后,各加入一条 Static Route 把路径指向 Firewall,我们用一个 Router 来模拟成 Firewall(我这是直接配了一个 Firewall),它能够做 Routing。R1

1
2
3
4
5
6
7
8
9
hostname R1
!
interface Ethernet0/0
ip address 10.1.1.1 255.255.255.0
!
router bgp 65500
neighbor 10.2.2.1 remote-as 65501
!
ip route 10.2.2.0 255.255.255.0 Ethernet0/0

R2

1
2
3
4
5
6
7
8
9
hostname R2
!
interface Ethernet0/1
ip address 10.2.2.1 255.255.255.0
!
router bgp 65501
neighbor 10.1.1.1 remote-as 65500
!
ip route 10.1.1.0 255.255.255.0 Ethernet0/1

Firewall

1
2
3
4
5
6
7
hostname Firewall
!
interface Ethernet0/0
ip address 10.1.1.2 255.255.255.0
!
interface Ethernet0/1
ip address 10.2.2.2 255.255.255.0

在 R1 测试一下,明明可以 PING 到 10.2.2.1,就是没法建立 BGP Peers:R1

1
2
3
4
5
6
7
8
9
10
11
12
R1#ping 10.2.2.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.2.2.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 40/50/72 ms
R1#show ip bgp summary
BGP router identifier 10.1.1.1, local AS number 65500
BGP table version is 1, main routing table version 1

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
10.2.2.1 4 65501 31 32 0 0 0 00:02:05 Idle

这时候在两个 Router 的 BGP config 里加入

neighbor [ip] ebgp-multihop [max hop count]

max hop count 是两个 Router 中间相隔的 hop 数目。

设置好之后,问题就迎刃而解:R1

1
R1(config-router)# neighbor 10.2.2.1 ebgp-multihop 2

R1

1
2
R2(config-router)# neighbor 10.1.1.1 ebgp-multihop 2
*Mar 1 00:48:31.035: %BGP-5-ADJCHANGE: neighbor 10.1.1.1 Up

Password

为了认证 Peer Router,我们可以加入 Password,方法如下:

1
2
3
router bgp 65000
neighbor 2.2.2.2 remote-as 65000
neighbor 2.2.2.2 password cisco

只要两边都加入了 password 指令,即可以通过密码认证。

Peer Group

若果要为各个 Neighbor 做相同的设置,可以使用 Peer Group 来简化,既方便又快捷。用以下的一套设置为例:

1
2
3
4
5
6
7
8
9
10
router bgp 65000
neighbor 2.2.2.2 remote-as 65000
neighbor 2.2.2.2 password cisco
neighbor 2.2.2.2 update-source Loopback0
neighbor 3.3.3.3 remote-as 65000
neighbor 3.3.3.3 password cisco
neighbor 3.3.3.3 update-source Loopback0
neighbor 4.4.4.4 remote-as 65000
neighbor 4.4.4.4 password cisco
neighbor 4.4.4.4 update-source Loopback0

如果使用 Peer Group 将会变成这样:

1
2
3
4
5
6
7
8
router bgp 65000
neighbor iBGPNei peer-group // 为 Peer Group 设置一个名称
neighbor iBGPNei remote-as 65000 // 开始为 Peer Group 做设置
neighbor iBGPNei password cisco
neighbor iBGPNei update-source Loopback0
neighbor 2.2.2.2 peer-group iBGPNei // 把 2.2.2.2 放进 Peer Group
neighbor 3.3.3.3 peer-group iBGPNei
neighbor 4.4.4.4 peer-group iBGPNei

Network 指令

学好了建立 Peers 之后,终于可以开始尝试在 Neighbor 之间交换 Route 了。最基本的方法就是使用 Network 这个指令,不过在 BGP 中执行 Network 指令,其功能与 OSPF、EIGRP 等的 Routing Protocol 有所不同。在 BGP 中,Network 指令只会宣告发布一个网段,而不会让任何 Interface 加入成为 BGP 的发布点。原因其实很理所当然,因为 BGP 的 Neighbor 指令已经让 BGP 知道那些 Interface 加入 BGP,而且完成了 Peers 的建立,而 Network 指令只需处理发布网段的事情便可以了。

要用 BGP 发布一个网段,Router 本身的 Route Table 必需有该网段的 Route,否则不能发布。

请看看以下的例子:

假设所有 IP 和 Neighbor 已经设置好,现在我们尝试在 R1 加一个 Loopback,然后把 Loopback 这个网段发布出去:R1

1
2
3
4
5
6
hostname R1
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
router bgp 65100
network 1.1.1.0 mask 255.255.255.0

先在 R1 用 show ip route 确认一下 1.1.1.0/24 出现在 Routeing table 之中。

1
2
3
4
5
6
7
R1#show ip route

<Output Omitted>

C 192.168.12.0/24 is directly connected, Ethernet0/0
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0

然后使用 show ip bgp,可以看到 1.1.1.0/24 已经加入 BGP Table 了。

1
2
3
4
5
6
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 0.0.0.0 0 32768 i

再来看看 R2 的 show ip bgp,有收到 1.1.1.0/24,而且 show ip route 也看到这网段已成功加入在 Route Table 之中!

1
2
3
4
5
6
R2#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 192.168.12.1 0 0 65100 i
1
2
3
4
5
6
7
8
R2#show ip route

<Output Omitted>

C 192.168.12.0/24 is directly connected, Ethernet0/0
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 192.168.12.1, 00:08:35
C 192.168.23.0/24 is directly connected, Ethernet0/1

R3 的情况又怎样呢?

1
2
3
4
5
6
7
8
9
10
11
12
13
R3#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 192.168.23.2 0 65200 65100 i
R3#show ip route

<Output Omitted>

1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 192.168.23.2, 00:16:04
C 192.168.23.0/24 is directly connected, Ethernet0/1

就是一个 Network 指令,便完成了这个简单的 BGP 网络路由交换了。在此我们先解释一下在 show ip bgp 中看到的栏位都代表什么意思?

  • Network
    网段的 Network ID 与及 Prefix Length。
  • Next Hop
    要到达这个网段的 Next Hop IP address。如果显示为 0.0.0.0,即是说此网段是由本地 Router 发布的。另外有一个重要的地方要注意,就是此栏位所显示的 Next Hop IP 必需有路由可到达,此网段才会放入 Routing Table 之中,暂时请稍稍记一下,稍后的例子会加以说明。
  • Metric
    这是其中一个用来选择最佳路径的属性。在路径选择的部份会详细说明。
  • LocPrf
    也是其中一个用来选择最佳路径的属性。
  • Weight
    特别注意这是 Cisco 独有的栏位,如果这条 Route 是由本机 Network 指令产生的话,就会设置成 32768。这也是其中一个用来选择最佳路径的属性。
  • Path
    到达这个网段所经过的 AS Number,如果该网段是在本机的 AS Number 之中,此值便会变成空白,请留意是空白,并非 i ,i 是下一个栏位 Origin。
  • Origin
    Origin 并没有在栏位名显示出来,Origin 的值就显示在 Path 属性后面,只有三个值:i , e 或是 ?
    • i
      此 Route 的来源是 IGP 或者是用 Network 指令
    • e
      此 Route 的来源是 EGP,不过 EGP 已经是历史的产物,可以不用理会了。
    • ?
      此 Route 是通过 redistribute 得来的

Origin 也是选择最佳路径的一个方法,在稍后会详细说明。

Next-hop-self 指令

现在我们试试另一个例子:

R1 与 R2 是 eBGP,R2 与 R3 是 iBGP,R3 与 R4 是 eBGP。假设全部 IP 及 Peers 已经设置好,我们在 R1 设置 Loopback Interface 然后把它发布出去。看看 R2 的 BGP database,有 > 标记表示 BGP 选好了用 Next Hop IP 192.168.12.1 来到达 1.1.1.0/24,Route Table 也似乎没问题。R2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
R2#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 192.168.12.1 0 0 65100 i
R2#show ip route

<Output Omitted>

C 192.168.12.0/24 is directly connected, Ethernet0/0
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 192.168.12.1, 00:07:37
C 192.168.23.0/24 is directly connected, Ethernet0/1

再看看 R3 的 BGP Table,为什么没有选到 best path,Route table 也没有加入 1.1.1.0 这条 Route,为什么?R3

1
2
3
4
5
6
R3#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 192.168.12.1 0 100 0 65100 i

R3

1
2
3
4
5
6
7
R3#show ip route

<Output Omitted>

C 192.168.12.0/24 is directly connected, Ethernet0/0
1.0.0.0/24 is subnetted, 1 subnets
C 192.168.23.0/24 is directly connected, Ethernet0/1

大家还记得吗?在上一部份介绍 Next Hop 这个栏位时,我们说过 Next Hop IP 必需要「可以到达」的才能把该条 Route 加入 Route Table,由于对 R3 来说,192.168.12.1 并没有路径可以到达 (即 Route Table 里找不到 192.168.12.1 的 Route) ,所以 R3 不会把这条 Route 加入 Route Table。

至于为什么 Next Hop IP 会是 192.168.12.1 而不是 R2 的 192.168.23.2 呢?这是因为当 BGP 把一条 Route 用 iBGP 发布给 Neighbor 时,Default 是不会更改其 Next Hop 的 IP ,这点我们需要紧记!

怎么解决呢?有两个办法:

第一个方法是加入一条 Static Route (或用其他 IGP) 让 R3 学懂怎样去 192.168.12.1。加了之后便发现 BGP Route 成功得到了:R3

1
2
3
4
5
6
7
8
9
10
11
R3(config)#ip route 192.168.12.1 255.255.255.255 ethernet 0/1
R3(config)#do sh ip route

<Output Omitted>

192.168.12.0/32 is subnetted, 1 subnets
S 192.168.12.1 is directly connected, Ethernet0/1
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [200/0] via 192.168.12.1, 00:00:04
C 192.168.23.0/24 is directly connected, Ethernet0/1
C 192.168.34.0/24 is directly connected, Ethernet0/0

另一个方法是使用 Next-hop-self 指令,迫使 R2 在发布 Route 给 R3 时使用自己的 IP 作为 Next Hop IP。只要在 BGP config 中加入一句 neighbor [IP] next-hop-self 便可以了。

1
2
3
4
router bgp 65200
neighbor 192.168.12.1 remote-as 65100
neighbor 192.168.23.3 remote-as 65200
neighbor 192.168.23.3 next-hop-self

现在我们再看看 R3 的 BGP Table,Next Hop 变成 192.168.23.2 了,有 > 标记,证明 BGP 接受了这条为 Best Path,Route Table 亦成功加入这条 Route。R3

1
2
3
4
5
6
R3#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*>i1.1.1.0/24 192.168.23.2 0 100 0 65100 i

R3

1
2
3
4
5
6
7
8
R3#show ip route

<Output Omitted>

1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [200/0] via 192.168.23.2, 00:02:47
C 192.168.23.0/24 is directly connected, Ethernet0/1
C 192.168.34.0/24 is directly connected, Ethernet0/0

Synchronization (同步)

有些情况,我们需要通过 IGP 作媒介来让两个或多个 iBGP Neighbor 连接,如图 6 这个例子,AS65200 的 R2 和 R5 成为 iBGP Peers,然后我们想把 AS65100 的 Route 通过 AS65200 发布到 AS65300,这时候我们需要注意同步的问题。我们试把着眼点放于 R5 上,当 BGP 的 Route,到达 R5 之后,由于 R5 开启了 IGP,所以 R5 把 Route 发布去 AS65300 之前会先检查同步的条件有没有达成,如果条件达成就发出去,相反就不会发出去。

所谓达到同步,就是说从 iBGP 收回来的 Route,在 Routing Table 中必需要有相同的 IGP Route 能够到达。

例如:在 AS65100 发布 1.1.1.0/24 到 R2,R2 收到后发布到 R5,R5 会检查 Route Table 中有没有 IGP Route 能够去到 1.1.1.0/24,如果有就是同步了。

就图中的例子,我们可以看看 R2 和 R5 的设置。R2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
hostname R2
!
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
router ospf 1
network 2.2.2.0 0.0.0.255 area 0
network 192.168.23.0 0.0.0.255 area 0
network 192.168.24.0 0.0.0.255 area 0
!
router bgp 65200
neighbor 5.5.5.5 remote-as 65200
neighbor 5.5.5.5 update-source Loopback0
neighbor 5.5.5.5 next-hop-self
neighbor 192.168.12.1 remote-as 65100

R5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
hostname R5
!
interface Loopback0
ip address 5.5.5.5 255.255.255.0
!
router ospf 1
network 5.5.5.0 0.0.0.255 area 0
network 192.168.35.0 0.0.0.255 area 0
network 192.168.45.0 0.0.0.255 area 0
!
router bgp 65200
neighbor 2.2.2.2 remote-as 65200
neighbor 2.2.2.2 update-source Loopback0
neighbor 192.168.56.6 remote-as 65300

在 R2 确认有收到 1.1.1.0/24:R2

1
2
3
4
R2#show ip bgp
<Output Omitted>
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 192.168.12.1 0 0 65100 i

R5 收到但没有 > 标记,所以没有发布出去:R5

1
2
3
4
R5#show ip bgp
<Output Omitted>
Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 2.2.2.2 0 100 0 65100 i

为什么没有发布呢?因为 IGP 「看不懂」 1.1.1.0/24R5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
R5# show ip route

<–Output Omitted–>

2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/21] via 192.168.45.4, 00:37:38, Ethernet0/1
[110/21] via 192.168.35.3, 00:37:38, Ethernet0/0
C 192.168.45.0/24 is directly connected, Ethernet0/1
O 192.168.24.0/24 [110/20] via 192.168.45.4, 00:37:38, Ethernet0/1
5.0.0.0/24 is subnetted, 1 subnets
C 5.5.5.0 is directly connected, Loopback0
C 192.168.56.0/24 is directly connected, Ethernet0/2
O 192.168.23.0/24 [110/20] via 192.168.35.3, 00:37:38, Ethernet0/0
C 192.168.35.0/24 is directly connected, Ethernet0/0

所以 R6 什么也没有:R6

1
2
3
R6# show ip bgp

R6#

有两个办法可以解决,第一个方法当然是把 IGP 同步,例如在 R2 把 BGP Route redistribute 到 OSPF 之中。R2

1
2
R2(config)#router ospf 1
R2(config-router)#redistribute bgp 65200 subnets

R5 有 best path 了。(留意 r 的意思是 RIB failure,不要担心,这是因 iBGP (AD=200) 的 AD 不够 OSPF (AD=110) 低,所以系统标了 r(Route Table 不用这条 Route,但对 BGP 的发布没有影响)。R5

1
2
3
4
5
6
R5#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
r>i1.1.1.0/24 2.2.2.2 0 100 0 65100 i

R6 收到 BGP Route 了。R6

1
2
3
4
5
6
R6#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 192.168.56.5 0 65200 65100 i

那么另一个解决办法是什么呢?就是干脆把 Synchronization 关掉。只要在 BGP 设置中用 no synchronization 这个指令便可以。

不过有一点需要留意的是:在某些 IOS 版本中,Synchronization default 是关掉的。R2

1
2
R2(config)#router bgp 65200
R2(config-router)#no synchronization

R5

1
2
R5(config)#router bgp 65200
R5(config-router)#no synchronization

Route Reflector

再讨论上图的网络,读者有没有想过为什么要借助 OSPF 来当桥梁呢?如果把全部 Router 都用 iBGP 连起来不就可以了吗?答案是可以的!

不过现在又要宣布 BGP 中一个重要的法则…

从 iBGP Peers 得到的 Route 不会发布到另一个 iBGP Peers。

如果 AS65200 全部使用 iBGP 的话,R2 从 R1 那里收到 1.1.1.0/24,并发布到 R3 ,但 R3 不会把 Route 发给 R5。同样地,R4 也不会发给 R5。

解决方法之一是 R2 也和 R5 建立 iBGP 连线,除此之外,为了整个 AS 里的 Route 可以互通,我们应该把所有 Router 对应其他 Router 都建立 iBGP 连线,即所谓的 Fully Mesh。 但 Fully Mesh 随着 Router 的数量增加,连线数目也会几何级数上升,另一个较好的方法是使用 neighbor [IP] route-reflector-client

Route Reflector 指令可以让 BGP Router 把从 iBGP Peers 得到的 Route 发布到另一个 iBGP Peers。设置方法如下:R3

1
2
3
4
5
6
7
hostname R3
!
router bgp 65200
neighbor 192.168.23.2 remote-as 65200
neighbor 192.168.23.2 route-reflector-client
neighbor 192.168.35.5 remote-as 65200
!

Confederation

有时遇到较复杂的网路,在同一个 AS 里面有很多只 BGP Router 的话,用 Route Reflector 来建 iBGP Peers 仍然令人相当头痛,这时候我们还有一杀着,就是使用 Confederation。

Confederation 可以把一个 AS 分成多个 Sub-AS,只需要每一个 Sub-AS 里的 BGP Router 要 Fully Mesh,设置简单之余又方便管理。而其他 AS 的 Router 亦不会看到这些 Sub-AS。

看下面例子,图中把 AS 65000 分成两个 Sub-AS 10 和 20,留意 AS 65100 的 R7 会和 AS 65000 的 R1 成 eBGP Peers,而不是 AS 10,同样地, AS 65200 的 R6 会和 AS 65000 的 R5 成 eBGP Peers,而不是 AS 20。

来看看 R1 的 BGP 设置,基本上分别不大,只是多了以下两个 Command:

  • bgp confederation identifier [AS Number]
    宣告这个 Sub-AS 包含在那一个主 AS 里
  • bgp confederation peers [AS Number]
    还有那些相邻的 Sub-AS

R1

1
2
3
4
5
6
7
8
9
hostname R1
!
router bgp 10
bgp confederation identifier 65000
bgp confederation peers 20
neighbor 192.168.12.2 remote-as 10
neighbor 192.168.13.3 remote-as 10
neighbor 192.168.14.4 remote-as 20
neighbor 192.168.17.7 remote-as 65100

假设全部 Router 已经设置好 BGP Peers,我们试试在 R6 用 Network 指令去发布 6.6.6.0/24 的网段。

到 R7 看看 BGP Table,AS Path 并没有显示 AS 10 和 20 哦R7

1
2
3
4
5
6
R7#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*> 6.6.6.0/24 192.168.17.1 0 65000 65200 i

Best Path (最佳路径) 的选择

说了这么久,终于进入我们的主菜,就是 BGP Best Path 的选择。什么时候需要选择呢?当一只 Router 收到很多条关于同一个 destination 的 Route 时,一般情况下 BGP 只会选择一条最好的来使用。而选择的方法就是通过比较每条 BGP Route 当中不同的 Attribute (属性),现在介绍这些属性和比较的顺序。

基本条件

在正式比较之前,BGP 会先检查 Route 的 3 个属性,附合这 3 个条件的 Route 才可进入比较程序,不附合的 Route 在这刻已经被即时淘汰了。

  1. Next-hop Address 所在 Network 必需为可到达,即存在于 Route Table 之中。
  2. As-path 不存在 Router 自身的 AS Number,这是为了防止 Loop 发生。
  3. 如 BGP 有开启 Synchronization,则必需附合,详情请看本篇 Synchronization 部份。

Weight (选较大的)

第一个比较项目是比 Weight,Weight 是本地 Router 对自己的 Peers 的权重值,谁的 Weight 大就用它给我的那条 Route。

请注意 Weight 是 Cisco 独有的 Attribute,其他路由器是没有的。

用以下例子去测试一下,假设所有 IP address,BGP Peers 都设置好,R1 与 R2 和 R1 与 R3 之间的 iBGP Peers 用了 Next-hop-self 指令,R1 执行了 Route Reflector,R6 把 Loopback 0 的 6.6.6.0/24 用 Network 指令发布出来。

在 R1 看看 BGP Table,得知现时选择了 192.168.12.2 为 Best Path,两条 Route 的 Weight 是 0,因为在没有设置的情况下,Weight default 设置是 0 ,由于 Weight 相等,BGP 用了其他方法去决定 Next Hop 192.168.12.2 是 Best Path。R1

1
2
3
4
5
6
7
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
* i6.6.6.0/24 192.168.13.3 0 100 0 65100 65300 i
*>i 192.168.12.2 0 100 0 65200 65300 i

有几个方法可以更改 Weight 的设置,其中一个最简单的方法就是在 R1 使用 neighbor <ip> weight <default weight> 指令,然后用 clear ip bgp * 去 reset 所有 Peers:R1

1
2
3
4
5
6
7
8
9
10
11
12
R1(config)#router bgp 65000
R1(config-router)#neighbor 192.168.13.3 weight 1000
R1(config-router)#end
R1#
*Mar 1 00:21:19.123: %SYS-5-CONFIG_I: Configured from console by console
R1#clear ip bgp *
R1#
*Mar 1 00:24:05.375: %BGP-5-ADJCHANGE: neighbor 192.168.12.2 Down User reset
*Mar 1 00:24:05.379: %BGP-5-ADJCHANGE: neighbor 192.168.13.3 Down User reset
*Mar 1 00:24:06.079: %BGP-5-ADJCHANGE: neighbor 192.168.12.2 Up
R1#
*Mar 1 00:24:06.587: %BGP-5-ADJCHANGE: neighbor 192.168.13.3 Up

这时再 show ip bgp,Next Hop 192.168.13.3 这条 Route 的 Weight 值变成 1000 了,基于这条 Route Weight 1000 比较大,所以选择了这条做 Best Path。亦只有这条 Route 会被 R1 发布到其他 Peers。R1

1
2
3
4
5
6
7
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
* i6.6.6.0/24 192.168.12.2 0 100 0 65200 65300 i
*>i 192.168.13.3 0 100 1000 65100 65300 i

留意 Weight 只是一个用于 Local Router 的 Attribute,所以 Weight 值并不会跟随 Route 发布到另一个 Router。这时看看 R2 的 BGP Table,所有 Weight 仍然是 0,R2 选择自己的 Best Path。R2

1
2
3
4
5
6
7
R2#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
* i6.6.6.0/24 192.168.13.3 0 100 0 65100 65300 i
*> 192.168.24.4 0 65200 65300 i

Local Preference (选较大的)

如果因为 Weight 相同而没法选出 Best Path,BGP 会用 Local Preference 来判断,一条 Route 的 Local Preference 较大的话,它就是整个 AS 对于该个 Destination 的出口。

接着,我们再使用相同的例子,但先在 R1 把两条 Route 的 Weight 调至一样。R1

1
2
3
4
5
6
7
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*>i6.6.6.0/24 192.168.12.2 0 100 1000 65200 65300 i
* i 192.168.13.3 0 100 1000 65100 65300 i

这样第一条 Route 又比选为 Best Path 了。

等等,我们还未作 Local Preference 的调校工作,为什么会是 100 呢?这是因为凡是通过 iBGP Peers 传来的 Route,Local Preference default 值都是 100。

为了证明较大的被选中,我们尝试在 R3 把从 R5 传来 6.6.6.0/24 这条 Route 的 Local Preference 设置成 500,看看会有什么变化。我们可以使用 Route Map 来完成。R3

1
2
3
4
5
6
7
8
9
10
R3(config)#router bgp 65000
R3(config-router)#neighbor 192.168.35.5 route-map TuningLocPrf in
R3(config-router)#exit
R3(config)#ip access-list extended RouteMatch
R3(config-ext-nacl)#permit ip 6.6.6.0 0.0.0.255 any
R3(config-ext-nacl)#route-map TuningLocPrf permit 10
R3(config-route-map)#match ip address RouteMatch
R3(config-route-map)#set local-preference 500
R3(config-route-map)#end
R3#clear ip bgp *

由于 Local Preference 是整个 AS 的事,所以这个 Attribute 会传输到 iBGP Peers。

看看 R1 的 BGP Table,可以看到 Local Preference 已经变成 500 了,顺理成章地,R1 把这条选为 Best Path。R1

1
2
3
4
5
6
7
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*>i6.6.6.0/24 192.168.13.3 0 500 1000 65100 65300 i
* i 192.168.12.2 0 100 1000 65200 65300 i

Locally Originated (本机原生)

即由本机用指令 Network、Aggregate-address 生成或由本机把 IGP Route Redistribute 到 BGP 的 Route,相比较从其他 Neighbor 收回来的 Route 要好。

AS Path (选较短的)

AS Path 是到达目的地网段所要经过的 AS,BGP 认为 AS Path 越短越好,如果以上两点都无法分出胜负,BGP 就会选 AS Path 较短的那条 Route 为 Best Path。

以同一例子来测试,不过我们先把 R1 的两条 Route Local Preference 值调整到一样。R1

1
2
3
4
5
6
7
R1#sh ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*>i6.6.6.0/24 192.168.12.2 0 500 1000 65200 65300 i
* i 192.168.13.3 0 500 1000 65100 65300 i

现时使用了第一条 Route 为 Best Path,如果把第一条的 AS Path 增长,那么第二条 Route 应该可以成为 Best Path。

如果我们不想大费周章去改变网络的 Topology,那怎样可以简单地改动 AS Path 来测试呢?

我们可以使用 Route Map 里面的 Prepend。Prepend 可以在 AS Path 很犯规地加入一些 AS Number,让它变得较长,不过此方法只可用于 eBGP Peers 传来的 Route,iBGP Peers 传出的是不能修改 AS Path 的。因此,为了延长第一条 Route 的 AS Path,我们可以走到 R4 改设置,实例如下:R4

1
2
3
4
5
6
7
8
9
R4(config)#router bgp 65200
R4(config-router)#neighbor 192.168.24.2 route-map TuningAsPath out
R4(config-router)#exit
R4(config)#ip prefix-list MatchNetwork seq 5 permit 6.6.6.0/24
R4(config)#route-map TuningAsPath
R4(config-route-map)#match ip address prefix-list MatchNetwork
R4(config-route-map)#set as-path prepend 65200
R4(config-route-map)#end
R4#clear ip bgp *

为什么是 Prepend 65200 呢?

我们目标只想把 AS Path 延长,AS Number 是什么都没有关系,不过为了防止有 Routing Loop 出现,我们通常都会使用 AS Path 最前面的一个 AS Number 作为 Prepend 的 AS,所以就用了 65200。

现在看看 R1 的 BGP Table,由于第二条 Route 的 AS Path 较短,所以被选定为 Best Path 了。R1

1
2
3
4
5
6
7
8
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
* i6.6.6.0/24 192.168.12.2 0 500 1000 65200 65200 65300 i
*>i 192.168.13.3 0 500 1000 65100 65300 i
R1#

Origin Type (选较小的)

之前曾经介绍过 Origin 有三个值,i , e 和 ? ,e 已经很少会用到了,因此只需学习 i 和 ?i 表示该 Route 的来源是 IGP、使用 Network 指令或 Aggregate-address 指令,? 表示该 Route 是通过 redistribute 得来的。

要测试这个 Attribute ,首先我们得把 AS Path 长度调至一样,举个例子:R1

1
2
3
4
5
6
7
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*>i6.6.6.0/24 192.168.12.2 0 500 1000 65200 65300 i
* i 192.168.13.3 0 500 1000 65100 65300 i

现在尝试把第一条 Route 的 Origin 改成 ? ,看看能否把 Best Path 改变。

要怎样改呢?我们可以在 R4 加入一条指向 6.6.6.0/24 的 Static Route,然后把它 Redistribute 到 BGP 中。R4

1
2
3
R4(config)#ip route 6.6.6.0 255.255.255.0 null 0
R4(config)#router bgp 65200
R4(config-router)#redistribute static

回到 R1 看 BGP Table,Origin 变成 ?,但由于 R4 的设置改变了 AS Path,我们必需 Prepend AS Path,来证明在 AS Path 长度相同的情况下,BGP 比较喜欢 i 多于 ? 。Prepend AS Path 的办法在上一部份已说明过了,在此不重复描述。R1

1
2
3
4
5
6
7
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*>i6.6.6.0/24 192.168.12.2 0 500 1000 65200 ?
* i 192.168.13.3 0 500 1000 65100 65300 i

Prepend 好 AS Path 之后,两条 Route AS Path 长度一样,BGP Table 果然选了 Origin i 的第二条作为 Best Path。R1

1
2
3
4
5
6
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
* i6.6.6.0/24 192.168.12.2 0 500 1000 65200 65200 ? *>i 192.168.13.3 0 500 1000 65100 65300 i

MED (选较小的)

故事尚未完结,如果去到 Origin Type 也相同,下一个要比较的就是 MED (Metric)。MED 就像 IGP 里的 Metric,是一个可以传到另一个 AS 的 Attribute,Metric 较少的 Route 会被选为 Best Path。

不过要注意的是,MED 必需要在 AS Path 中第一个 AS Number 相同的时候才会作出比较,除非使用了 bgp always compare MED,则不设此限。

为了做这个测试,我们在下图的 Topology 中把 AS 65200 改成 65100。

另外还故意把 Weight, LocPrf, AS Path, Origin 都设置成相同的值,现时使用第一条 Route 作为 Best Path,如果把第一条 Route 的 Metric 增大,理论上它就会失去 Best Path 了。R1

1
2
3
4
5
6
7
R1#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*>i6.6.6.0/24 192.168.12.2 0 500 1000 65100 65300 i
* i 192.168.13.3 0 500 1000 65100 65300 i

尝试在 R4 用 Route Map 把 Metric 增加至 100,看看 Best Path 是否会发生改变。R4

1
2
3
4
5
6
7
8
9
R4(config)#router bgp 65100
R4(config-router)#neighbor 192.168.24.2 route-map TuningMetric out
R4(config-router)#exit
R4(config)#ip prefix-list MatchNetwork seq 5 permit 6.6.6.0/24
R4(config)#route-map TuningAsPath permit 10
R4(config-route-map)#match ip address prefix-list MatchNetwork
R4(config-route-map)#set metric 100
R4(config-route-map)#end
R4#clear ip bgp *

由于第二条 Route Metric 比较小,现在成为了 Best Path。

值得留意的是,这个 AS 当中的 R2 和 R3 的 Metric 同样改变了,因为 Metric 是传到整个 AS 当中的。R1

1
2
3
4
5
6
7
R1#sh ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
* i6.6.6.0/24 192.168.12.2 100 500 1000 65100 65300 i
*>i 192.168.13.3 0 500 1000 65100 65300 i

R2

1
2
3
4
5
6
7
R2#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*> 6.6.6.0/24 192.168.24.4 100 500 0 65100 65300 i
* i 192.168.13.3 0 500 0 65100 65300 i

R3

1
2
3
4
5
6
7
R3#show ip bgp

<Output Omitted>

Network Next Hop Metric LocPrf Weight Path
*> 6.6.6.0/24 192.168.35.5 0 65100 65300 i
* i 192.168.12.2 100 500 0 65100 65300 i

预设情况下,如 Route 没有提供 MED 值则设为 0,如使用 bgp bestpath med missing-as-worst 则预设值改为最大值,即 4, 294, 967, 294。

eBGP vs iBGP

如果以上全部相同,eBGP 的路径会优于 iBGP。就算 Best Path 在这个阶段被选出,BGP 仍会跳到 9. Multipath 检查是否需要做 Load Sharing。由此可见,如果希望做 Multipath 设置,之前所比较的 1-6 项 Attribute 必需全部相同。

Next-hop 的 IGP Metric (选较小的)

如此时未能选出 best path,则比较到达 Next-hop 的 IGP Metric,较小的胜出。就算 Best Path 在这个阶段被选出,BGP 仍会跳到 9. Multipath 检查是否需要做 Load Sharing。

Multipath

BGP 所支缓的是 Unbalanced Load Sharing,即可以参考 Interface 的 Bandwidth 设置去分配 Traffic。

现在使用以下网络作例子,进行 Multipath 设置。

R5 一共有 3 条 Path 到达 172.16.4.0/24。在预设情况下,Multipath 设置值为 1,即不会进行 Load Balancing。R5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
R5#show ip protocols
*** IP Routing is NSF aware ***

Routing Protocol is “bgp 65125”
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
IGP synchronization is disabled
Automatic route summarization is disabled
Neighbor(s):
Address FiltIn FiltOut DistIn DistOut Weight RouteMap
192.168.15.1
192.168.25.2
192.168.35.3
Maximum path: 1
Routing Information Sources:
Gateway Distance Last Update
192.168.35.3 20 00:02:10
Distance: external 20 internal 200 local 200

所以根据概率程序选了 Next-hop 192.168.25.2 为 Best Path。R5

1
2
3
4
5
6
7
8
9
10
11
12
R5#show ip bgp
BGP table version is 5, local router ID is 192.168.35.5
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not found

Network Next Hop Metric LocPrf Weight Path
* 172.16.4.0/24 192.168.35.3 0 65001 i
* 192.168.15.1 0 65001 i
*> 192.168.25.2 0 65001 i

现在把 Maximum Path 加至 3。R5

1
2
R5(config)#router bgp 65005
R5(config-router)#maximum-paths 3

于是所有 3 条 BGP Route 也入选成为 Multipath,留意一下,Best Path 仍然存在,Router 只会把 Best Path 发布给其他 Neighbor。R5

1
2
3
4
5
6
7
8
9
10
11
12
R5#show ip bgp
BGP table version is 6, local router ID is 192.168.35.5
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not found

Network Next Hop Metric LocPrf Weight Path
*m 172.16.4.0/24 192.168.35.3 0 65001 i
*m 192.168.15.1 0 65001 i
*> 192.168.25.2 0 65001 i

用 show ip route 可以查看现时的 Traffic 分布,可见现时分布是 1:1:1。R5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
R5#show ip route 172.16.4.0
Routing entry for 172.16.4.0/24
Known via “bgp 65005”, distance 20, metric 0
Tag 65001, type external
Last update from 192.168.25.2 00:05:20 ago
Routing Descriptor Blocks:
* 192.168.35.3, from 192.168.35.3, 00:05:20 ago
Route metric is 0, traffic share count is 1
AS Hops 1
Route tag 65001
MPLS label: none
192.168.25.2, from 192.168.25.2, 00:05:20 ago
Route metric is 0, traffic share count is 1
AS Hops 1
Route tag 65001
MPLS label: none
192.168.15.1, from 192.168.15.1, 00:05:20 ago
Route metric is 0, traffic share count is 1
AS Hops 1
Route tag 65001
MPLS label: none

由于 R5 → R3 这条 Path 速度较慢,平均分布 Traffic 并非是个好办法。我们可以用 bgp dmzlink-bw 要求 BGP 按照 Interface 的 Bandwidth 去分配 Traffic。R5

1
2
3
4
R5(config-router)#bgp dmzlink-bw
R5(config-router)#neighbor 192.168.15.1 dmzlink-bw
R5(config-router)#neighbor 192.168.25.2 dmzlink-bw
R5(config-router)#neighbor 192.168.35.3 dmzlink-bw

新的 Traffic 分布为 37:240:240。R5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
R5#show ip route 172.16.4.0
Routing entry for 172.16.4.0/24
Known via “bgp 65005”, distance 20, metric 0
Tag 65001, type external
Last update from 192.168.25.2 00:00:19 ago
Routing Descriptor Blocks:
* 192.168.35.3, from 192.168.35.3, 00:00:19 ago
Route metric is 0, traffic share count is 37
AS Hops 1
Route tag 65001
MPLS label: none
192.168.25.2, from 192.168.25.2, 00:00:19 ago
Route metric is 0, traffic share count is 240
AS Hops 1
Route tag 65001
MPLS label: none
192.168.15.1, from 192.168.15.1, 00:00:19 ago
Route metric is 0, traffic share count is 240
AS Hops 1
Route tag 65001
MPLS label: none

以上只是部份比较常用的 Best Path 机制,如果希望了解到更多,你可以到 这里 查看更详细的教学。

Community

Community 是一个 BGP 的 Attribute,作用就好像在发布的 Prefix 上加一个 Label,当其他 BGP Router 收到这条 Prefix 时,就可以检测这个 Label 的值来做某些动作,我们用以下的网络做一个实验:

假设所有 IP 和 BGP 都已经设置好,R1 把 1.1.1.0/24 发布出去,我们先看看 R2 的 BGP Table 里关于 1.1.1.0 Prefix 的资料:R2

1
2
3
4
5
6
7
R2#show ip bgp 1.1.1.0
BGP routing table entry for 1.1.1.0/24, version 2
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Not advertised to any peer
65000
192.168.12.1 from 192.168.12.1 (192.168.12.1)
Origin IGP, metric 0, localpref 100, valid, external, best

现在我们尝试在 R1 发布 1.1.1.0 时贴上一个 Community,可以用 Route Map 简单完成,但要留意的是,BGP 预设是不会传输 Community 这个 Attribute,需要用 neighbor [IP] send-community 这个指令去启动。R1

1
2
3
4
5
6
7
8
9
10
11
12
13
hostname R1
!
router bgp 65000
network 1.1.1.0 mask 255.255.255.0
neighbor 192.168.12.2 remote-as 65001
neighbor 192.168.12.2 send-community
neighbor 192.168.12.2 route-map SetComm out
!
access-list 1 permit 1.1.1.0 0.0.0.255
!
route-map SetComm permit 10
match ip address 1
set community 1000

现在看看 R2 的 Prefix 1.1.1.0,发现多了一行 Community 显示值为 1000。R2

1
2
3
4
5
6
7
8
9
R2#show ip bgp 1.1.1.0
BGP routing table entry for 1.1.1.0/24, version 2
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
Not advertised to any peer
65000
192.168.12.1 from 192.168.12.1 (192.168.12.1)
Origin IGP, metric 0, localpref 100, valid, external, best
Community: 1000

于是,我们就可以在 R2 使用 Community List 和 Route Map 配合一起做些事情。

例如我们想把 Community 是 1000 的 prefix 的 Local Preference 改成 500。R2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
hostname R2
!
router bgp 65001
neighbor 192.168.12.1 remote-as 65000
neighbor 192.168.12.1 route-map SetLocal in
no auto-summary
!
ip community-list 1 permit 1000
!
route-map SetLocal permit 10
match community 1
set local-preference 500
R2#show ip bgp
BGP table version is 2, local router ID is 192.168.12.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
*> 1.1.1.0/24 192.168.12.1 0 500 0 65000 i

另外,利用 Community 也能做一些 Route Filtering 的动作。

Community 的值除了可以自己设置外,其实系统有 4 个预设值可以使用,分别是:no-advertiselocal-ASno-export 和 internet,4 个预设值的作用如下:

Keywords功能
no-advertise告诉收到这条 Prefix 的 Router 不要将这条 Prefix 发布出去
local-AS告诉收到这条 Prefix 的 Router 这条 Prefix 只能发布给 Confederation 中的同一个 AS
no-export告诉收到这条 Prefix 的 Router 不要将这条 Router 发布给其他 AS
internet告诉收到这条 Prefix 的 Router 这条 Prefix 可以自由发布

现在用以下网络来测试不同的 Community。

首先在 R1 用 Route Map 设置好不同 Prefix 的 Community。R1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
hostname R1
!
router bgp 10
bgp confederation identifier 65000
bgp confederation peers 20
network 1.1.1.0 mask 255.255.255.0
network 2.2.2.0 mask 255.255.255.0
network 3.3.3.0 mask 255.255.255.0
network 4.4.4.0 mask 255.255.255.0
neighbor 192.168.12.2 remote-as 10
neighbor 192.168.12.2 send-community
neighbor 192.168.12.2 route-map TuneComm out
!
access-list 1 permit 1.1.1.0 0.0.0.255
access-list 2 permit 2.2.2.0 0.0.0.255
access-list 3 permit 3.3.3.0 0.0.0.255
access-list 4 permit 4.4.4.0 0.0.0.255
!
route-map TuneComm permit 10
match ip address 1
set community no-advertise
!
route-map TuneComm permit 20
match ip address 2
set community local-AS
!
route-map TuneComm permit 30
match ip address 3
set community no-export
!
route-map TuneComm permit 40
match ip address 4
set community internet

到 R2 看看各 Prefix 的 Community:R2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
R2#show ip bgp 1.1.1.0
BGP routing table entry for 1.1.1.0/24, version 2
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to any peer)
Not advertised to any peer
Local, (Received from a RR-client)
192.168.12.1 from 192.168.12.1 (4.4.4.4)
Origin IGP, metric 0, localpref 100, valid, confed-internal, best
Community: no-advertise
R2#show ip bgp 2.2.2.0
BGP routing table entry for 2.2.2.0/24, version 3
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised outside local AS)
Advertised to update-groups:
1
Local, (Received from a RR-client)
192.168.12.1 from 192.168.12.1 (4.4.4.4)
Origin IGP, metric 0, localpref 100, valid, confed-internal, best
Community: local-AS
R2#show ip bgp 3.3.3.0
BGP routing table entry for 3.3.3.0/24, version 4
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to EBGP peer)
Advertised to update-groups:
1
Local, (Received from a RR-client)
192.168.12.1 from 192.168.12.1 (4.4.4.4)
Origin IGP, metric 0, localpref 100, valid, confed-internal, best
Community: no-export
R2#show ip bgp 4.4.4.0
BGP routing table entry for 4.4.4.0/24, version 5
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Advertised to update-groups:
1
Local, (Received from a RR-client)
192.168.12.1 from 192.168.12.1 (4.4.4.4)
Origin IGP, metric 0, localpref 100, valid, confed-internal, best
Community: internet

在 R3 查看 BGP Table,发现没有收到 1.1.1.0/24,因为 R2 看见这条 Prefix 是 no-advertise 因此不发给 R3。R3

1
2
3
4
5
6
7
8
9
10
R3#show ip bgp
BGP table version is 4, local router ID is 192.168.34.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
*>i2.2.2.0/24 192.168.12.1 0 100 0 i
*>i3.3.3.0/24 192.168.12.1 0 100 0 i
*>i4.4.4.0/24 192.168.12.1 0 100 0 i

在 R4 查看 BGP Table,发现没有收到 2.​​2.2.0/24,因为 R3 看见 Prefix 的 Community 是 local-AS,这条 Prefix 只能存在于 Confederation 的 Local AS 之中,R4 位于另一个 AS,因此 R3 不把这条 Prefix 发出去。R4

1
2
3
4
5
6
7
8
9
R4#show ip bgp
BGP table version is 3, local router ID is 192.168.45.4
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
*> 3.3.3.0/24 192.168.34.3 0 100 0 (10) i
*> 4.4.4.0/24 192.168.34.3 0 100 0 (10) i

最后,在 R5 不会看到 3.3.3.0/24,因为这条 Prefix 的 Community 是 no-export,因此 R4 不会发给位于其他 AS 之内的 R5。至于 4.4.4.0/24 的 Community 是 internet 则没有此限制。R5

1
2
3
4
5
6
7
8
R5#show ip bgp
BGP table version is 2, local router ID is 192.168.45.5
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.4.4.0/24 192.168.45.4 0 65000 i

Aggregate Address

所有 Routing Protocol 都提供 Summary 功能。在 BGP 里面称为 Aggregate Address,意思就是把多条 Route 组合成一条来发布。由于每条 BGP Route 都涉及不同 Attribute 值,令 BGP 的 Summery Address 发布变得复杂。

现在使用以下网络作例子,R3 发布 10.0.0.0/24 及 10.0.1.0/24,R1 及 R2 都收到这两条 Route。

aggregate-address 指令可以发布 Summary,大前题是负责发布的 Router 的 BGP Table 必需拥有此 Summary 内的最少一个 Subnet,不能无中生有。如在 R2 执行 aggregate-address,R1 就会收到 Summary Route。R2

1
2
R2(config)#router bgp 65012
R2(config-router)#aggregate-address 10.0.0.0 255.255.254.0

R1

1
2
3
4
5
6
7
8
9
10
11
12
R1#show ip bgp
BGP table version is 8, local router ID is 192.168.12.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not found

Network Next Hop Metric LocPrf Weight Path
*>i 10.0.0.0/24 192.168.12.2 0 100 0 65023 1000 2000 i
*>i 10.0.0.0/23 192.168.12.2 0 100 0 i
*>i 10.0.1.0/24 192.168.12.2 0 100 0 65023 2000 4000 i

在 R1 的 BGP Table 中,除了 /23 Summary Route 外,仍然收到 /24 Route,如果想要 R1 只收 /23 Summary Route,可在 aggregate-address 加上 summary-only 选项。R2

1
2
R2(config)#router bgp 65012
R2(config-router)#aggregate-address 10.0.0.0 255.255.254.0 summary-only

R1

1
2
3
4
5
6
7
8
9
10
R1#show ip bgp
BGP table version is 8, local router ID is 192.168.12.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not found

Network Next Hop Metric LocPrf Weight Path
*>i 10.0.0.0/23 192.168.12.2 0 100 0 i

如果想要保留部份 Route,可用 suppress-map,使用方法如下。R2

1
2
3
4
5
6
R2(config-router)#router bgp 65012
R2(config-router)#aggregate-address 10.0.0.0 255.255.254.0 as-set summary-only suppress-map SUPP
R2(config-router)#exit
R2(config)#ip prefix-list P1 seq 5 permit 10.0.0.0/24
R2(config)#route-map SUPP permit 10
R2(config-route-map)#match ip address prefix-list P1

R1

1
2
3
4
5
6
7
8
9
10
11
R1#show ip bgp
BGP table version is 8, local router ID is 192.168.12.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not found

Network Next Hop Metric LocPrf Weight Path
*>i 10.0.0.0/23 192.168.12.2 0 100 0 i
*>i 10.0.1.0/24 192.168.12.2 0 100 0

留意 Summary Route 失去了 AS Path 信息,AS Path 是防止 Route Loop 的机制,建议在 aggregate-address 增加 as-set 选项保留 AS Path 信息。R2

1
2
R2(config)#router bgp 65012
R2(config-router)#aggregate-address 10.0.0.0 255.255.254.0 summary-only as-set

R1

1
2
3
4
5
6
7
8
9
10
R1#show ip bgp
BGP table version is 15, local router ID is 192.168.12.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not found

Network Next Hop Metric LocPrf Weight Path
*>i 10.0.0.0/23 192.168.12.2 0 100 0 {65023,1000,3000,2000,4000} i

留意 as-set 除了保留 AS Path 信息,也帮 Summary Route 继承了所有 Community 属性。R1

1
2
3
4
5
6
7
8
9
10
R1#show ip bgp 10.0.0.0/23
BGP routing table entry for 10.0.0.0/23, version 25
Paths: (1 available, best #1, table default, not advertised to EBGP peer)
Not advertised to any peer
Refresh Epoch 2
{65023,1000,3000,2000,4000}, (aggregated by 65012 192.168.23.2)
192.168.12.2 from 192.168.12.2 (192.168.23.2)
Origin IGP, metric 0, localpref 100, valid, internal, best
Community: no-export local-AS
rx pathid: 0, tx pathid: 0x0

如果不想继承所有 Community 属性,可以使用 advertise-map 去帮 Summary Route 选择继承那一条 Route 的属性。R2

1
2
3
4
5
6
R2(config)#router bgp 65012
R2(config-router)#aggregate-address 10.0.0.0 255.255.254.0 as-set advertise-map ADV
R2(config-router)#exit
R2(config)#ip prefix-list P1 seq 5 permit 10.0.0.0/24
R2(config)#route-map ADV permit 10
R2(config-route-map)#match ip address prefix-list P1

也可以使用 attribute-map 直接去改变 Summary Route 的属性。R2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
R2(config)#router bgp 65012
R2(config-router)#aggregate-address 10.0.0.0 255.255.254.0 as-set attribute-map ATTR
R2(config-router)#exit
R2(config)#route-map ATTR permit 10
R2(config-route-map)#set metric 9999
R2(config-route-map)#set local-preference 999
R2(config-route-map)#set community internet
R1#show ip bgp 10.0.0.0/23
BGP routing table entry for 10.0.0.0/23, version 10
Paths: (1 available, best #1, table default)
Not advertised to any peer
Refresh Epoch 1
{65023,1000,3000,2000,4000}, (aggregated by 65012 192.168.23.2)
192.168.12.2 from 192.168.12.2 (192.168.23.2)
Origin IGP, metric 9999, localpref 999, valid, internal, best
Community: internet
rx pathid: 0, tx pathid: 0x0

用 GNS3 测试 advertise-map 和 attribute-map 时需要 clear ip bgp * 才能生效,还不知道这是不是个 bug。

Route Injection

Aggregate address 可以把 Route 组合成 Summary Route,Route Injection 刚好相反,可把 Summary 拆散成不同的 Route。但 Route Injection 设置比较严谨,必需用 exist-map 确定 Summary Route 存在而且来自附合的 Source Address。以下例子把 10.0.0.0/24 拆成 10.0.0.0/25 和 10.0.0.128/25

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
router bgp 60512
bgp inject-map INJECT exist-map EXIST
!
ip prefix-list P24 permit 10.0.0.0/24
!
ip prefix-list P25 permit 10.0.0.0/25
ip prefix-list P25 permit 10.0.0.128/25
!
ip prefix-list PSOURCE permit 192.168.23.3/32
!
route-map EXTIST permit 10 // Exist-map 必需包含以下兩個 Match
match ip address prefix-list P24 // 要分拆解的 Summary Route
match ip route-source prefix-list PSOURCE // 由誰發佈這 Summary Route
!
route-map INJECT permit 10
set ip address prefix-list P25 // 要分拆成這些 Route,緊記這裡是 Set 不是 Match

Backdoor

先说好这个 Backdoor 可不是你所想的那个后门程序哦(

Backdoor 的概念其实十分容易理解,请看以下这个网络。网络同时存在 EIGRP 和 BGP,假设 R2 把 2.2.2.0/24 通过 EIGRP 和 BGP 发布。

由于 R1 同时执行了 EIGRP 和 BGP,它会分别收到 BGP 传来的 2.2.2.0/24 和 EIGRP 传来的 2.2.2.0/24,由于 EGIRP 的 AD 是 90,而 BGP 的 AD 是 20 (这是 EBGP),因此 R1 会选择 R1→R3→R2 的路径到达 R2,这显然不是最佳的路径。R1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
R1#show ip bgp
BGP table version is 6, 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
r> 2.2.2.0/24 192.168.13.3 0 65001 i

R1#show ip eigrp topology
IP-EIGRP Topology Table for AS(1)/ID(1.1.1.1)

Codes: P – Passive, A – Active, U – Update, Q – Query, R – Reply,
r – reply Status, s – sia Status

P 2.2.2.0/24, 1 successors, FD is 409600
via 192.168.12.2 (409600/128256), Ethernet0/0
P 192.168.12.0/24, 1 successors, FD is 281600
via Connected, Ethernet0/0

R1#show ip route | begin Gateway
Gateway of last resort is not set

C 192.168.12.0/24 is directly connected, Ethernet0/0
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
C 192.168.13.0/24 is directly connected, Ethernet0/1
2.0.0.0/24 is subnetted, 1 subnets
B 2.2.2.0 [20/0] via 192.168.13.3, 00:00:02

要解决这个问题,除了改 AD 之外,我们还可以在 R1 的 BGP 设置 backdoor,告诉 R1 BGP 只用作「后备路径」,这样 R1 便会优先使用 EIGRP 的 Route,设置方法如下:R1

1
2
3
4
5
6
7
8
9
10
11
12
R1(config)#router bgp 65000
R1(config-router)#network 2.2.2.0 mask 255.255.255.0 backdoor
R1(config-router)#end
R1#show ip route | begin Gateway
Gateway of last resort is not set

C 192.168.12.0/24 is directly connected, Ethernet0/0
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
C 192.168.13.0/24 is directly connected, Ethernet0/1
2.0.0.0/24 is subnetted, 1 subnets
D 2.2.2.0 [90/409600] via 192.168.12.2, 00:00:22, Ethernet0/0

Dampening

我们都知道一个 BGP Update 可以改变世界!(BGP 赛高!)然而由于 Route 不稳定而产生的 Update 可能会影响全球网络上其他 BGP Router 的路径选择。

Dampening 设置可以容忍 Route 在短时间内的迅速改变从而减少不必要的 BGP Update,要了解 Dampening,请先用 bgp dampeing 启动 Dampering,然后用 show ip bgp dampening parameters 看看预设的参数。R1

1
2
3
4
5
6
7
8
9
R1(config)#router bgp 65001
R1(config-router)#bgp dampening
R1(config-router)#exit
R1#show ip bgp dampening parameters

dampening 15 750 2000 60 (DEFAULT)
Half-life time : 15 mins Decay Time : 2320 secs
Max suppress penalty: 12000 Max suppress time: 60 mins
Suppress penalty : 2000 Reuse penalty : 750

现在解释一下每一个参数的意思:

  • Suppress Penalty
    话说 Dampening 设置一旦被启动后,Route 的状态改变会让该 Route 的 Penalty 值提升,Update/Withdraw 会让 Penalty 值增加 1000,而 Attribute 改变则会增加 500。如 Route 的 Penalty 值大于 Suppress Penalty 值则会触发 Suppress,即 BGP Router 认为此 Route 不稳定暂时不会发布给其他 Router。
  • Max Suppress Penalty
    然而 Penalty 值并不会无限量增加下去,Max Suppress Penalty 为 Penalty 的最大值,预设为 12000。
  • Half-life Time
    Route 的 Penalty 值又会随着时间慢慢下调,预设每 15 分钟就会减去一半。由此可见,如 Route 开始稳定而没有再发生状态改变,Penalty 值必然慢慢减少。
  • Reuse Penalty
    当 Penalty 值减至小于 Reuse Penalty,BGP Router 觉得这条 Route 终于稳定下来了,又会开始向外发布这条 Route。
  • Max Suppress Time
    Max Suppress Time 是一条 Route 被 Suppress 的最长时间,预设为 60 分钟。即是说 Route 由被 Suppress 开始算起如果过了 60 分钟,无论 Penalty 是多少都必需被释放。

我们可以使用以下指令改变 Dampening 的几个参数:

bgp dampening [Half-life] [Reuse Penalty] [Suppress Penalty] [Max Suppress Time]

其中,Max Suppress Penalty 会被自动计算出来。R1

1
2
3
4
5
6
7
8
9
R1(config)#router bgp 65001
R1(config-router)#bgp dampening 10 1000 2000 30
R1(config-router)#exit
R1#show ip bgp dampening parameters

dampening 10 1000 2000 30
Half-life time : 10 mins Decay Time : 1200 secs
Max suppress penalty: 8000 Max suppress time: 30 mins
Suppress penalty : 2000 Reuse penalty : 1000

Author: Jason CooperLink: https://blog.dwx.io/about-bgp/Copyright Notice: All articles in this blog are licensed under BSD 3-Clause “New” or “Revised” License unless stating additionally.ISPPeerNetworkBGP

咱很菜的,是个智障。 人设非常容易崩。
上一篇

迫真分布式设计-狐思乱想

下一篇

【意呆利临期灵车】意盟KIMBO意式浓缩金牌豆

你也可能喜欢

4 条评论

  1. 博主的博客配色很卡哇伊,但是居然是技术达人啊,O(∩_∩)O哈哈~

  2. 好耶,是大佬

回复 VPS234主机测评 取消回复

您的电子邮件地址不会被公开。 必填项已用 * 标注

提示:点击验证后方可评论!

插入图片
返回顶部