🔹类型:外部网关协议 EGP
🔹全称:Border Gateway Protocol
🔹文件:BGP指南-IP单播路由.pdf
🔹视频:BGP基础 - 基本原理
🔹链接:BGP配置
简介
BGP用于在不同的自治系统(AS)之间交换路由信息。当两个AS需要交换路由信息时,每个AS都必须指定一个运行BGP的节点,来代表AS与其他的AS交换路由信息。
BGP属于外部网关路由协议,可以实现自治系统间无环路的域间路由。BGP是沟通Internet广域网的主用路由协议,例如不同省份、不同国家之间的路由大多要依靠BGP协议。BGP可分为 IBGP 和 EBGP。BGP的邻居关系(或称通信对端/对等实体)是通过人工配置实现的,对等实体之间通过TCP会话交互数据。BGP路由器会周期地发送19字节的保持存活keep-alive消息来维护连接。在路由协议中,只有BGP使用TCP作为传输层协议。
IBGP 和 EBGP
- IBGP:同一个自治系统(AS)中的两个或多个对等实体之间运行的BGP被称为 IBGP(Internal/Interior BGP)
- EBGP:归属不同的AS的对等实体之间运行的BGP称为 EBGP (External BGP),用于不同AS间路由信息交换
交换机 BGP 配置
EBGP 拓扑
**
配置 Router A
-----------------------------------------------------------------------------------------
Switch# configure terminal 进入配置模式
Switch(config)# interface eth-0-13 进入接口模式
Switch(config-if)# no shutdown 启用端口
Switch(config-if)# no switchport 将该端口转换为三层interface
Switch(config-if)# ip address 1.1.1.1/24 配置IP 地址为1.1.1.1/24
Switch(config-if)# exit 退出接口模式并且进入配置模式
Switch(config)# interface eth-0-1 进入接口模式
Switch(config-if)# no shutdown 启用端口
Switch(config-if)# no switchport 将该端口转换为三层interface
Switch(config-if)# ip address 2.2.2.1/24 配置IP 地址为2.2.2.1/24
Switch(config-if)# exit 退出接口模式并且进入配置模式
Switch(config)# ip route 3.3.3.0/24 2.2.2.2 增加一条静态路由
Switch(config)# router bgp 100 创建BGP 100 并进入路由模式
Switch(config-router)# bgp router-id 10.10.10.10 配置BGP router-id
Switch(config-router)# neighbor 1.1.1.2 remote-as 200 配置EBGP 邻居号200
Switch(config)# neighbor 1.1.1.2 ebgp-multihop 配置邻居为ebgp-multihop
Switch(config-router)# network 4.0.0.0/8 宣告网络号
Switch(config-router)# redistribute static 重分布静态路由到BGP
Switch(config-router)# redistribute connected 重分布直连路由到BGP
Switch(config-router)# exit 退出路由模式并且进入配置模式
配置 Router B
---------------------------------------------------------------------------------------
Switch# configure terminal 进入配置模式
Switch(config)# interface eth-0-13 进入接口模式
Switch(config-if)# no shutdown 启用端口
Switch(config-if)# no switchport 将该端口转换为三层interface
Switch(config-if)# ip address 1.1.1.2/24 配置IP 地址为1.1.1.2/24
Switch(config-if)# exit 退出接口模式并且进入配置模式
Switch(config)# router bgp 200 创建BGP 200 并进入路由模式
Switch(config-router)# bgp router-id 11.11.11.11 配置BGP router-id
Switch(config-router)# neighbor 1.1.1.1 remote-as 100 配置EBGP 邻居号100
Switch(config)# neighbor 1.1.1.1 ebgp-multihop 配置邻居为ebgp-multihop
Switch(config-router)# redistribute connected 重分布直连路由到BGP
Switch(config-router)# exit 退出路由模式并且进入配置模式
试验结果
SwitchA# show ip bgp neighbors
-----------------------------------------------------------------------
BGP neighbor is 1.1.1.2, remote AS 200, local AS 100, external link
BGP version 4, remote router ID 0.0.0.0
BGP state = Active
Last read 00:26:00, hold time is 180, keepalive interval is 60 seconds
Received 0 messages, 0 notifications, 0 in queue
Sent 0 messages, 0 notifications, 0 in queue
Route refresh request: received 0, sent 0
Minimum time between advertisement runs is 30 seconds
For address family: IPv4 Unicast
BGP table version 1, neighbor version 0
Index 1, Offset 0, Mask 0x2
0 accepted prefixes
0 announced prefixes
Connections established 0; dropped 0
External BGP neighbor may be up to 255 hops away.
********Next connect timer due in 87 seconds********
SwitchB# show ip bgp neighbors
----------------------------------------------------------------------
BGP neighbor is 1.1.1.1, remote AS 100, local AS 200, external link
BGP version 4, remote router ID 0.0.0.0
BGP state = Active
Last read 00:21:39, hold time is 180, keepalive interval is 60 seconds
Received 0 messages, 0 notifications, 0 in queue
Sent 0 messages, 0 notifications, 0 in queue
Route refresh request: received 0, sent 0
Minimum time between advertisement runs is 30 seconds
For address family: IPv4 Unicast
BGP table version 1, neighbor version 0
Index 1, Offset 0, Mask 0x2
0 accepted prefixes
0 announced prefixes
Connections established 0; dropped 0
External BGP neighbor may be up to 255 hops away.
Next connect timer due in 97 seconds
IBGP 拓扑
配置 Router A
-----------------------------------------------------------------------------------------
Switch #configure terminal 进入配置模式
Switch (config)# interface eth-0-13 进入接口模式
Switch (config-if)# no shutdown 启用端口
Switch (config-if)# no switchport 将该端口转换为三层interface
Switch (config-if)# ip address 1.1.1.1/24 配置IP 地址为1.1.1.1/24
Switch (config-if)# exit 退出接口模式并且进入配置模式
Switch (config)# interface loopback 0 进入接口模式
Switch (config-if)# ip address 10.10.10.10/32 配置IP 地址为10.10.10.10/32
Switch (config-if)# exit 退出接口模式并且进入配置模式
Switch (config)# ip route 11.11.11.11/32 1.1.1.2 增加一条静态路由
Switch (config)# interface eth-0-1 进入接口模式
Switch (config-if)# no shutdown 启用端
Switch (config-if)# no switchport 将该端口转换为三层interface
Switch (config-if)# ip address 2.2.2.1/24 配置IP 地址为2.2.2.1/24
Switch (config-if)# exit 退出接口模式并且进入配置模式
Switch (config)# ip route 3.3.3.0/24 2.2.2.2 增加一条静态路由
Switch (config)# router bgp 100 创建BGP 100 并进入路由模式
Switch (config-router)# bgp router-id 10.10.10.10 配置BGP router-id
Switch (config-router)# neighbor 11.11.11.11 remote-as 100 配置IBGP 邻居AS 号100
Switch (config-router)# neighbor 11.11.11.11 update-source loopback 0 配置loopback0 为更新源端口
Switch (config-router)# network 4.0.0.0/8 宣告网络号
Switch (config-router)# redistribute static 重分布静态路由到BGP
Switch (config-router)# redistribute connected 重分布直连路由到BGP
Switch (config-router)# exit 退出路由模式并且进入配置模式
配置 Router B
---------------------------------------------------------------------------------------
Switch #configure terminal 进入配置模式
Switch (config)# interface eth-0-13 进入接口模式
Switch (config-if)# no shutdown 启用端口
Switch (config-if)# no switchport 将该端口转换为三层interface
Switch (config-if)# ip address 1.1.1.2/24 配置IP 地址为1.1.1.2/24
Switch (config-if)# exit 退出接口模式并且进入配置模式
Switch (config)# interface loopback 0 进入接口模式
Switch (config-if)# ip address 11.11.11.11/32 配置IP 地址为11.11.11.11/32
Switch (config-if)# exit 退出接口模式并且进入配置模式
Switch (config)# ip route 10.10.10.10/32 1.1.1.1 增加一条静态路由
Switch (config)# router bgp 100 创建BGP 100 并进入路由模式
Switch (config-router)# bgp router-id 11.11.11.11 配置BGP router-id
Switch (config-router)# neighbor 10.10.10.10 remote-as 100 配置IBGP 邻居AS 号100
Switch (config-router)# neighbor 10.10.10.10 update-source loopback 0 配置loopback0 为更新源端口
Switch (config-router)# redistribute connected 重分布直连路由到BGP
Switch (config-router)# exit 退出路由模式并且进入配置模式
试验结果
SwitchA# show ip bgp neighbors
-----------------------------------------------------------------------
BGP neighbor is 11.11.11.11, remote AS 100, local AS 100, internal link
BGP version 4, remote router ID 0.0.0.0
BGP state = Active
Last read 00:02:32, hold time is 180, keepalive interval is 60 seconds
Received 0 messages, 0 notifications, 0 in queue
Sent 0 messages, 0 notifications, 0 in queue
Route refresh request: received 0, sent 0
Minimum time between advertisement runs is 5 seconds
Update source is loopback0
For address family: IPv4 Unicast
BGP table version 1, neighbor version 0
Index 1, Offset 0, Mask 0x2
0 accepted prefixes
0 announced prefixes
Connections established 0; dropped 0
Next connect timer due in 62 seconds
SwitchB# show ip bgp neighbors
----------------------------------------------------------------------
BGP neighbor is 10.10.10.10, remote AS 100, local AS 100, internal link
BGP version 4, remote router ID 0.0.0.0
BGP state = Active
Last read 00:01:58, hold time is 180, keepalive interval is 60 seconds
Received 0 messages, 0 notifications, 0 in queue
Sent 0 messages, 0 notifications, 0 in queue
Route refresh request: received 0, sent 0
Minimum time between advertisement runs is 5 seconds
Update source is loopback0
For address family: IPv4 Unicast
BGP table version 1, neighbor version 0
Index 1, Offset 0, Mask 0x2
0 accepted prefixes
0 announced prefixes
Connections established 0; dropped 0
Next connect timer due in 17 seconds