BGP
建立
BGP 是通过TCP发送的,建立邻居之前要先保证两端能 ping 通
ping -a <source_ip> <destination_ip>
分类
AS 一般是一个独立的机构 (AS号分为公有和私有,公有可以确定一个区域)
同一个 AS:IBGP(RIP, OSPF)
不同 AS:EBGP
- IBGP 默认的 TTL 是 255
- EBGP 默认的 TTL 是 1 ,通过该命令修改
ebgp-max-hop <number>
建立邻居
建立之前保证两端接口能 ping 通
确保建立邻居的两端 源/目的 地址匹配
EBGP 保证 TTL 值足够大
peer <destination_ip> as-number <destination_as_number> # 指定与哪个的路由器建立邻居
peer <destination_ip> connect-interface <local-interface> # 指定本端与对端建立邻居的接口(默认是一个出接口)
配置完成后,一般有 32 秒的 idle 时间,然后才开始建立 TCP 连接
指定与对端建立邻居的接口
peer <destination_ip> connect-interface <local-interface>
目的是为了提高连接的可靠性。将接口指定为本地的 Loopback 接口
BGP 路由表
- 指定路由表中的一条路由:
network <router>
- 和路由策略配合,引入某一类路由:
import <type> route-policy <policy_name>
BGP 通告原则
标识:
* 有效
> 最优
- 仅将最优路由通告给邻居
- 通过 EBGP 获得的路由会发送给所有邻居
- 通过 IBGP 获得的路由不会发送给 IBGP 邻居
实验

步骤一
为所有接口配置 IP 地址
步骤二
为 AS 234 配置OSPF

步骤三
AR1, AR2 通过物理接口 建立EBGP邻居
前提:AR1 能ping通 AR2

配置 BGP:
[R1]bgp 10
[R1-bgp]peer 10.1.12.2 as-number 234
[R2]bgp 234
[R2-bgp]peer 10.1.12.1 as-number 10
验证:

步骤三
AR4 和 AR5 通过 loopback 接口建立邻居
前提:保证loopback接口两端能 ping 通(配置静态路由)
[R4]ip route-static 5.5.5.5 32 10.1.45.5
[R5]ip route-static 4.4.4.4 32 10.1.45.4

配置 BGP
[R4]bgp 234
[R4-bgp]peer 5.5.5.5 as-number 50
[R4-bgp]peer 5.5.5.5 connect-interface LoopBack 0 # 指定与对端建立邻居的接口(默认为一个出接口),指定loopback接口提高可靠性
[R5]bgp 50
[R5-bgp]peer 4.4.4.4 as-number 234
[R5-bgp]peer 4.4.4.4 connect-interface LoopBack 0
配置完成后会发现无法建立邻居;因为 4.4.4.4 --> 5.5.5.5 之间有2跳;而EBGP默认 TTL 为 1

通过在R4接口上抓包可以发现:4.4.4.4 --> 5.5.5.5 的 TTL 的 1,但是它们之间的条数为 2

解决:EBGP 默认 TTL 值 1,可修改
[R4-bgp]peer 5.5.5.5 ebgp-max-hop 2
[R5-bgp]peer 4.4.4.4 ebgp-max-hop 2
验证:


步骤四
AS 234 建立BGP (IBGP)
前提:AR2, AR3, AR3 的 loopback 接口能 Ping 通 (已经配置OSPF)
BGP 配置:
[R2]bgp 234
[R2-bgp]peer 3.3.3.3 as-number 234
[R2-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[R3]bgp 234
[R3-bgp]peer 2.2.2.2 as-number 234
[R3-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[R3-bgp]peer 4.4.4.4 as-number 234
[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[R4]bgp 234
[R4-bgp]peer 3.3.3.3 as-number 234
[R4-bgp]peer 3.3.3.3 connect-interface LoopBack 0
验证:

步骤五
路由通告
[R1]interface LoopBack 1
[R1-LoopBack1]ip address 192.168.1.1 24
[R1-LoopBack1]q
[R1]bgp 10
[R1-bgp]network 192.168.1.1 24


通告规则


[R2]bgp 234
[R2-bgp]peer 3.3.3.3 next-hop-local
[R3]bgp 234
[R3-bgp]peer 4.4.4.4 next-hop-local

通过规则

[R3-bgp]peer 4.4.4.4 reflect-client

BGP 的更新速度很慢,需等待 32 秒左右

AR5
[R5]interface LoopBack 1
[R5-LoopBack1]ip address 192.168.2.1 24
[R5-LoopBack1]quit
[R5]bgp 50
[R5-bgp]network 192.168.2.1 24
[R5-bgp]q
[R3-bgp]peer 2.2.2.2 reflect-client
[R1]ip route-static 0.0.0.0 0.0.0.0 10.1.12.2
[R5]ip route-static 0.0.0.0 0.0.0.0 10.1.45.4
[R2-acl-basic-2000]rule permit source 10.1.12.0 0.0.0.255
[R2-route-policy]if-match acl 2000
[R2-ospf-1]import-route direct route-policy ospf_ar1
[R4-acl-basic-2000]rule permit source 10.1.45.0 0.0.0.255
[R4-route-policy]if-match acl 2000
[R4]ospf
[R4-ospf-1]import-route direct route-policy ospf_ar5

网友评论