实验拓扑图
AS2 地址划分(基于172.16.0.0/16划分)
172.16.0.0/30 ---p2p
172.16.0.128/29 ---MA
环回0 :172.16.1.0/24 ---172.16.1.2/32 172.16.1.3/32 172.16.1.4/32 ... ---建邻环回
环回1:172.16.2.1/24、 172.16.3.1/24 、172.16.4.1/24 .... ----用户环回
172.16.2.0/24
172.16.7.0/24
物理地址和环回配置
检测
在OSPF中宣告
[r2]ospf 1 router-id 2.2.2.2
[r2-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255
[r3]ospf 1 router-id 3.3.3.3
[r3]-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255
[r4]ospf 1 router-id 4.4.4.4
[r4]ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255
[r5]ospf 1 router-id 5.5.5.5
[r5]-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255
[r6]ospf 1 router-id 6.6.6.6
[r6]-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255
[r7]ospf 1 router-id 7.7.7.7
[r7]-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.25
检测
<r2>display ospf peer brief
OSPF Process 1 with Router ID 172.16.1.2
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 3.3.3.3 Full
0.0.0.0 GigabitEthernet0/0/2 5.5.5.5 Full
----------------------------------------------------------------------------
<r2>
<r3>display ospf peer brief
OSPF Process 1 with Router ID 3.3.3.3
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 172.16.1.2 Full
0.0.0.0 GigabitEthernet0/0/0 4.4.4.4 Full
----------------------------------------------------------------------------
<r3>
<r4>display ospf peer brief
OSPF Process 1 with Router ID 4.4.4.4
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/0 3.3.3.3 Full
0.0.0.0 GigabitEthernet0/0/2 7.7.7.7 Full
----------------------------------------------------------------------------
<r4>
<r5>display ospf peer brief
OSPF Process 1 with Router ID 5.5.5.5
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/2 172.16.1.2 Full
0.0.0.0 GigabitEthernet0/0/0 6.6.6.6 Full
----------------------------------------------------------------------------
<r5>
<r6>display ospf peer brief
OSPF Process 1 with Router ID 6.6.6.6
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/0 5.5.5.5 Full
0.0.0.0 GigabitEthernet0/0/1 7.7.7.7 Full
----------------------------------------------------------------------------
<r6>
<r7>display ospf peer brief
OSPF Process 1 with Router ID 7.7.7.7
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 6.6.6.6 Full
0.0.0.0 GigabitEthernet0/0/2 4.4.4.4 Full
----------------------------------------------------------------------------
<r7>
在r2、3、4、5、6、7中更改OSPF协议的类型
[r2-LoopBack1]ospf network-type broadcast
[r3-LoopBack1]ospf network-type broadcast
. . .
ospf路由表
开始配置BGP
[r1]bgp 1
[r1-bgp]router-id 1.1.1.1
[r1-bgp]peer 12.0.0.2 as-number 2
[r2]bgp 64512 ---写在自己所在的小的AS号
[r2-bgp]router-id 2.2.2.2
[r2-bgp]confederation id 2 ---联邦ID(说明自己的大AS号)
[r2-bgp]confederation peer-as 64513 ---说明这个也是AS2中的小AS号
[r2-bgp]peer 12.0.0.1 as
[r2-bgp]peer 12.0.0.1 as-number 1
[r2-bgp]peer 172.16.1.3 as-number 64512
[r2-bgp]peer 172.16.1.3 connect-interface LoopBack 0---使用环回建立必须修改更
新源地址
[r2-bgp]peer 172.16.1.5 as-number 64513
[r2-bgp]peer 172.16.1.5 connect-interface LoopBack 0
[r2-bgp]peer 172.16.1.5 ebgp-max-hop 2 TTL默认为1,改大一点(跳数)
[r3]bgp 64512
[r3-bgp]router-id 3.3.3.3
[r3-bgp]confederation id 2
[r3-bgp]peer 172.16.1.2 as-number 64512
[r3-bgp]peer 172.16.1.2 connect-interface l0
[r3-bgp]peer 172.16.1.4 as-number 64512
[r3-bgp]peer 172.16.1.4 connect-interface l0
[r4]bgp 64512
[r4-bgp]router-id 4.4.4.4
[r4-bgp]confederation id 2
[r4-bgp]confederation peer-as 64513
[r4-bgp]peer 172.16.1.3 as 64512
[r4-bgp]peer 172.16.1.3 connect-interface LoopBack 0
[r4-bgp]peer 172.16.1.7 as-number 64513
[r4-bgp]peer 172.16.1.7 connect-interface LoopBack 0
[r4-bgp]peer 172.16.1.7 ebgp-max-hop 2
[r4-bgp]
[r5]bgp 64513
[r5-bgp]router-id 5.5.5.5
[r5-bgp]confederation id 2
[r5-bgp]compare-different-as-med
[r5-bgp]confederation peer-as 64512
[r5-bgp]peer 172.16.1.2 as-number 64512
[r5-bgp]peer 172.16.1.2 connect-interface l0
[r5-bgp]peer 172.16.1.2 ebgp-max-hop 2
[r5-bgp]peer 172.16.1.6 as-number 64513
[r5-bgp]peer 172.16.1.6 connect-interface l0
[r5-bgp]
[r6]bgp 64513
[r6-bgp]router-id 6.6.6.6
[r6-bgp]confederation id 2
[r6-bgp]confederation peer-as 64512
[r6-bgp]peer 172.16.1.5 as-number 64513
[r6-bgp]peer 172.16.1.5 connect-interface l0
[r6-bgp]peer 172.16.1.7 as-number 64513
[r6-bgp]peer 172.16.1.7 connect-interface LoopBack 0
[r6-bgp]
[r7]bgp 64513
[r7-bgp]router-id 7.7.7.7d
[r7-bgp]confederation id 2
[r7-bgp]confederation peer-as 64512
[r7-bgp]peer 172.16.1.4 as-number 64512
[r7-bgp]peer 172.16.1.4 connect-interface l0
[r7-bgp]peer 172.16.1.4 ebgp-max-hop 2
[r7-bgp]peer 172.16.1.6 as-number 64513
[r7-bgp]peer 172.16.1.6 connect-interface l0
[r7-bgp]peer 78.0.0.2 as-number 3
[r7-bgp]
[r8]bgp 3
[r8-bgp]router-id 8.8.8.8
[r8-bgp]peer 78.0.0.1 as-number 2
[r8-bgp]
检查建邻情况
BGP建邻完成
BGP中宣告环回
[r1]bgp 1
[r1-bgp]network 1.1.1.0 24
让设备传递路由是修改下一跳属性
[r2-bgp]peer 172.16.1.3 next-hop-local
[r2-bgp]peer 172.16.1.5 next-hop-local
已优
[r3-bgp]peer 172.16.1.4 reflect-client ---将r4设置为r3的客户,r4就学到了路由
[r6-bgp]peer 172.16.1.7 reflect-client ---将r7设置为r6的客户
此时r7学到了两条路由,一条已优,一条未优
通过以下命令可查看那条路由是哪台发的
<r7>display bgp routing-table peer 172.16.1.4 received-routes
<r7>display bgp routing-table peer 172.16.1.6 received-routes
由此可看出r4给r7的路由被优化了
r8也学到了
接下来宣告r8的环回
[r8]bgp 3
[r8-bgp]net
[r8-bgp]network 8.8.8.0 24
宣告后r4、r6学到的是不优的,需要更改下一跳
[r7-bgp]peer 172.16.1.4 next-hop-local
[r7-bgp]peer 172.16.1.6 next-hop-local
r8发出的路由,r7和r4会学到,r4是r3的客户吗,r3学到了会给自己的非客户r1,另一条同理
1.1.1.1和8.8.8.8.8也是通了
接下来让r1和r8学到AS2的路由
[r2]ip route-static 172.16.0.0 21 NULL 0 --空接口防环
[r2]bgp 64512
[r2-bgp]network 172.16.0.0 21
[r2-bgp]
宣告
[r7]bgp 64513
[r7-bgp]net
[r7-bgp]network 172.16.2.0 24
[r7-bgp]network 172.16.3.0 24
[r7-bgp]network 172.16.4.0 24
[r7-bgp]network 172.16.5.0 24
[r7-bgp]network 172.16.6.0 24
[r7-bgp]network 172.16.7.0 24
抑制明细,自动生成空接口
[r7-bgp]aggregate 172.16.0.0 21 detail-suppressed
结束