BGP简单实验配置
实验拓扑:
要求:
BGP动态路由实验:
4台路由器基础名称,接口IP均配置
(1).4台PC分别在4个不同网段:
- PC1:10.1.1.0/24
- PC2: 10.1.2.0/24
- PC3: 10.2.3.0/25
- PC4: 10.2.4.0/25
(2).4台路由器loopback0地址分别是:
- R1:1.1.1.1/32
- R2:2.2.2.2/32
- R3:3.3.3.3/32
- R4:4.4.4.4/32
(3).路由器之间中继链路使用接口地址为:192.168.0.0/16,已经有基础配置。
组网要求使用BGP动态路由方式:
- R1和R2属AS 100域,R3和R4属AS200。
- R1和R3之间起EBGP协议,域内都起IBGP协议。
- 4台路由器loopback0地址可互通。
- 域间路由发布用户路由必须通过EBGP。
- R1和R3分别向R2和R4发布默认路由。
- PC2所在地址段10.1.2.0/24只能和域内地址互通。
- R3只能向R1发布PC3和PC4的汇总路由:10.2.0.0/16。
实验配置步骤:
- 配置IP编址
- 配置AS内IGP连通性
- 配置IBGP
- 配置EBGP
- 配置路由聚合
- 配置路由引入策略,是的PC2只能域内互通
- 验证
一、配置IP编址:
R1:
#
interface GigabitEthernet0/0/0
description R1-R3-GE0/0/0
ip address 192.168.13.1 255.255.255.252
#
interface GigabitEthernet0/0/1
description R1-R2
ip address 192.168.12.1 255.255.255.252
#
interface GigabitEthernet1/0/0
description R1-R3-GE1/0/0
ip address 192.168.13.5 255.255.255.252
#
interface GigabitEthernet5/0/0
description R1-PC1
ip address 10.1.1.1 255.255.255.0
#
interface LoopBack0
ip address 1.1.1.1 255.255.255.255
#
R2:
#
interface GigabitEthernet0/0/1
description R2-R1
ip address 192.168.12.2 255.255.255.252
#
interface GigabitEthernet5/0/0
description R2-PC2
ip address 10.1.2.1 255.255.255.0
#
interface LoopBack0
ip address 2.2.2.2 255.255.255.255
#
R3:
#
interface GigabitEthernet0/0/0
description R3-R1-GE0/0/0
ip address 192.168.13.2 255.255.255.252
#
interface GigabitEthernet0/0/1
description R3-R4-GE0/0/1
ip address 192.168.34.1 255.255.255.252
#
interface GigabitEthernet1/0/0
description R3-R1-GE1/0/0
ip address 192.168.13.6 255.255.255.252
#
interface GigabitEthernet5/0/0
description R3-PC3
ip address 10.2.3.2 255.255.255.128
#
interface LoopBack0
ip address 3.3.3.3 255.255.255.255
#
R4:
#
interface GigabitEthernet0/0/1
description R4-R3-GE0/0/1
ip address 192.168.34.2 255.255.255.252
#
interface GigabitEthernet5/0/0
description R4-PC4
ip address 10.2.4.1 255.255.255.128
#
interface LoopBack0
ip address 4.4.4.4 255.255.255.255
#
配置完成后测试地址直连地址连通性:此处不一一测试。
二、配置IGP连通性
AS100内运行OSPF,AS200内采用静态路由保证R3、R4的loopback 0 地址互通。具体配置如下:
AS100内:
R1:
#
ospf 1
area 0.0.0.0
network 1.1.1.1 0.0.0.0
network 192.168.12.0 0.0.0.255
#
R2:
#
ospf 1
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 192.168.12.0 0.0.0.255
area 0.0.0.12
#
AS200内:
R3:
#
ip route-static 4.4.4.4 255.255.255.255 192.168.34.2
#
R4:
#
ip route-static 3.3.3.3 255.255.255.255 192.168.34.1
#
三:配置IBGP
R1:
#
bgp 100
peer 2.2.2.2 as-number 100
peer 2.2.2.2 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
network 1.1.1.1 255.255.255.255
network 10.1.1.0 255.255.255.0
peer 2.2.2.2 enable
#
R2:
bgp 100
peer 1.1.1.1 as-number 100
peer 1.1.1.1 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
network 2.2.2.2 255.255.255.255
network 10.1.2.0 255.255.255.0
peer 1.1.1.1 enable
#
R3:
#
bgp 200
peer 4.4.4.4 as-number 200
peer 4.4.4.4 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
aggregate 10.2.0.0 255.255.0.0 detail-suppressed
network 3.3.3.3 255.255.255.255
network 10.2.3.0 255.255.255.128
peer 4.4.4.4 enable
peer 4.4.4.4 default-route-advertise
#
R4:
#
bgp 200
peer 3.3.3.3 as-number 200
peer 3.3.3.3 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
network 4.0.0.0
network 4.4.4.4 255.255.255.255
network 10.2.4.0 255.255.255.128
peer 3.3.3.3 enable
#
注意:BGP为保证路由下一跳的可达性,需要将IGP路由与EGP路由同步。故,需在R1,R3上将IGP协议路由引入。
R1:
#
bgp 100
import-route direct
import-route static
import-route ospf 1
#
R3:
#
bgp 200
import-route direct
import-route static
#
四、配置EBGP
此处采用loopback口进行EBGP邻居的搭建,也可用直连口进行EBGP邻居建立,直连口建立邻居关系更简单。具体配置如下:
R1:
#
ip route-static 3.3.3.3 255.255.255.255 192.168.13.2
ip route-static 3.3.3.3 255.255.255.255 192.168.13.6 #保证路由的可达性,BGP为TCP协议,需三层可达才能建立BGP邻居关系。
#
bgp 100
peer 3.3.3.3 as-number 200
peer 3.3.3.3 ebgp-max-hop 2 #EBGP邻居建立是,默认TTL值为1,利用loopback口建立邻居关系是由于loopback口之间不是直连,故需要改变EBGP邻居的多跳可达属性。
peer 3.3.3.3 connect-interface LoopBack0
#
R3:
#
ip route-static 1.1.1.1 255.255.255.255 192.168.13.1
ip route-static 1.1.1.1 255.255.255.255 192.168.13.5
#
bgp 200
peer 1.1.1.1 as-number 100
peer 1.1.1.1 ebgp-max-hop 2
peer 1.1.1.1 connect-interface LoopBack0
ipv4-family unicast
undo synchronization
aggregate 10.2.0.0 255.255.0.0 detail-suppressed
network 3.3.3.3 255.255.255.255
network 10.2.3.0 255.255.255.128
peer 1.1.1.1 enable
peer 4.4.4.4 default-route-advertise 向R4发布默认路由
#
五、配置路由聚合
#
bgp 200
aggregate 10.2.0.0 255.255.0.0 detail-suppressed
#
验证:在R1上查看是否有10.2.3.0或者10.2.4.0网段
六、配置路由引入策略,是的PC2只能域内互通
R2:
#
ip ip-prefix PC2 index 10 deny 10.2.0.0 16
ip ip-prefix PC2 index 20 permit 0.0.0.0 0 less-equal 32
#
bgp 100
peer 1.1.1.1 ip-prefix PC2 import
#
七、验证
R1:
R2:
R3:
R4:
PC2:
PC1:
PC3:
PC4: