🔹类型:外部网关协议 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 (边界网关协议) - 图1

交换机 BGP 配置

EBGP 拓扑

image.png

image.png
**

  1. 配置 Router A
  2. -----------------------------------------------------------------------------------------
  3. Switch# configure terminal 进入配置模式
  4. Switch(config)# interface eth-0-13 进入接口模式
  5. Switch(config-if)# no shutdown 启用端口
  6. Switch(config-if)# no switchport 将该端口转换为三层interface
  7. Switch(config-if)# ip address 1.1.1.1/24 配置IP 地址为1.1.1.1/24
  8. Switch(config-if)# exit 退出接口模式并且进入配置模式
  9. Switch(config)# interface eth-0-1 进入接口模式
  10. Switch(config-if)# no shutdown 启用端口
  11. Switch(config-if)# no switchport 将该端口转换为三层interface
  12. Switch(config-if)# ip address 2.2.2.1/24 配置IP 地址为2.2.2.1/24
  13. Switch(config-if)# exit 退出接口模式并且进入配置模式
  14. Switch(config)# ip route 3.3.3.0/24 2.2.2.2 增加一条静态路由
  15. Switch(config)# router bgp 100 创建BGP 100 并进入路由模式
  16. Switch(config-router)# bgp router-id 10.10.10.10 配置BGP router-id
  17. Switch(config-router)# neighbor 1.1.1.2 remote-as 200 配置EBGP 邻居号200
  18. Switch(config)# neighbor 1.1.1.2 ebgp-multihop 配置邻居为ebgp-multihop
  19. Switch(config-router)# network 4.0.0.0/8 宣告网络号
  20. Switch(config-router)# redistribute static 重分布静态路由到BGP
  21. Switch(config-router)# redistribute connected 重分布直连路由到BGP
  22. Switch(config-router)# exit 退出路由模式并且进入配置模式
  23. 配置 Router B
  24. ---------------------------------------------------------------------------------------
  25. Switch# configure terminal 进入配置模式
  26. Switch(config)# interface eth-0-13 进入接口模式
  27. Switch(config-if)# no shutdown 启用端口
  28. Switch(config-if)# no switchport 将该端口转换为三层interface
  29. Switch(config-if)# ip address 1.1.1.2/24 配置IP 地址为1.1.1.2/24
  30. Switch(config-if)# exit 退出接口模式并且进入配置模式
  31. Switch(config)# router bgp 200 创建BGP 200 并进入路由模式
  32. Switch(config-router)# bgp router-id 11.11.11.11 配置BGP router-id
  33. Switch(config-router)# neighbor 1.1.1.1 remote-as 100 配置EBGP 邻居号100
  34. Switch(config)# neighbor 1.1.1.1 ebgp-multihop 配置邻居为ebgp-multihop
  35. Switch(config-router)# redistribute connected 重分布直连路由到BGP
  36. Switch(config-router)# exit 退出路由模式并且进入配置模式
  37. 试验结果
  38. SwitchA# show ip bgp neighbors
  39. -----------------------------------------------------------------------
  40. BGP neighbor is 1.1.1.2, remote AS 200, local AS 100, external link
  41. BGP version 4, remote router ID 0.0.0.0
  42. BGP state = Active
  43. Last read 00:26:00, hold time is 180, keepalive interval is 60 seconds
  44. Received 0 messages, 0 notifications, 0 in queue
  45. Sent 0 messages, 0 notifications, 0 in queue
  46. Route refresh request: received 0, sent 0
  47. Minimum time between advertisement runs is 30 seconds
  48. For address family: IPv4 Unicast
  49. BGP table version 1, neighbor version 0
  50. Index 1, Offset 0, Mask 0x2
  51. 0 accepted prefixes
  52. 0 announced prefixes
  53. Connections established 0; dropped 0
  54. External BGP neighbor may be up to 255 hops away.
  55. ********Next connect timer due in 87 seconds********
  56. SwitchB# show ip bgp neighbors
  57. ----------------------------------------------------------------------
  58. BGP neighbor is 1.1.1.1, remote AS 100, local AS 200, external link
  59. BGP version 4, remote router ID 0.0.0.0
  60. BGP state = Active
  61. Last read 00:21:39, hold time is 180, keepalive interval is 60 seconds
  62. Received 0 messages, 0 notifications, 0 in queue
  63. Sent 0 messages, 0 notifications, 0 in queue
  64. Route refresh request: received 0, sent 0
  65. Minimum time between advertisement runs is 30 seconds
  66. For address family: IPv4 Unicast
  67. BGP table version 1, neighbor version 0
  68. Index 1, Offset 0, Mask 0x2
  69. 0 accepted prefixes
  70. 0 announced prefixes
  71. Connections established 0; dropped 0
  72. External BGP neighbor may be up to 255 hops away.
  73. Next connect timer due in 97 seconds


IBGP 拓扑

image.png

