01-BGP典型配置举例
本章节下载: 01-BGP典型配置举例 (369.68 KB)
目 录
本文档介绍了BGP的基础配置举例。
本文档中的配置均是在实验室环境下进行的配置和验证,配置前设备的所有参数均采用出厂时的缺省配置。如果您已经对设备进行了配置,为了保证配置效果,请确认现有配置和以下举例中的配置不冲突。
本文档假设您已了解BGP特性。
随着A公司的不断发展,其网络规模也不断扩大,导致其设备运行的IGP协议不堪重负,为了解决这一问题,公司管理者决定在设备上运行一些BGP的基础配置。如图1所示,所有交换机均运行BGP协议。要求Device A和Device B之间建立EBGP连接,Device B和Device C之间建立IBGP连接,使得Device C能够访问Device A直连的8.1.1.0/24网段。
图1 IPv4 BGP基础配置组网图
· 在AS 65009内部,保证Device B到Device C的LoopBack接口路由可达,Device C到Device B的LoopBack接口路由可达,这样两个IBGP对等体才能建立TCP连接,本案例使用OSPF协议实现。
· 由于设备缺省情况下BGP不发布任何本地的网段路由,为了使Device C能够访问Device A直连的8.1.1.0/24网段,将8.1.1.0/24网段宣告进Device A的BGP进程中,将3.1.1.0/24网段和9.1.1.0/24网段宣告进Device B的BGP进程中。
表1 适用产品及版本
产品 |
软件版本 |
S12500R |
Release 5210及以上版本 |
· 为了防止端口状态不稳定引起路由震荡,本举例使用LoopBack接口来创建IBGP对等体。
· 使用LoopBack接口创建IBGP对等体时,因为LoopBack接口不是两对等体实际连接的接口,所以,必须使用peer connect-interface命令将LoopBack接口配置为BGP连接的源接口。
· EBGP邻居关系的两台交换机,处于不同的AS域,对端的LoopBack接口一般路由不可达,所以一般使用直连地址建立EBGP邻居。
· 缺省情况下,本设备的接口处于ADM(Administratively Down)状态,请根据实际需要在对应接口视图下使用undo shutdown命令开启接口
# 配置接口HundredGigE2/0/1的IP地址。
<RouterA> system-view
[RouterA] interface hundredgige 2/0/1
[RouterA-HundredGigE2/0/1] ip address 8.1.1.1 24
# 请参考以上方法配置其它相关接口的IP地址,配置步骤这里省略。
<DeviceB> system-view
[DeviceB] bgp 65009
[DeviceB-bgp-default] router-id 2.2.2.2
[DeviceB-bgp-default] peer 3.3.3.3 as-number 65009
[DeviceB-bgp-default] peer 3.3.3.3 connect-interface Loopback 0
[DeviceB-bgp-default] address-family ipv4 unicast
[DeviceB-bgp-default-ipv4] peer 3.3.3.3 enable
[DeviceB-bgp-default-ipv4] quit
[DeviceB-bgp-default] quit
[DeviceB] ospf 1
[DeviceB-ospf-1] area 0
[DeviceB-ospf-1-area-0.0.0.0] network 2.2.2.2 0.0.0.0
[DeviceB-ospf-1-area-0.0.0.0] network 9.1.1.0 0.0.0.255
[DeviceB-ospf-1-area-0.0.0.0] quit
[DeviceB-ospf-1] quit
<DeviceC> system-view
[DeviceC] bgp 65009
[DeviceC-bgp-default] router-id 3.3.3.3
[DeviceC-bgp-default] peer 2.2.2.2 as-number 65009
[DeviceC-bgp-default] peer 2.2.2.2 connect-interface Loopback 0
[DeviceC-bgp-default] address-family ipv4 unicast
[DeviceC-bgp-default-ipv4] peer 2.2.2.2 enable
[DeviceC-bgp-default-ipv4] quit
[DeviceC-bgp-default] quit
[DeviceC] ospf 1
[DeviceC-ospf-1] area 0
[DeviceC-ospf-1-area-0.0.0.0] network 3.3.3.3 0.0.0.0
[DeviceC-ospf-1-area-0.0.0.0] network 9.1.1.0 0.0.0.255
[DeviceC-ospf-1-area-0.0.0.0] quit
[DeviceC-ospf-1] quit
# 查看Device C的BGP对等体的连接状态。
[DeviceC] display bgp peer ipv4
BGP local router ID : 3.3.3.3
Local AS number : 65009
Total number of peers : 1 Peers in established state : 1
* - Dynamically created peer
Peer AS MsgRcvd MsgSent OutQ PrefRcv Up/Down State
2.2.2.2 65009 2 2 0 0 00:00:13 Established
以上显示信息表明Device B和Device C之间的IBGP连接已经建立。
<DeviceA> system-view
[DeviceA] bgp 65008
[DeviceA-bgp-default] router-id 1.1.1.1
[DeviceA-bgp-default] peer 3.1.1.1 as-number 65009
[DeviceA-bgp-default] address-family ipv4 unicast
[DeviceA-bgp-default-ipv4] peer 3.1.1.1 enable
[DeviceA-bgp-default-ipv4] network 8.1.1.0 24
[DeviceA-bgp-default-ipv4] quit
[DeviceA-bgp-default] quit
[DeviceB] bgp 65009
[DeviceB-bgp-default] peer 3.1.1.2 as-number 65008
[DeviceB-bgp-default] address-family ipv4 unicast
[DeviceB-bgp-default-ipv4] peer 3.1.1.2 enable
[DeviceB-bgp-default-ipv4] quit
[DeviceB-bgp-default] quit
# 查看Device B的BGP对等体的连接状态。
[DeviceB] display bgp peer ipv4
BGP local router ID : 2.2.2.2
Local AS number : 65009
Total number of peers : 2 Peers in established state : 2
* - Dynamically created peer
Peer AS MsgRcvd MsgSent OutQ PrefRcv Up/Down State
3.3.3.3 65009 4 4 0 0 00:02:49 Established
3.1.1.2 65008 2 2 0 0 00:00:05 Established
可以看出,Device B与Device C、Device B与Device A之间的BGP连接均已建立。
# 查看Device A的BGP路由表。
[DeviceA] display bgp routing-table ipv4
Total number of routes: 1
BGP local router ID is 1.1.1.1
Status codes: * - valid, > - best, d - dampened, h - history
s - suppressed, S - stale, i - internal, e - external
a - additional-path
Origin: i - IGP, e - EGP, ? - incomplete
Network NextHop MED LocPrf PrefVal Path/Ogn
* > 8.1.1.0/24 8.1.1.1 0 32768 i
# 查看Device B的BGP路由表。
[DeviceB] display bgp routing-table ipv4
Total number of routes: 1
BGP local router ID is 2.2.2.2
Status codes: * - valid, > - best, d - dampened, h - history
s - suppressed, S - stale, i - internal, e – external
a - additional-path
Origin: i - IGP, e - EGP, ? - incomplete
Network NextHop MED LocPrf PrefVal Path/Ogn
* >e 8.1.1.0/24 3.1.1.2 0 0 65008i
# 查看Device C的BGP路由表。
[DeviceC] display bgp routing-table ipv4
Total number of routes: 1
BGP local router ID is 3.3.3.3
Status codes: * - valid, > - best, d - dampened, h - history
s - suppressed, S - stale, i - internal, e – external
a - additional-path
Origin: i - IGP, e - EGP, ? - incomplete
Network NextHop MED LocPrf PrefVal Path/Ogn
i 8.1.1.0/24 3.1.1.2 0 100 0 65008i
从路由表可以看出,Device A没有学到AS 65009内部的任何路由,Device C虽然学到了AS 65008中的8.1.1.0的路由,但因为下一跳3.1.1.2不可达,所以也不是有效路由。
在Device B上配置BGP发布本地网段路由,以便Device A能够获取到网段9.1.1.0/24的路由,Device C能够获取到网段3.1.1.0/24的路由。
[DeviceB] bgp 65009
[DeviceB-bgp-default] address-family ipv4 unicast
[DeviceB-bgp-default-ipv4] network 3.1.1.0 24
[DeviceB-bgp-default-ipv4] network 9.1.1.0 24
[DeviceB-bgp-default-ipv4] quit
[DeviceB-bgp-default] quit
# 查看Device A的BGP路由表。
[DeviceA] display bgp routing-table ipv4
Total number of routes: 3
BGP local router ID is 1.1.1.1
Status codes: * - valid, > - best, d - dampened, h - history
s - suppressed, S - stale, i - internal, e – external
a - additional-path
Origin: i - IGP, e - EGP, ? - incomplete
Network NextHop MED LocPrf PrefVal Path/Ogn
* >e 3.1.1.0/24 3.1.1.1 0 0 65009?
* > 8.1.1.0/24 8.1.1.1 0 32768 i
* >e 9.1.1.0/24 3.1.1.1 0 0 65009i
以上显示信息表明,在Device B上发布本地网段路由后,Device A新增了到达9.1.1.0/24的路由。
# 查看Device C的BGP路由表。
[DeviceC] display bgp routing-table ipv4
Total number of routes: 3
BGP local router ID is 3.3.3.3
Status codes: * - valid, > - best, d - dampened, h - history
s - suppressed, S - stale, i - internal, e – external
a - additional-path
Origin: i - IGP, e - EGP, ? - incomplete
Network NextHop MED LocPrf PrefVal Path/Ogn
* >i 3.1.1.0/24 2.2.2.2 0 100 0 ?
* >i 8.1.1.0/24 3.1.1.2 0 100 0 65008i
* >i 9.1.1.0/24 2.2.2.2 0 100 0 i
以上显示信息表明,到8.1.1.0的路由变为有效路由,下一跳为Device A的地址。
# 在DeviceC上Ping目标地址8.1.1.1进行验证。
[DeviceC] ping 8.1.1.1
Ping 8.1.1.1 (8.1.1.1): 56 data bytes, press CTRL_C to break
56 bytes from 8.1.1.1: icmp_seq=0 ttl=254 time=10.000 ms
56 bytes from 8.1.1.1: icmp_seq=1 ttl=254 time=4.000 ms
56 bytes from 8.1.1.1: icmp_seq=2 ttl=254 time=4.000 ms
56 bytes from 8.1.1.1: icmp_seq=3 ttl=254 time=3.000 ms
56 bytes from 8.1.1.1: icmp_seq=4 ttl=254 time=3.000 ms
--- Ping statistics for 8.1.1.1 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 3.000/4.800/10.000/2.638 ms
以上信息表明Device C能够访问Device A直连的8.1.1.0/24网段。
· Device A
#
interface Loopback0
ip address 1.1.1.1 255.255.255.255
#
interface HundredGigE 2/0/1
ip address 8.1.1.1 255.255.255.0
#
interface HundredGigE 2/0/2
ip address 3.1.1.2 255.255.255.0
#
bgp 65008
router-id 1.1.1.1
peer 3.1.1.1 as-number 65009
#
address-family ipv4 unicast
network 8.1.1.0 255.255.255.0
peer 3.1.1.1 enable
#
· Device B
#
interface Loopback0
ip address 2.2.2.2 255.255.255.255
#
interface HundredGigE 2/0/1
ip address 3.1.1.1 255.255.255.0
#
interface HundredGigE 2/0/2
ip address 9.1.1.1 255.255.255.0
#
bgp 65009
router-id 2.2.2.2
peer 3.1.1.2 as-number 65008
peer 3.3.3.3 as-number 65009
peer 3.3.3.3 connect-interface Loopback0
#
address-family ipv4 unicast
network 3.1.1.0 255.255.255.0
network 9.1.1.0 255.255.255.0
peer 3.1.1.2 enable
peer 3.3.3.3 enable
#
ospf 1
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 9.1.1.0 0.0.0.255
#
· Device C
#
interface Loopback0
ip address 3.3.3.3 255.255.255.255
#
interface HundredGigE 2/0/1
ip address 9.1.1.2 255.255.255.0
#
bgp 65009
router-id 3.3.3.3
peer 2.2.2.2 as-number 65009
peer 2.2.2.2 connect-interface Loopback0
#
address-family ipv4 unicast
peer 2.2.2.2 enable
#
ospf 1
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 9.1.1.0 0.0.0.255
#
公司A的所有设备在AS 65008内,公司B的所有设备在AS 65009内,AS 65008和AS 65009通过设备Device A和Device B相连。公司A的研发部门所在网段为8.1.1.0/24,公司B的研发部门所在网段为9.1.2.0/24。
由于市场需求,现在两个公司决定联合开发一款新型产品,这就需要两个公司的研发部门可以互相通信,实现网段9.1.2.0/24与网段8.1.1.0/24的互通,同时需要确保两个公司的其它网段不能相互通信。
图2 BGP与IGP交互配置组网图
配置思路
在Device B上将BGP和OSPF路由互相引入,使得Device A可以访问9.1.2.0/24网段,Device C可以访问8.1.1.0/24网段。
表2 适用产品及版本
产品 |
软件版本 |
S12500R |
Release 5210及以上版本 |
· EBGP邻居关系的两台交换机,处于不同的AS域,对端的LoopBack接口一般路由不可达,所以一般使用直连地址建立EBGP邻居。
· 缺省情况下,本设备的接口处于ADM(Administratively Down)状态,请根据实际需要在对应接口视图下使用undo shutdown命令开启接口
# 配置接口HundredGigE2/0/1的IP地址。
<RouterA> system-view
[RouterA] interface hundredgige 2/0/1
[RouterA-HundredGigE2/0/1] ip address 8.1.1.1 24
# 请参考以上方法配置其它相关接口的IP地址,配置步骤这里省略。
在AS 65009内配置OSPF,使得Device B能获取到到9.1.2.0/24网段的路由。
<DeviceB> system-view
[DeviceB] ospf 1
[DeviceB-ospf-1] area 0
[DeviceB-ospf-1-area-0.0.0.0] network 2.2.2.2 0.0.0.0
[DeviceB-ospf-1-area-0.0.0.0] network 9.1.1.0 0.0.0.255
[DeviceB-ospf-1-area-0.0.0.0] quit
[DeviceB-ospf-1] quit
<DeviceC> system-view
[DeviceC] ospf 1
[DeviceC-ospf-1] area 0
[DeviceC-ospf-1-area-0.0.0.0] network 9.1.1.0 0.0.0.255
[DeviceC-ospf-1-area-0.0.0.0] network 9.1.2.0 0.0.0.255
[DeviceC-ospf-1-area-0.0.0.0] quit
[DeviceC-ospf-1] quit
配置EBGP连接,并在Device A上将8.1.1.0/24网段通告到BGP路由表中,以便Device B获取到网段8.1.1.0/24的路由。
<DeviceA> system-view
[DeviceA] bgp 65008
[DeviceA-bgp-default] router-id 1.1.1.1
[DeviceA-bgp-default] peer 3.1.1.1 as-number 65009
[DeviceA-bgp-default] address-family ipv4 unicast
[DeviceA-bgp-default-ipv4] peer 3.1.1.1 enable
[DeviceA-bgp-default-ipv4] network 8.1.1.0 24
[DeviceA-bgp-default-ipv4] quit
[DeviceA-bgp-default] quit
[DeviceB] bgp 65009
[DeviceB-bgp-default] router-id 2.2.2.2
[DeviceB-bgp-default] peer 3.1.1.2 as-number 65008
[DeviceB-bgp-default] address-family ipv4 unicast
[DeviceB-bgp-default-ipv4] peer 3.1.1.2 enable
# 在Device B上配置BGP和OSPF互相引入路由。
[DeviceB-bgp-default-ipv4] import-route ospf 1
[DeviceB-bgp-default-ipv4] quit
[DeviceB-bgp-default] quit
[DeviceB] ospf 1
[DeviceB-ospf-1] import-route bgp
[DeviceB-ospf-1] quit
# 查看Device A的BGP路由表。
[DeviceA] display bgp routing-table ipv4
Total number of routes: 3
BGP local router ID is 1.1.1.1
Status codes: * - valid, > - best, d - dampened, h - history
s - suppressed, S - stale, i - internal, e – external
a - additional-path
Origin: i - IGP, e - EGP, ? - incomplete
Network NextHop MED LocPrf PrefVal Path/Ogn
* > 8.1.1.0/24 8.1.1.1 0 32768 i
* >e 9.1.2.0/24 3.1.1.1 1 0 65009?
# 查看Device C的OSPF路由表。
[DeviceC] display ospf routing
OSPF Process 1 with Router ID 3.3.3.3
Routing Table
Topology base (MTID 0)
Routing for network
Destination Cost Type NextHop AdvRouter Area
9.1.1.0/24 1 Transit 9.1.1.2 3.3.3.3 0.0.0.0
9.1.2.0/24 1 Stub 9.1.2.1 192.168.0.63 0.0.0.0
2.2.2.2/32 1 Stub 9.1.1.1 2.2.2.2 0.0.0.0
Routing for ASEs
Destination Cost Type Tag NextHop AdvRouter
8.1.1.0/24 1 Type2 1 9.1.1.1 2.2.2.2
Total nets: 3
Intra area: 2 Inter area: 0 ASE: 1 NSSA: 0
从Device A的BGP路由表和Device C的OSPF路由表可以看出,Swtich B上的BGP和OSPF路由已经互相引入。
# 在Device A上使用源地址8.1.1.1Ping目标地址9.1.2.1进行验证。
[DeviceA] ping -a 8.1.1.1 9.1.2.1
Ping 9.1.2.1 (9.1.2.1) from 8.1.1.1: 56 data bytes, press CTRL_C to break
56 bytes from 9.1.2.1: icmp_seq=0 ttl=254 time=10.000 ms
56 bytes from 9.1.2.1: icmp_seq=1 ttl=254 time=12.000 ms
56 bytes from 9.1.2.1: icmp_seq=2 ttl=254 time=2.000 ms
56 bytes from 9.1.2.1: icmp_seq=3 ttl=254 time=7.000 ms
56 bytes from 9.1.2.1: icmp_seq=4 ttl=254 time=9.000 ms
--- Ping statistics for 9.1.2.1 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 2.000/8.000/12.000/3.406 ms
# 在Device C上使用源地址9.1.2.1Ping目标地址8.1.1.1进行验证。
[DeviceC] ping -a 9.1.2.1 8.1.1.1
Ping 8.1.1.1 (8.1.1.1) from 9.1.2.1: 56 data bytes, press CTRL_C to break
56 bytes from 8.1.1.1: icmp_seq=0 ttl=254 time=9.000 ms
56 bytes from 8.1.1.1: icmp_seq=1 ttl=254 time=4.000 ms
56 bytes from 8.1.1.1: icmp_seq=2 ttl=254 time=3.000 ms
56 bytes from 8.1.1.1: icmp_seq=3 ttl=254 time=3.000 ms
56 bytes from 8.1.1.1: icmp_seq=4 ttl=254 time=3.000 ms
--- Ping statistics for 8.1.1.1 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 3.000/4.400/9.000/2.332 ms
上述显示信息说明网段9.1.2.0/24与网段8.1.1.0/24能实现互通。
# 在Device A上使用源地址8.1.2.1分别Ping目标地址9.1.2.1和9.1.3.1进行验证。
[DeviceA] ping –a 8.1.2.1 9.1.2.1
Ping 9.1.2.1 (9.1.2.1) from 8.1.2.1: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- Ping statistics for 9.1.2.1 ---
5 packet(s) transmitted, 0 packet(s) received, 100.0% packet loss
[DeviceA] ping –a 8.1.2.1 9.1.3.1
Ping 9.1.3.1 (9.1.3.1) from 8.1.2.1: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- Ping statistics for 9.1.3.1 ---
5 packet(s) transmitted, 0 packet(s) received, 100.0% packet loss
# 在Device C上使用源地址9.1.3.1分别Ping目标地址8.1.1.1和8.1.2.1进行验证。
[DeviceC] ping –a 9.1.3.1 8.1.1.1
Ping 8.1.1.1 (8.1.1.1) from 9.1.3.1: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- Ping statistics for 8.1.1.1 ---
5 packet(s) transmitted, 0 packet(s) received, 100.0% packet loss
[DeviceC] ping –a 9.1.3.1 8.1.2.1
Ping 8.1.2.1 (8.1.2.1) from 9.1.3.1: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- Ping statistics for 8.1.2.1 ---
5 packet(s) transmitted, 0 packet(s) received, 100.0% packet loss
上述信息说明两个自治区域之间只有网段9.1.2.0/24与网段8.1.1.0/24能实现互通,其他网段之间是无法互通的。
· Device A
#
interface Loopback0
ip address 1.1.1.1 255.255.255.255
#
interface HundredGigE 2/0/1
ip address 8.1.1.1 255.255.255.0
#
interface HundredGigE 2/0/2
ip address 3.1.1.2 255.255.255.0
#
bgp 65008
router-id 1.1.1.1
peer 3.1.1.1 as-number 65009
#
address-family ipv4 unicast
network 8.1.1.0 255.255.255.0
peer 3.1.1.1 enable
#
· Device B
#
interface Loopback0
ip address 2.2.2.2 255.255.255.255
#
interface HundredGigE 2/0/1
ip address 3.1.1.1 255.255.255.0
#
interface HundredGigE 2/0/2
ip address 9.1.1.1 255.255.255.0
#
bgp 65009
router-id 2.2.2.2
peer 3.1.1.2 as-number 65008
#
address-family ipv4 unicast
import-route ospf 1
peer 3.1.1.2 enable
#
ospf 1
import-route bgp
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 9.1.1.0 0.0.0.255
#
· Device C
#
interface Loopback0
ip address 3.3.3.3 255.255.255.255
#
interface HundredGigE 2/0/1
ip address 9.1.1.2 255.255.255.0
#
interface HundredGigE 2/0/2
ip address 9.1.2.1 255.255.255.0
#
ospf 1
area 0.0.0.0
network 9.1.1.0 0.0.0.255
network 9.1.2.0 0.0.0.255
#
· H3C S12500R系列交换路由器 三层技术-IP路由配置指导-R52xx
· H3C S12500R系列交换路由器 三层技术-IP路由命令参考-R52xx
· H3C S12500R-48Y8C&S12500R-48C6D交换路由器 三层技术-IP路由配置指导-R52xx
· H3C S12500R-48Y8C&S12500R-48C6D交换路由器 三层技术-IP路由命令参考-R52xx
不同款型规格的资料略有差异, 详细信息请向具体销售和400咨询。H3C保留在没有任何通知或提示的情况下对资料内容进行修改的权利!