BGP笔记及实验

发布于:2025-08-15 ⋅ 阅读:(13) ⋅ 点赞:(0)

一、实验需求


二、需求分析
环回地址限制:AS1 和 AS3 部分环回地址不能宣告,需通过合理的路由策略控制,防止地址泄露。
BGP 协议运用:利用 BGP 协议在不同自治系统间交换路由信息,实现环回地址互通,需正确配置 BGP 邻居关系、属性等。
联邦 AS:AS2 和 AS3 划分为联邦自治系统,要配置联邦内和联邦间的 BGP 关系,以实现路由传递和隔离。
路由优化:通过配置 BGP 属性(如 AS_PATH、MED 等)、路由反射器等方式,减少路由条目,避免环路。

三、实验步骤 
1、设备基本配置
给所有路由器配置主机名(如 AR1、AR2 等 )。
配置各路由器接口 IP 地址,包括 AS 间骨干链路和 AS2 内部链路地址,按照规划的地址段配置。
R1
 
GigabitEthernet0/0/0              12.0.0.1/24          up         up          
LoopBack0                         192.168.1.1/24       up         up(s)     
LoopBack1                         10.1.1.1/24          up         up(s) 
 
 
R2
 
GigabitEthernet0/0/0              12.0.0.2/24          up         up        
GigabitEthernet0/0/1              172.16.0.1/30        up         up        
GigabitEthernet0/0/2              172.16.0.21/30       up         up        
LoopBack0                         172.16.1.1/30        up         up(s)     
 
 
R3
GigabitEthernet0/0/0              172.16.0.2/30        up         up        
GigabitEthernet0/0/1              172.16.0.5/30        up         up           
LoopBack0                         172.16.1.5/30        up         up(s) 
 
 
R4
 
GigabitEthernet0/0/0              172.16.0.6/30        up         up        
GigabitEthernet0/0/1              172.16.0.9/30        up         up             
LoopBack0                         172.16.1.9/30        up         up(s) 
 
 
R5
 
GigabitEthernet0/0/0              172.16.0.22/30       up         up        
GigabitEthernet0/0/1              172.16.0.17/30       up         up        
LoopBack0                         172.16.1.21/30       up         up(s)   
 
 
R6
 
GigabitEthernet0/0/0              172.16.0.10/30       up         up        
GigabitEthernet0/0/1              172.16.0.14/30       up         up        
GigabitEthernet0/0/2              78.0.0.7/24          up         up        
LoopBack0                         172.16.1.13/30       up         up(s) 
 
 
R7
 
GigabitEthernet0/0/0              172.16.0.10/30       up         up        
GigabitEthernet0/0/1              172.16.0.14/30       up         up        
GigabitEthernet0/0/2              78.0.0.7/24          up         up        
LoopBack0                         172.16.1.13/30       up         up(s) 
 
 
R8
 
GigabitEthernet0/0/0              78.0.0.8/24          up         up         
LoopBack0                         192.168.2.1/24       up         up(s)     
LoopBack1                         11.1.1.1/24          up         up(s) 
 
 

 2、环回地址配置
在 AS1 的路由器上配置环回接口及地址 192.168.1.0/24 ,不将其宣告进任何路由协议。
在 AS3 的路由器上配置环回接口及地址 192.168.2.0/24 和 10.1.1.0/24 ,192.168.2.0/24 不宣告进任何路由协议。
R2:

[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]a 0
[R2-ospf-1-area-0.0.0.0]net 172.16.0.0 0.0.255.255


 R3:

[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]a 0
[R3-ospf-1-area-0.0.0.0]net 172.16.0.0 0.0.255.255


R4:

[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1]a 0
[R4-ospf-1-area-0.0.0.0]net 172.16.0.0 0.0.255.255


R5:

[R5]ospf 1 router-id 5.5.5.5
[R5-ospf-1]a 0
[R5-ospf-1-area-0.0.0.0]net 172.16.0.0 0.0.255.255


R6:

[R6]ospf 1 router-id 6.6.6.6
[R6-ospf-1]a 0
[R6-ospf-1-area-0.0.0.0]net 172.16.0.0 0.0.255.255


R7:

[R7]ospf 1 router-id 7.7.7.7
[R7-ospf-1]a 0
[R7-ospf-1-area-0.0.0.0]net 172.16.0.0 0.0.255.255


3、BGP联邦配置
AS1 配置:在 AS1 的路由器上启动 BGP 进程,配置与 AS2(联邦 AS 64512 )的边界路由器的邻居关系。
AS2(联邦 AS 64512)配置
配置联邦内部 BGP 邻居关系,在 AS2 内路由器间建立 iBGP 邻居。
配置与 AS1 和 AS3(联邦 AS 64513 )的边界路由器的 eBGP 邻居关系,设置联邦相关参数。
AS3(联邦 AS 64513)配置
配置联邦内部 BGP 邻居关系,在 AS3 内路由器间建立 iBGP 邻居。
配置与 AS2 的边界路由器的 eBGP 邻居关系,设置联邦相关参数
R1:

[r1]bgp 
[r1-bgp]router-id 1.1.1.1    
[r1-bgp]peer 12.0.0.2 as-number 2

 R2:

 
