服务器 linux 运维 配置BGP的基本示例 - 2 as-number 65009

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力网站平台 👁️ 409 次阅读

目录

BGP简介

BGP定义

配置BGP目的

受益

实验

实验拓扑

​编辑 组网需求

配置思路

配置步骤

配置各接口所属的VLAN

配置各Vlanif的ip地址

配置IBGP连接

配置EBGP

查看BGP对等体的连接状态

配置SwitchA发布路由10.1.0.0/16

配置BGP引入直连路由

BGP简介

BGP定义

边界网关协议BGP(Border Gateway Protocol)是一种实现自治系统AS(Autonomous System)之间的路由可达,并选择最佳路由的距离矢量路由协议。早期发布的三个版本分别是BGP-1(RFC1105)、BGP-2(RFC1163)和BGP-3(RFC1267),1994年开始使用BGP-4(RFC1771),2006年之后单播IPv4网络使用的版本是BGP-4(RFC4271),其他网络(如IPv6等)使用的版本是MP-BGP(RFC4760)。

MP-BGP是对BGP-4进行了扩展,来达到在不同网络中应用的目的,BGP-4原有的消息机制和路由机制并没有改变。MP-BGP在IPv6单播网络上的应用称为BGP4+,在IPv4组播网络上的应用称为MBGP(Multicast BGP)。

配置BGP目的

为方便管理规模不断扩大的网络,网络被分成了不同的自治系统。1982年,外部网关协议EGP(Exterior Gateway Protocol)被用于实现在AS之间动态交换路由信息。但是EGP设计得比较简单,只发布网络可达的路由信息,而不对路由信息进行优选,同时也没有考虑环路避免等问题,很快就无法满足网络管理的要求。

BGP是为取代最初的EGP而设计的另一种外部网关协议。不同于最初的EGP,BGP能够进行路由优选、避免路由环路、更高效率的传递路由和维护大量的路由信息。

虽然BGP用于在AS之间传递路由信息,但并不是所有AS之间传递路由信息都需要运行BGP。比如在数据中心上行的连入Internet的出口上,为了避免Internet海量路由对数据中心内部网络的影响,设备采用静态路由代替BGP与外部网络通信。

受益

BGP从多方面保证了网络的安全性、灵活性、稳定性、可靠性和高效性:

BGP采用认证和GTSM的方式,保证了网络的安全性。 BGP提供了丰富的路由策略,能够灵活的进行路由选路。 BGP提供了路由聚合和路由衰减功能用于防止路由振荡,有效提高了网络的稳定性。 BGP使用TCP作为其传输层协议(端口号为179),并支持BGP与BFD联动、BGP Tracking和BGP GR,提高了网络的可靠性。

实验

实验拓扑

组网需求

如实验拓扑所示,需要在所有Switch上运行BGP协议,SwitchA、SwitchB之间建立连接,SwitchB、SwithC和SwitchD之间建立IBGP全连接

配置思路

采用如下的思路配置BGP的基本功能:

在SwitchB、SwitchC和SwitchD间配置IBGP连接。在SwitchA和SwitchB之间配置EBGP连接。

配置步骤

配置各接口所属的VLAN

###配置SwitcA。SwitchB、C和D的配置与SwitchA相似

system-view

[Huawei]sysname SwitchA

[SwitchA]undo info-center enable

[SwitchA]vlan batch 10 50

[SwitchA]interface GigabitEthernet 0/0/1

[SwitchA-GigabitEthernet0/0/1]port link-type trunk

[SwitchA-GigabitEthernet0/0/1]port trunk allow-pass vlan 10

[SwitchA-GigabitEthernet0/0/1]quit

[SwitchA]interface GigabitEthernet 0/0/2

[SwitchA-GigabitEthernet0/0/2]port link-type trunk

[SwitchA-GigabitEthernet0/0/2]port trunk allow-pass vlan 50

[SwitchA-GigabitEthernet0/0/2]quit

[SwitchA]

配置各Vlanif的ip地址

##配置SwitchA。SwitchB、SwitchC和SwitchD的配置与SwitchA类似。

[SwitchA]interface Vlanif 10

[SwitchA-Vlanif10]ip address 192.168.1.2 24

[SwitchA-Vlanif10]quit

[SwitchA]interface Vlanif 50

[SwitchA-Vlanif50]ip address 10.1.1.1 16

[SwitchA-Vlanif50]quit

[SwitchA]

配置IBGP连接

##SwitchB的配置

[SwitchB]bgp 65009

[SwitchB-bgp]router-id 172.17.2.2

[SwitchB-bgp]peer 172.16.1.2 as-number 65009

[SwitchB-bgp]peer 172.16.3.2 as-number 65009

[SwitchB-bgp]quit

[SwitchB]

##SwitchC的配置

[SwitchC]bgp 65009

[SwitchC-bgp]router-id 172.17.3.3

[SwitchC-bgp]peer 172.16.3.1 as-number 65009

[SwitchC-bgp]peer 172.16.2.2 as-number 65009

##SwitchD的配置

[SwitchD]bgp 65009

[SwitchD-bgp]router-id 172.17.4.4

[SwitchD-bgp]peer 172.16.1.1 as-number 65009

[SwitchD-bgp]peer 172.16.2.1 as-number 65009

[SwitchD-bgp]quit

[SwitchD]

配置EBGP

##SwitchA的配置

[SwitchA]bgp 65008

[SwitchA-bgp]router-id 172.17.1.1

