规划思路:
1.
先将
172.16.0.0/16
划分到
/24
的网段,因为
/24
的网段可用地址数量为
254
(接近一个局域网容纳主机的
极限)
172.16.0.0/16
172.16.0.0/24
172.16.1.0/24
...
2.
其中选取
172.16.0.0/24
网段,划分至
/32
,这些地址分配用于环回接口,用来未来建立
BGP
的邻居
172.16.0.0/24
172.16.0.0/32
172.16.0.1/32
...
3.
剩下的因为骨干链路不做要求,所以可以自行随意配置(这里仅提供一种,如果需求规划的思路)
选择
172.16.1.0/24
网段做骨干链路使用,将该网段划分至
/30
,原因在于
/30
的网段实际只包含两个可
用
IP
地址(而骨干链路一般不会连接设备,所以实际上只需要配置链路两端的节点
IP
)
172.16.1.0/24
172.16.1.0/32
172.16.1.4/32
...
该图因为不做需求,所以简化规划思路
—R1-R2
直连链路(
12.0.0.0/24
)
4.
剩余网段统一用于
AS
区域的用户使用
172.16.2.0/24------R2
环回(用来模拟用户网段)
172.16.3.0/24------R3
环回
...
2.2—
按照规划的
IP
配置路由器的
IP
地址(该步骤省略)
![](https://i-blog.csdnimg.cn/blog_migrate/83c4920329e8fbad1322b5146a717dc7.png)
这里以R7为例,链路以设备编号随意划分,环回0代表用户网段,环回1用于BGP建邻
2.3—AS
内部配置
IGP
使得
AS2
内部网络互通(备注:此时网络不大、其次重点在于
BGP
的使用,所以这里使用单区域
OSPF
进行配置)
R2
配置:
ospf 1 router-id 2.2.2.2 —
配置路由器
RID
area 0.0.0.0 —
创建区域
network 23.0.0.0 0.0.0.255
network 25.0.0.0 0.0.0.255
network 172.16.0.0 0.0.255.255 —
宣告(注意用户网段、建邻环回和骨干链路都需要宣告,
同时如果骨干
链路也进行了规划,那么这里宣告时可用进行范围宣告
172.16.0.0 0.0.255.255
)
所以,实际上地址规划相当重要,因为合理的规划
IP
地址,一方面可用简化后续所以的配置难度,另一方面
可以使得网络更加合理
R3
配置:
ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 23.0.0.0 0.0.0.255
network 34.0.0.0 0.0.0.255
network 172.16.0.0 0.0.255.255
其余设备类似,不一一展示
![](https://i-blog.csdnimg.cn/blog_migrate/feed2329945eb668a5593a9866dbd070.png)
R2的OSPF邻居表
R2的路由表—这里只展示R3-R7的用户网段和建邻网段
2.4—
配置
BGP
分析:
R1
和
R2
、
R7
和
R8
,建立
EBGP
邻居,要求
EBGP
邻居使用直连接口建立邻居,不用修改更新源,直接进入
IPV4
地址族,使能邻居即可。
IBGP
邻居要求使用环回口建立,根据
BGP
邻居建立条件,需要修改
IBGP
邻居更新源为对应环回口。由于
R2
和
R7
既有
EBGP
邻居,又有
IBGP
邻居,为了使从
EBGP
邻居学习的路由传递至
IBGP
邻居时下一跳可达,需要
修改
IBGP
邻居下一跳为本机
分析:由于
AS 2
建立
BGP
联盟,所以
R2
、
R3
、
R4
的
BGP
运行在
AS 64512
中,
R4
、
R5
、
R6
的
BGP
运行在
AS
64513
中,子
AS
之间通过
R2
和
R5
、
R4
和
R7
建立
EBGP
邻居来解决
BGP
路由传递问题,路由黑洞问题通过全
连接的
BGP
解决
(注意:联盟
AS
有单独的
AS
号进行区分)
真实
AS
之间的
EBGP
邻居仍然使用真实
AS
编号,子
AS
之间的
EBGP
邻居使用子
AS
编号。
在
AS 2
外部,
R1
和
R2
建立
EBGP
邻居,
R7
和
R8
建立
EBGP
邻居。
在
AS 2
内部,
R2
和
R5
上建立
EBGP
邻居,
R4-R7
上建立
EBGP
邻居。
R2
和
R3
、
R3
和
R4
、
R5
和
R6
、
R6
和
R7
之
间建立
IBGP
邻居。
要求
EBGP
邻居使用直连接口建立邻居,
IBGP
邻居使用环回口建立邻居。
步骤
1
:在
R1-R2
上配置
EBGP
,建立并使能邻居关系
分析:
R2
上创建
BGP
进程运行在
AS 64512
中,联盟
ID
为
2
,
R1
和
R2
建立
EBGP
邻居,与
R3/R4/R5
建立
IBGP
邻
居,联盟内邻居
AS
为
AS 64512
R1
配置
[r1]bgp 1—
创建
BGP
并指定
AS
号
[r1-bgp]router-id 1.1.1.1—
指定
BGP
路由器
RID
[r1-bgp]peer 12.0.0.2 as-number 2—
和
R2
建立
EBGP
邻居(
EBGP
的建邻建议使用接口建邻的方式)
R2
配置:
[r2]bgp 64512—
创建
BGP
指定
AS
号为
64512
[r2-bgp]router-id 2.2.2.2—
指定
RID
[r2-bgp]confederation id 2—
声明自身处于的大的
AS
号
[r2-bgp]confederation peer-as 64513—
通告一个联盟内部的子自治系统号
(注意:配置本命令前,
需使用
confederation id
命令指定各子自治系统所属的联盟
ID
,若未指定联盟
ID
,本命令无效)
[r2-bgp]peer 12.0.0.1 as-number 1—
和
R1
建立
EBGP
邻居
步骤
2
:在
R2
和
R5
之间建立联邦内部的
EBGP
邻居,联盟内部使用小号建邻(同时由于是联盟内部的
EBGP
建
邻,所以仍然推荐使用环回建邻)
[r2-bgp]peer 172.16.0.5 as-number 64513
[r2-bgp]peer 172.16.0.5 connect-interface LoopBack 1—
使用环回建邻需要更改更新源
[r2-bgp]peer 172.16..0.5 ebgp-max-hop—
改变传递的
TTL
值(联盟内部同样遵循值传一条的原则)
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.0.2 as-number 64512
[r5-bgp]peer 172.16.0.2 connect-interface LoopBack 1
[r5-bgp]peer 172.16.0.2 ebgp-max-hop
![](https://i-blog.csdnimg.cn/blog_migrate/3ddb0b8c2efcf6c44033692f27db0ff7.png)
步骤三
—
联盟内部建立全连接的
IBGP
邻居
R2
配置:
[r2-bgp]peer 172.16.0.3 as-number 64512 —
和
R3
建邻
[r2-bgp]peer 172.16.0.3 connect-interface LoopBack 1—IBGP
使用环回建邻,更改更新源
[r2-bgp]peer 172.16.0.4 as-number 64512—
和
R4
建邻
[r2-bgp]peer 172.16.0.4 connect-interface LoopBack 1
R3
配置:
[r3-bgp]peer 172.16.0.2 as-number 64512
[r3-bgp]peer 172.16.0.2 connect-interface LoopBack 1
[r3-bgp]peer 172.16.0.4 as-number 64512
[r3-bgp]peer 172.16.0.4 connect-interface LoopBack 1
R4
配置:
[r4-bgp]peer 172.16.0.2 as-number 64512
[r4-bgp]peer 172.16.0.2 connect-interface LoopBack 1
[r4-bgp]peer 172.16.0.3 as-number 64512
[r4-bgp]peer 172.16.0.3 connect-interface LoopBack 1
![](https://i-blog.csdnimg.cn/blog_migrate/047ea07aad297053e69e6a87bdde4c0c.png)
同时
R4
还需要和
R7
建立
EBGP
邻居
[r4-bgp]confederation id 2
[r4-bgp]confederation peer-as 64513
[r4-bgp]peer 172.16.0.7 as-number 64513
[r4-bgp]peer 172.16.0.7 ebgp-max-hop
[r4-bgp]peer 172.16.0.7 connect-interface LoopBack 1
下面路由器配置思路一致
R5
配置:
bgp 64513
router-id 5.5.5.5
confederation id 2
confederation peer-as 64512
peer 172.16.0.2 as-number 64512
peer 172.16.0.2 ebgp-max-hop 255
peer 172.16.0.2 connect-interface LoopBack1
peer 172.16.0.6 as-number 64513
peer 172.16.0.6 connect-interface LoopBack1
peer 172.16.0.7 as-number 64513
peer 172.16.0.7 connect-interface LoopBack1
R6
配置:
bgp 64513
peer 172.16.0.5 as-number 64513
peer 172.16.0.5 connect-interface LoopBack1
peer 172.16.0.7 as-number 64513
peer 172.16.0.7 connect-interface LoopBack1
R7
配置:
bgp 64513
router-id 7.7.7.7
confederation id 2
confederation peer-as 64512
peer 78.0.0.2 as-number 3
peer 172.16.0.4 as-number 64512
peer 172.16.0.4 ebgp-max-hop 255
peer 172.16.0.4 connect-interface LoopBack1
peer 172.16.0.5 as-number 64513
peer 172.16.0.5 connect-interface LoopBack1
peer 172.16.0.6 as-number 64513
peer 172.16.0.6 connect-interface LoopBack1
![](https://i-blog.csdnimg.cn/blog_migrate/f086af22391fd0f2aaa0b098cfb07dc8.png)
BGP
配置完成
三、
BGP
宣告网段
分析:
AS1
中存在两个环回,一个地址为
192.168.1.0/24
,该地址不能在任何协议中宣告;
AS3
中存在两个环回,一个地址为
192.168.2.0/24
,该地址不能在任何协议中宣告,最终要求这两个环回可
以
ping
通;
针对上述情况需要做隧道,
GRE
或者
MGRE
都可以,在这里以
GRE
为例。其他没特殊要求的网段则正常宣
告。
备注:这里只
BGP
发布用户网段,如果骨干链路需要在
BGP
中通告,那么按照路由表中记录宣告即可,同时
用来建邻
BGP
邻居的环回一般不需要进行宣告
例:
R2
宣告
[r2-bgp]network 172.16.2.0 24
[r2-bgp]network 23.0.0.0 24—
这里只宣告
R2
用户网段和
R2-R3
相连骨干
R3
宣告
[r3-bgp]network 172.16.3.0 24
...
R1
路由器上学习到的
BGP
路由
PS
:为了测试需要宣告
12.0.0.0/24
和
78.0.0.0/24
网段,否则直接
PING
将没有回包路由
四、
AS1
和
AS3
环回互通
![](https://i-blog.csdnimg.cn/blog_migrate/e9f98dedd4ec8d41cfde2a8b7225edf2.png)
需要建立
VPN
隧道
—
这里使用
GRE
R1
上创建隧道
这里隧道使用
10.0.0.0/24
网段,或者任取一个新网段也可以。
interface Tunnel0/0/0
description 78.0.0.2
ip address 10.0.0.1 255.255.255.0
tunnel-protocol gre
source 12.0.0.1
R8
配置:
interface Tunnel0/0/0
ip address 10.0.0.2 255.255.255.0
tunnel-protocol gre
source 78.0.0.2
destination 12.0.0.1
为了使全网可达,又不能宣告
AS1-3
的环回,就只能写一条静态让目标下一跳指向
Tunnel
隧道
[r1]ip route-static 192.168.2.0 24 Tunnel 0/0/0
[r8]ip route-static 192.168.1.0 24 Tunnel 0/0/0
测试:
![](https://i-blog.csdnimg.cn/blog_migrate/dd3f87402ed36b6eada9ba06b646c39f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/eb880aa761f04487cbd0c5f3c8cab128.png)