image.png

  1. 配置 Router A
  2. -----------------------------------------------------------------------------------------
  3. Switch #configure terminal 进入配置模式
  4. Switch (config)# interface eth-0-13 进入接口模式
  5. Switch (config-if)# no shutdown 启用端口
  6. Switch (config-if)# no switchport 将该端口转换为三层interface
  7. Switch (config-if)# ip address 1.1.1.1/24 配置IP 地址为1.1.1.1/24
  8. Switch (config-if)# exit 退出接口模式并且进入配置模式
  9. Switch (config)# interface loopback 0 进入接口模式
  10. Switch (config-if)# ip address 10.10.10.10/32 配置IP 地址为10.10.10.10/32
  11. Switch (config-if)# exit 退出接口模式并且进入配置模式
  12. Switch (config)# ip route 11.11.11.11/32 1.1.1.2 增加一条静态路由
  13. Switch (config)# interface eth-0-1 进入接口模式
  14. Switch (config-if)# no shutdown 启用端
  15. Switch (config-if)# no switchport 将该端口转换为三层interface
  16. Switch (config-if)# ip address 2.2.2.1/24 配置IP 地址为2.2.2.1/24
  17. Switch (config-if)# exit 退出接口模式并且进入配置模式
  18. Switch (config)# ip route 3.3.3.0/24 2.2.2.2 增加一条静态路由
  19. Switch (config)# router bgp 100 创建BGP 100 并进入路由模式
  20. Switch (config-router)# bgp router-id 10.10.10.10 配置BGP router-id
  21. Switch (config-router)# neighbor 11.11.11.11 remote-as 100 配置IBGP 邻居AS 100
  22. Switch (config-router)# neighbor 11.11.11.11 update-source loopback 0 配置loopback0 为更新源端口
  23. Switch (config-router)# network 4.0.0.0/8 宣告网络号
  24. Switch (config-router)# redistribute static 重分布静态路由到BGP
  25. Switch (config-router)# redistribute connected 重分布直连路由到BGP
  26. Switch (config-router)# exit 退出路由模式并且进入配置模式
  27. 配置 Router B
  28. ---------------------------------------------------------------------------------------
  29. Switch #configure terminal 进入配置模式
  30. Switch (config)# interface eth-0-13 进入接口模式
  31. Switch (config-if)# no shutdown 启用端口
  32. Switch (config-if)# no switchport 将该端口转换为三层interface
  33. Switch (config-if)# ip address 1.1.1.2/24 配置IP 地址为1.1.1.2/24
  34. Switch (config-if)# exit 退出接口模式并且进入配置模式
  35. Switch (config)# interface loopback 0 进入接口模式
  36. Switch (config-if)# ip address 11.11.11.11/32 配置IP 地址为11.11.11.11/32
  37. Switch (config-if)# exit 退出接口模式并且进入配置模式
  38. Switch (config)# ip route 10.10.10.10/32 1.1.1.1 增加一条静态路由
  39. Switch (config)# router bgp 100 创建BGP 100 并进入路由模式
  40. Switch (config-router)# bgp router-id 11.11.11.11 配置BGP router-id
  41. Switch (config-router)# neighbor 10.10.10.10 remote-as 100 配置IBGP 邻居AS 100
  42. Switch (config-router)# neighbor 10.10.10.10 update-source loopback 0 配置loopback0 为更新源端口
  43. Switch (config-router)# redistribute connected 重分布直连路由到BGP
  44. Switch (config-router)# exit 退出路由模式并且进入配置模式
  45. 试验结果
  46. SwitchA# show ip bgp neighbors
  47. -----------------------------------------------------------------------
  48. BGP neighbor is 11.11.11.11, remote AS 100, local AS 100, internal link
  49. BGP version 4, remote router ID 0.0.0.0
  50. BGP state = Active
  51. Last read 00:02:32, hold time is 180, keepalive interval is 60 seconds
  52. Received 0 messages, 0 notifications, 0 in queue
  53. Sent 0 messages, 0 notifications, 0 in queue
  54. Route refresh request: received 0, sent 0
  55. Minimum time between advertisement runs is 5 seconds
  56. Update source is loopback0
  57. For address family: IPv4 Unicast
  58. BGP table version 1, neighbor version 0
  59. Index 1, Offset 0, Mask 0x2
  60. 0 accepted prefixes
  61. 0 announced prefixes
  62. Connections established 0; dropped 0
  63. Next connect timer due in 62 seconds
  64. SwitchB# show ip bgp neighbors
  65. ----------------------------------------------------------------------
  66. BGP neighbor is 10.10.10.10, remote AS 100, local AS 100, internal link
  67. BGP version 4, remote router ID 0.0.0.0
  68. BGP state = Active
  69. Last read 00:01:58, hold time is 180, keepalive interval is 60 seconds
  70. Received 0 messages, 0 notifications, 0 in queue
  71. Sent 0 messages, 0 notifications, 0 in queue
  72. Route refresh request: received 0, sent 0
  73. Minimum time between advertisement runs is 5 seconds
  74. Update source is loopback0
  75. For address family: IPv4 Unicast
  76. BGP table version 1, neighbor version 0
  77. Index 1, Offset 0, Mask 0x2
  78. 0 accepted prefixes
  79. 0 announced prefixes
  80. Connections established 0; dropped 0
  81. Next connect timer due in 17 seconds