[SwitchA-bgp]peer 192.168.1.1 as-number 65009

[SwitchA-bgp]quit

[SwitchA]

##SwitchB的配置

[SwitchB]bgp 65009

[SwitchB-bgp]peer 192.168.1.2 as-number 65008

[SwitchB-bgp]quit

[SwitchB]

查看BGP对等体的连接状态

[SwitchB]display bgp peer

BGP local router ID : 172.17.2.2

Local AS number : 65009

Total number of peers : 3 Peers in established state : 3

Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre

fRcv

172.16.1.2 4 65009 5 6 0 00:03:01 Established

0

172.16.3.2 4 65009 6 7 0 00:04:04 Established

0

192.168.1.2 4 65008 3 2 0 00:01:00 Established

0

[SwitchB]

可以看出,SwitchB与其他Switch的BGP连接均已建立

配置SwitchA发布路由10.1.0.0/16

##配置SwitchA发布路由

[SwitchA]bgp 65008

[SwitchA-bgp]ipv4-family unicast

[SwitchA-bgp-af-ipv4]network 10.1.0.0 255.255.0.0

[SwitchA-bgp-af-ipv4]quit

[SwitchA-bgp]quit

[SwitchA]

##查看SwitchA路由表信息

[SwitchA]display bgp routing-table

BGP Local router ID is 172.17.1.1

Status codes: * - valid, > - best, d - damped,

h - history, i - internal, s - suppressed, S - Stale

Origin : i - IGP, e - EGP, ? - incomplete

Total Number of Routes: 1

Network NextHop MED LocPrf PrefVal Path/Ogn

*> 10.1.0.0/16 0.0.0.0 0 0 i

[SwitchA]

##查看SwitchB的路由表

[SwitchB]display bgp routing-table

BGP Local router ID is 172.17.2.2

Status codes: * - valid, > - best, d - damped,

h - history, i - internal, s - suppressed, S - Stale

Origin : i - IGP, e - EGP, ? - incomplete

Total Number of Routes: 1

Network NextHop MED LocPrf PrefVal Path/Ogn

*> 10.1.0.0/16 192.168.1.2 0 0 65008i

[SwitchB]

##查看SwitchC的路由表

[SwitchC]display bgp routing-table

BGP Local router ID is 172.17.3.3

Status codes: * - valid, > - best, d - damped,

h - history, i - internal, s - suppressed, S - Stale

Origin : i - IGP, e - EGP, ? - incomplete

Total Number of Routes: 1

Network NextHop MED LocPrf PrefVal Path/Ogn

i 10.1.0.0/16 192.168.1.2 0 100 0 65008i

[SwitchC]

从路由表可以看出,SwitchC学到了AS65008中10.1.0.0的路由,但因为下一跳192.168.1.2不可达,所以也不是有效路由

配置BGP引入直连路由

##配置SwitchB

[SwitchB]bgp 65009

[SwitchB-bgp]ipv4-family unicast

[SwitchB-bgp-af-ipv4]import-route direct

[SwitchB-bgp-af-ipv4]quit

[SwitchB-bgp]quit

[SwitchB]

##查看SwitchA的BGP路由表

[SwitchA]display bgp routing-table

BGP Local router ID is 172.17.1.1

Status codes: * - valid, > - best, d - damped,

h - history, i - internal, s - suppressed, S - Stale

Origin : i - IGP, e - EGP, ? - incomplete

Total Number of Routes: 4

Network NextHop MED LocPrf PrefVal Path/Ogn

*> 10.1.0.0/16 0.0.0.0 0 0 i

*> 172.16.1.0/24 192.168.1.1 0 0 65009?

*> 172.16.3.0/24 192.168.1.1 0 0 65009?

192.168.1.0 192.168.1.1 0 0 65009?

[SwitchA]

查看SwitchC的BGP路由表

[SwitchC]display bgp routing-table

BGP Local router ID is 172.17.3.3

Status codes: * - valid, > - best, d - damped,

h - history, i - internal, s - suppressed, S - Stale

Origin : i - IGP, e - EGP, ? - incomplete

Total Number of Routes: 4

Network NextHop MED LocPrf PrefVal Path/Ogn

*>i 10.1.0.0/16 192.168.1.2 0 100 0 65008i

*>i 172.16.1.0/24 172.16.3.1 0 100 0 ?

i 172.16.3.0/24 172.16.3.1 0 100 0 ?

*>i 192.168.1.0 172.16.3.1 0 100 0 ?

[SwitchC]

可以看到,到10.1.0.0的路由变为有效路由,下一跳为SwichA的地址

##使用ping进行验证

[SwitchC]ping 10.1.1.1

PING 10.1.1.1: 56 data bytes, press CTRL_C to break

Reply from 10.1.1.1: bytes=56 Sequence=1 ttl=254 time=50 ms

Reply from 10.1.1.1: bytes=56 Sequence=2 ttl=254 time=60 ms

Reply from 10.1.1.1: bytes=56 Sequence=3 ttl=254 time=70 ms

Reply from 10.1.1.1: bytes=56 Sequence=4 ttl=254 time=70 ms

Reply from 10.1.1.1: bytes=56 Sequence=5 ttl=254 time=30 ms

--- 10.1.1.1 ping statistics ---

5 packet(s) transmitted 拼多多帮助力入口

5 packet(s) received

0.00% packet loss

round-trip min/avg/max = 30/56/70 ms

[SwitchC]

好文推荐

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