通过此篇可以了解EBGP邻居关系的建立以及了解wireark对EBGP邻居报文的分析。

默认情况下,eBGP(外部 BGP)需要两台路由器相互直接连接,以建立邻居邻接关系,这是因为 eBGP 路由器对其 BGP 数据包使用的TTL 为 1,当 BGP 邻居超过一跳时,TTL 将递减为 0 并被丢弃。

当这两个路由器没有直接连接时,仍然可以使其工作,但必须使用multihop,此情形不适用于iBGP。

下面是一个例子:

ebgp多跳是什么意思 ebgp多跳配置_路由器

上面我们将尝试在 R1 和 R3 之间配置 eBGP,由于 R2 位于中间,这些路由器彼此相距不止一跳。我们来看看配置:

R1(config)#ip route 192.168.23.3 255.255.255.255 192.168.12.2
R3(config)#ip route 192.168.12.1 255.255.255.255 192.168.23.2
首先,创建一些静态路由,以便 R1 和 R3 能够相互访问,现在可以配置 eBGP:
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.23.3 remote-as 3
R3(config)#router bgp 3
R3(config-router)#neighbor 192.168.12.1 remote-as 1
即使此配置正确,BGP 仍然不会尝试建立 eBGP 邻居邻接关系,BGP 知道,由于这些路由器位于不同的子网上,因此它们没有直接连接,我们可以使用以下命令验证这一点:
R1#show ip bgp neighbors | include External
  External BGP neighbor not directly connected.
R3#show ip bgp neighbors | include External
  External BGP neighbor not directly connected.
以下命令仅仅为了测试,让我们禁用此检查,以便 R1 和 R3 尝试成为 eBGP 邻居,我们可以这样做:
R1(config-router)#neighbor 192.168.23.3 disable-connected-check
R3(config-router)#neighbor 192.168.12.1 disable-connected-check

路由器现在将尝试成为 eBGP 邻居,即使它们没有直接连接,看看将发生的事情:

ebgp多跳是什么意思 ebgp多跳配置_ebgp多跳是什么意思_02

上面的wireshark 捕获显示我们R1 正在尝试连接到R3。如您所见,TTL 为 1,一旦 R2 收到此数据包,它会将 TTL 减 1 并将其丢弃:

ebgp多跳是什么意思 ebgp多跳配置_R3_03

你可以看到 R2 正在丢弃这个数据包,因为超过了 TTL,它将向 R1 发送一个 ICMP 生存时间超时消息, BGP 路由器将显示如下消息:

R1#
BGP: 192.168.23.3 open failed: Connection timed out; remote host not responding, open active delayed 27593ms (35000ms max, 28% jitter)
这是 R1 告诉我们它无法连接到 R3,为了解决这个问题,我们会告诉 eBGP 增加 TTL,首先让我们再次启用直连检查:
R1(config-router)#no neighbor 192.168.23.3 disable-connected-check
R3(config-router)#no neighbor 192.168.12.1 disable-connected-check
现在我们将增加 TTL:
R1(config-router)#neighbor 192.168.23.3 ebgp-multihop 2
R3(config-router)#neighbor 192.168.12.1 ebgp-multihop 2
使用ebgp-multihop命令增加 TTL,在示例中,使用值 2 就足够了,R2 将收到一个 TTL 为 2 的数据包,将其减 1 并将其转发给 R3,我们可以通过查看 show ip bgp neighbor 命令来验证此更改:
R1 & R3
#show ip bgp neighbors | include External
  External BGP neighbor may be up to 2 hops away.

R1 和 R3 都同意 BGP 邻居可能在 2 跳之外,这是 BGP 数据包在wireshark中的样子:

ebgp多跳是什么意思 ebgp多跳配置_R3_04

此捕获向我们显示 了TTL 为 2,几秒钟后,路由器将成为 eBGP 邻居:

R1#
%BGP-5-ADJCHANGE: neighbor 192.168.23.3 Up
R3#
%BGP-5-ADJCHANGE: neighbor 192.168.12.1 Up
就这样,问题解决了!
如下为R1,R2,R3的配置:
hostname R1
!
interface fastEthernet0/0
 ip address 192.168.12.1 255.255.255.0
!
ip route 192.168.23.3 255.255.255.255 192.168.12.2
!
router bgp 1
 neighbor 192.168.23.3 remote-as 3
 neighbor 192.168.23.3 ebgp-multihop 2
!
End
hostname R2
!
interface fastEthernet0/0
 ip address 192.168.12.2 255.255.255.0
!
interface fastEthernet1/0
 ip address 192.168.23.2 255.255.255.0
!
end
hostname R3
!
interface fastEthernet0/0
 ip address 192.168.23.3 255.255.255.0
!
ip route 192.168.12.1 255.255.255.255 192.168.23.2
!
router bgp 3
 neighbor 192.168.12.1 remote-as 1
 neighbor 192.168.12.1 ebgp-multihop 2
!
end

即使 R1 和 R3 现在是邻居,在 R1 和 R3 之间的路由器中使用非 BGP 也不是一个好的方法,R1 和 R3 可能会通过 BGP 交换前缀,但是一旦数据包到达 R2,它将不知道将这些数据包转发到哪里......

现在你应该了解了 eBGP 多跳的工作原理,让我们来看一个更有用的场景:

ebgp多跳是什么意思 ebgp多跳配置_bgp_05

上面两个路由器……R1 和 R2,它们是直接连接的,但它们之间有两个链接,我们希望将它们用于负载均衡,我们将使用环回接口上的 IP 地址,而不是将这些 FastEthernet 接口上的 IP 地址用于 eBGP 邻居邻接。我们来看看配置:

R1(config)#ip route 2.2.2.0 255.255.255.0 192.168.12.2

R1(config)#ip route 2.2.2.0 255.255.255.0 192.168.21.2

R2(config)#ip route 1.1.1.0 255.255.255.0 192.168.12.1

R2(config)#ip route 1.1.1.0 255.255.255.0 192.168.21.1

在每个路由器上,我们将配置两条静态路由,这允许我们使用负载平衡来到达环回接口,现在我们可以配置 eBGP:

R1(config)#router bgp 1

R1(config-router)#neighbor 2.2.2.2 remote-as 2

R1(config-router)#neighbor 2.2.2.2 update-source loopback 0

R1(config-router)#neighbor 2.2.2.2 ebgp-multihop 2

R2(config)#router bgp 2

R2(config-router)#neighbor 1.1.1.1 remote-as 1

R2(config-router)#neighbor 1.1.1.1 update-source loopback 0

R2(config-router)#neighbor 1.1.1.1 ebgp-multihop 2

除了使用 ebgp-multihop 命令将 TTL 配置为 2 之外,我们还必须使用update-source命令告诉路由器使用其环回接口上的 IP 地址作为 eBGP 邻居邻接的源 IP 地址,几秒钟后,这些路由器将成为邻居:

R1#

%BGP-5-ADJCHANGE: neighbor 2.2.2.2 Up

R2#

%BGP-5-ADJCHANGE: neighbor 1.1.1.1 Up

由于我们的静态路由,我们将在两个路由器之间使用负载平衡:

R1#show ip route static

     2.0.0.0/24 is subnetted, 1 subnets

S       2.2.2.0 [1/0] via 192.168.21.2

                [1/0] via 192.168.12.2

R2#show ip route static

     1.0.0.0/24 is subnetted, 1 subnets

S       1.1.1.0 [1/0] via 192.168.21.1

                [1/0] via 192.168.12.1

END!