R1
[r1]int g0/0/0
[r1-GigabitEthernet0/0/0]ip add 12.1.1.1 24
[r1-GigabitEthernet0/0/0]int loopback0
[r1-LoopBack0]ip add 192.168.1.1 24
[r1-LoopBack0]int loopback1
[r1-LoopBack1]ip add 192.168.2.1 24
[r1-LoopBack1]int loopback3
[r1-LoopBack3]ip add 123.1.1.1 32
R2
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]ip add 12.1.1.2 24
[r2-GigabitEthernet0/0/0]int g0/0/1
[r2-GigabitEthernet0/0/1]ip add 23.1.1.2 24
[r2-GigabitEthernet0/0/1]int loopback0
[r2-LoopBack0]ip add 2.2.2.2 24
[r2-LoopBack0]int loopback1
[r2-LoopBack1]ip add 123.1.1.2 32
R3
[r3]int g0/0/0
[r3-GigabitEthernet0/0/0]ip add 23.1.1.1 24
[r3-GigabitEthernet0/0/0]int g0/0/1
[r3-GigabitEthernet0/0/1]ip add 34.1.1.1 24
[r3-GigabitEthernet0/0/1]int loopback0
[r3-LoopBack0]ip add 3.3.3.3 24
[r3-LoopBack0]int loopback1
[r3-LoopBack1]ip add 123.1.1.3 32
R4
[r4]int g0/0/0
[r4-GigabitEthernet0/0/0]ip add 34.1.1.2 24
[r4-GigabitEthernet0/0/0]int g0/0/1
[r4-GigabitEthernet0/0/1]ip add 45.1.1.2 24
[r4-GigabitEthernet0/0/1]int loop 0
[r4-LoopBack0]ip add 4.4.4.4 24
[r4-LoopBack0]int loop 1
[r4-LoopBack1]ip add 123.1.1.4 32
R5
[r5]int g0/0/0
[r5-GigabitEthernet0/0/0]ip add 45.1.1.1 24
[r5-GigabitEthernet0/0/0]int g0/0/1
[r5-GigabitEthernet0/0/1]ip add 56.1.1.1 24
[r5-GigabitEthernet0/0/1]int loop 0
[r5-LoopBack0]ip add 5.5.5.5 24
[r5-LoopBack0]int loop 1
[r5-LoopBack1]ip add 123.1.1.5 32
R6
[r6]int g0/0/0
[r6-GigabitEthernet0/0/0]ip add 56.1.1.2 24
[r6-GigabitEthernet0/0/0]int g0/0/1
[r6-GigabitEthernet0/0/1]ip add 67.1.1.2 24
[r6-GigabitEthernet0/0/1]int loop 0
[r6-LoopBack0]ip add 6.6.6.6 24
[r6-LoopBack0]int loop 1
[r6-LoopBack1]ip add 123.1.1.6 32
R7
[r7]int g0/0/0
[r7-GigabitEthernet0/0/0]ip add 67.1.1.1 24
[r7-GigabitEthernet0/0/0]int loopback0
[r7-LoopBack0]ip add 172.16.1.1 24
[r7-LoopBack0]int loop1
[r7-LoopBack1]ip add 172.16.2.1 24
[r7-LoopBack1]int loop2
[r7-LoopBack2]ip add 123.1.1.7 32
注:以上4个接口在IGP中不宣告
R1
[r1]rip 1
[r1-rip-1]version 2
[r1-rip-1]network 123.0.0.0
[r1-rip-1]network 192.168.1.0
[r1-rip-1]network 192.168.2.0
[r1-rip-1]network 12.0.0.0
R2
[r2]rip 1
[r2-rip-1]version 2
[r2-rip-1]network 12.0.0.0
[r2-rip-1]network 2.0.0.0
[r2-rip-1]network 123.0.0.0
R3
[r3]ospf 1 router-id 3.3.3.3
[r3-ospf-1]area 0
[r3-ospf-1-area-0.0.0.0]network 34.1.1.1 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 123.1.1.3 0.0.0.0
R4
[r4]ospf 1 router-id 4.4.4.4
[r4-ospf-1]area 0
[r4-ospf-1-area-0.0.0.0]network 0.0.0.0 255.255.255.255
R5
[r5]ospf 1 router-id 5.5.5.5
[r5-ospf-1]area 0
[r5-ospf-1-area-0.0.0.0]network 45.1.1.1 0.0.0.0
[r5-ospf-1-area-0.0.0.0]network 5.5.5.5 0.0.0.0
[r5-ospf-1-area-0.0.0.0]network 123.1.1.5 0.0.0.0
R6
[r6]ospf 1 router-id 6.6.6.6
[r6-ospf-1]area 0
[r6-ospf-1-area-0.0.0.0]network 6.6.6.6 0.0.0.0
[r6-ospf-1-area-0.0.0.0]network 123.1.1.6 0.0.0.0
[r6-ospf-1-area-0.0.0.0]network 67.1.1.2 0.0.0.0
R7
[r7]ospf 1 router-id 7.7.7.7
[r7-ospf-1]area 0
[r7-ospf-1-area-0.0.0.0]network 0.0.0.0 255.255.255.255
R1
[r1]bgp 100
[r1-bgp]router-id 1.1.1.1
[r1-bgp]peer 123.1.1.2 as-number 100
[r1-bgp]peer 123.1.1.2 connect-interface LoopBack 3
R2(R2与R3使用物理接口直接建邻)
[r2]bgp 100
[r2-bgp]router-id 2.2.2.2
[r2-bgp]peer 123.1.1.1 as-number 100
[r2-bgp]peer 123.1.1.1 connect-interface LoopBack 1
[r2-bgp]peer 23.1.1.1 as-number 101
R3
[r3]bgp 101
[r3-bgp]peer 23.1.1.2 as-number 100
[r3-bgp]peer 123.1.1.4 as-number 101
[r3-bgp]peer 123.1.1.4 connect-interface LoopBack 1
[r3-bgp]peer 123.1.1.5 as-number 101
[r3-bgp]peer 123.1.1.5 connect-interface LoopBack 1
R4
[r4]bgp 101
[r4-bgp]peer 123.1.1.3 as-number 101
[r4-bgp]peer 123.1.1.3 connect-interface LoopBack 1
[r4-bgp]peer 123.1.1.5 as-number 101
[r4-bgp]peer 123.1.1.5 connect-interface LoopBack 1
R5(R5和R6使用环回接口建邻)
前提:R5和R6的环回可以相互ping通
所以先在R5和R6上写条静态路由
[r5]ip route-static 123.1.1.6 32 56.1.1.2
[r6]ip route-static 123.1.1.5 32 56.1.1.1
再使用环回建邻
注:由于EBGP之间的TTL默认为1,所以若使用环回建邻就必须修改TTL值
[r5]bgp 101
[r5-bgp]peer 123.1.1.3 as-number 101
[r5-bgp]peer 123.1.1.3 connect-interface LoopBack 1
[r5-bgp]peer 123.1.1.4 as-number 101
[r5-bgp]peer 123.1.1.4 connect-interface LoopBack 1
[r5-bgp]peer 123.1.1.6 as-number 102
[r5-bgp]peer 123.1.1.6 connect-interface LoopBack 1
[r5-bgp]peer 123.1.1.6 ebgp-max-hop 2
R6
[r6]bgp 102
[r6-bgp]peer 123.1.1.5 as-number 101
[r6-bgp]peer 123.1.1.5 connect-interface LoopBack 1
[r6-bgp]peer 123.1.1.5 ebgp-max-hop 2
[r6-bgp]peer 123.1.1.7 as-number 102
[r6-bgp]peer 123.1.1.7 connect-interface LoopBack 1
R7
[r7]bgp 102
[r7-bgp]peer 123.1.1.6 as-number 102
[r7-bgp]peer 123.1.1.6 connect-interface LoopBack 2
建邻配置完成后,查看看邻居关系
[r7]display bgp peer
<r1>display tcp status
R1
R2
R3
R4
R5
R6
R7
[r3]int l0
[r3-LoopBack0]ospf network-type broadcast
[r4]int l0
[r4-LoopBack0]ospf network-type broadcast
[r5]int l0
[r5-LoopBack0]ospf network-type broadcast
[r6]int l0
[r6-LoopBack0]ospf network-type broadcast
[r7]int l0
[r7-LoopBack0]ospf network-type broadcast
[r7-LoopBack0]int l1
[r7-LoopBack1]ospf network-type broadcast
运行BGP的设备均宣告相同路由
使用不标准的汇总方式
[r1]ip route-static 192.168.0.0 22 NULL 0
[r1]bgp 100
[r1-bgp]network 192.168.0.0 22
[r1-bgp]network 192.168.1.0 24
此时我们会发现:当路由传到R4上时不优,所以我们就要修改下一跳
[r3]bgp 101
[r3-bgp]peer 123.1.1.4 next-hop-local
[r3-bgp]peer 123.1.1.5 next-hop-local
[r6-bgp]peer 123.1.1.7 next-hop-local
修改完之后,我们发现,路由优了
这样利用BGP的宣告特性,我们就可以实现:R1上有两个环回分别为192.168.1.0/24和192.168.2.0/24,只允许学到汇总和1.0
我们在R7上就可以看到效果
使用标准的汇总方式
我们可以使用抑制列表
第一步:先逐一宣告
[r7]bgp 102
[r7-bgp]network 172.16.1.0 24
[r7-bgp]network 172.16.2.0 24
此时我们会发现:当路由传到R4上时不优,所以我们就要修改下一跳,同理:
[r5]bgp 101
[r5-bgp]peer 123.1.1.4 next-hop-local
[r5-bgp]peer 123.1.1.3 next-hop-local
[r2]bgp 100
[r2-bgp]peer 123.1.1.1 next-hop-local
修改完之后,我们发现,路由优了
第二步:再在更新源路由器上进行聚合配置,会自动产生空接口防环路由
[r7]bgp 102
[r7-bgp]agg
[r7-bgp]aggregate 172.16.0.0 22
当我们敲完上面的命令后,我们可以看到此聚合路由和所有明细路由都被传了出去
[r7]ip ip-prefix aa permit 172.16.1.0 24
[r7]route-policy aa permit node 10
Info: New Sequence of this List.
[r7-route-policy]if-match ip-prefix aa
[r7-route-policy]q
[r7]bgp 102
[r7-bgp]aggregate 172.16.0.0 22 suppress-policy aa
做完抑制列表后,我们发现:只有2.0可以通过