[R2]bgp 64512
[R2-bgp]router-id 2.2.2.2
[R2-bgp]confederation id 2
[R2-bgp]peer 12.0.0.1 as 1
[R2-bgp]peer 172.16.1.5 as-number 64512    
[R2-bgp]peer 172.16.1.5 connect-interface l0 
[R2-bgp]peer 172.16.1.5 next-hop-local 
[R2-bgp]confederation peer-as 64513 
[R2-bgp]peer 172.16.1.21 as 64513
[R2-bgp]peer 172.16.1.21 connect-interface LoopBack 0
[r2-bgp]peer 172.16.1.21 ebgp-max-hop 
 

R3:

[r3]bgp 64512
[r3-bgp]router-id 3.3.3.3
[r3-bgp]confederation id 2
[r3-bgp]peer 172.16.1.1 as-number 64512
[r3-bgp]peer 172.16.1.1 connect-interface LoopBack 0
[r3-bgp]peer 172.16.1.9 as-number 64512
[r3-bgp]peer 172.16.1.9 connect-interface LoopBack 0

R4:

[r4]bgp 64512
[r4-bgp]router-id 4.4.4.4
[r4-bgp]confederation id 2
[r4-bgp]peer 172.16.1.5 as-number 64512    
[r4-bgp]peer 172.16.1.5 connect-interface LoopBack 0
[r4-bgp]confederation peer-as 64513
[r4-bgp]peer 172.16.1.13 as-number 64513
[r4-bgp]peer 172.16.1.13 connect-interface LoopBack 0
[r4-bgp]peer 172.16.1.13 ebgp-max-hop

R5:

[r5]bgp 64513
[r5-bgp]router-id 5.5.5.5
[r5-bgp]confederation id 2
 
[r5-bgp]confederation peer-as 64512
[r5-bgp]peer 172.16.1.1 as-number 64512
[r5-bgp]peer 172.16.1.1 connect-interface LoopBack 0
[r5-bgp]peer 172.16.1.1 ebgp-max-hop 
 
[r5-bgp]peer 172.16.1.17 as-number 64513    
[r5-bgp]peer 172.16.1.17 connect-interface LoopBack 0
 

R6:

[r6]bgp 64513
[r6-bgp]router-id 6.6.6.6
[r6-bgp]confederation id 2
[r6-bgp]peer 172.16.1.21 as-number 64513
[r6-bgp]peer 172.16.1.21 connect-interface LoopBack 0
[r6-bgp]peer 172.16.1.13 as-number 64513
[r6-bgp]peer 172.16.1.13 connect-interface LoopBack 0

R7:

[r7]bgp 64513
[r7-bgp]router-id 7.7.7.7    
[r7-bgp]confederation id 2
[r7-bgp]peer 172.16.1.17 as-number 64513
[r7-bgp]peer 172.16.1.17 connect-interface LoopBack 0
[r7-bgp]peer 172.16.1.17 next-hop-local
[r7-bgp]confederation peer-as 64512    
[r7-bgp]peer 172.16.1.9 as-number 64512
[r7-bgp]peer 172.16.1.9 connect-interface LoopBack 0
[r7-bgp]peer 172.16.1.9 next-hop-local
[r7-bgp]peer 172.16.1.9 ebgp-max-hop 
[r7]bgp 64513
[r7-bgp]peer 78.0.0.8 as-number 3
 

R8:

[r8]bgp 3
[r8-bgp]router-id 8.8.8.8
[r8-bgp]peer 78.0.0.7 as-number 2

4、配置路由反射器(RR)
在 AS2 和 AS3 内选择合适的路由器作为路由反射器,配置其为 RR,其他路由器作为客户端。在 RR 上配置相关命令(如bgp cluster - id ),客户端配置指向 RR 的邻居关系。
 R3:

[r3]bgp 64512
[r3-bgp]peer 172.16.1.9 reflect-client 

R6:

[r6]bgp 64513    
[r6-bgp]peer  172.16.1.21 reflect-client 

5、路由策略配置
在 AS1 和 AS3 配置路由策略,防止受限环回地址(192.168.1.0/24 和 192.168.2.0/24 )被宣告出去。
通过配置 BGP 属性(如 AS_PATH、MED )来优化路由选择,减少路由条目数量,避免环路。
R1:R8:直接宣告

[r1]bgp 1
[r1-bgp]network 10.1.1.0 24
[r8]bgp 3
[r8-bgp]network 11.1.1.0 24

 其他重发布-------通过BGP

[r2]bgp 64512
[r2-bgp]import-route ospf 1

6、配置VPN
 R1:

[r1]interface Tunnel 0/0/0
[r1-Tunnel0/0/0]ip address 192.168.3.1 24    
[r1-Tunnel0/0/0]tunnel-protocol gre 
[r1-Tunnel0/0/0]source 10.0.0.1
[r1-Tunnel0/0/0]destination 11.1.1.1

R8:

[r1]interface Tunnel 0/0/0
[r1-Tunnel0/0/0]ip address 192.168.3.1 24    
[r1-Tunnel0/0/0]tunnel-protocol gre 
[r1-Tunnel0/0/0]source 10.0.0.1
[r1-Tunnel0/0/0]destination 11.1.1.1
补充路由:

[r1]ip route-static 192.168.2.0 24 192.168.3.2
[r8]ip route-static 192.168.1.0 24 192.168.3.1

7、验证测试
使用ping命令测试 AS3 内两个环回地址(10.1.1.0/24 与 192.168.2.0/24 )间的连通性。
测试 AS1、AS2、AS3 所有设备环回地址间的相互连通性。
使用show ip bgp等命令查看 BGP 路由表、邻居关系等,确保配置正确。


网站公告

今日签到

点亮在社区的每一天
去签到