如图所示配置IP
1、在AS 2区域配置ospf协议
在R2上配置
[r2]ospf 1 router-id 2.2.2.2
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.0]network 172.16.1.1 0.0.0.0
[r2-ospf-1-area-0.0.0.0]network 172.16.1.21 0.0.0.0
[r2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.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 172.16.1.2 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 172.16.1.5 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 172.16.3.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 172.16.1.6 0.0.0.0
[r4-ospf-1-area-0.0.0.0]network 172.16.1.9 0.0.0.0
[r4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[r4-ospf-1-area-0.0.0.0]network 172.16.4.4 0.0.0.0
在R5上配置
[r5]ospf 1 router-id 5.5.5.5
[r5-ospf-1]area 0
[r5-ospf-1-area-0.0.0.0]network 172.16.1.22 0.0.0.0
[r5-ospf-1-area-0.0.0.0]network 172.16.1.17 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 172.16.5.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 172.16.1.18 0.0.0.0
[r6-ospf-1-area-0.0.0.0]network 172.16.1.13 0.0.0.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 172.16.6.6 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 172.16.1.14 0.0.0.0
[r7-ospf-1-area-0.0.0.0]network 172.16.1.10 0.0.0.0
[r7-ospf-1-area-0.0.0.0]network 7.7.7.7 0.0.0.0
[r7-ospf-1-area-0.0.0.0]network 172.16.7.7 0.0.0.0
查看ospf邻居
如图我们可以看到所有路由邻居都full了
配置BGP
在R1上配置EBGP
[r1]bgp 1
[r1-bgp]peer 12.1.1.2 as-number 2
在R2上配置EBGP
[r2]bgp 64512
[r2-bgp]confederation id 2
[r2-bgp]peer 12.1.1.1 as-number 1
[r2-bgp]peer 3.3.3.3 as-number 64512
[r2-bgp]peer 3.3.3.3 connect-interface l0
[r2-bgp]peer 3.3.3.3 next-hop-local
[r2-bgp]peer 5.5.5.5 as-number 64513
[r2-bgp]peer 5.5.5.5 connect-interface lo0
[r2-bgp]peer 5.5.5.5 ebgp-max-hop
[r2-bgp]peer 5.5.5.5 next-hop-local
在R3上配置
[r3]bgp 64512
[r3-bgp]confederation id 2
[r3-bgp]peer 2.2.2.2 as-number 64512
[r3-bgp]peer 2.2.2.2 connect-interface l0
[r3-bgp]peer 4.4.4.4 as-number 64512
[r3-bgp]peer 4.4.4.4 connect-interface l0
在R4上配置
[r4]bgp 64512
[r4-bgp]confederation id 2
[r4-bgp]peer 3.3.3.3 as-number 64512
[r4-bgp]peer 3.3.3.3 connect-interface l0
[r4-bgp]peer 7.7.7.7 as-number 64513
[r4-bgp]peer 7.7.7.7 connect-interface l0
[r4-bgp]peer 7.7.7.7 next-hop-local
在R5上配置
[r5]bgp 64513
[r5-bgp]confederation id 2
[r5-bgp]peer 2.2.2.2 as-number 64512
[r5-bgp]peer 2.2.2.2 connect-interface lo0
[r5-bgp]peer 2.2.2.2 ebgp-max-hop
[r5-bgp]peer 2.2.2.2 next-hop-local
[r5-bgp]peer 6.6.6.6 as-number 64513
[r5-bgp]peer 6.6.6.6 connect-interface lo0
[r5-bgp]peer 6.6.6.6 next-hop-local
在R6上配置
[r6]bgp 64513
[r6-bgp]confederation id 2
[r6-bgp]peer 5.5.5.5 as-number 64513
[r6-bgp]peer 5.5.5.5 connect-interface lo0
[r6-bgp]peer 5.5.5.5 next-hop-local
[r6-bgp]peer 7.7.7.7 as-number 64513
[r6-bgp]peer 7.7.7.7 connect-interface lo0
[r6-bgp]peer 7.7.7.7 next-hop-local
在R7上配置
[r7]bgp 64513
[r7-bgp]confederation id 2
[r7-bgp]peer 6.6.6.6 as-number 64513
[r7-bgp]peer 6.6.6.6 connect-interface lo0
[r7-bgp]peer 6.6.6.6 next-hop-local
[r7-bgp]peer 4.4.4.4 as-number 64512
[r7-bgp]peer 4.4.4.4 connect-interface lo0
[r7-bgp]peer 4.4.4.4 next-hop-local
[r7-bgp]peer 8.8.8.8 as-number 3
[r7-bgp]peer 8.8.8.8 connect-interface lo0
[r7-bgp]peer 8.8.8.8 next-hop-local
在R8上配置
[r8]bgp 3
[r8-bgp]peer 7.7.7.7 as-number 2
[r8-bgp]peer 7.7.7.7 connect-interface lo0
[r8-bgp]peer 7.7.7.7 next-hop-local
查看bgp邻居关系
在R1上BGP宣告1.1.1.1 在R8上宣告8.8.8.8因为IBGP的水平分割,R4学不到1.1.1.1和8.8.8.8
R5学不到8.8.8.8但是可以通过R2的EBGP学到1.1.1.1(我们这里只截取R4和R5看命令为display bgp routing-table)
为了使他们学到宣告的命令我们可以使用全连接、反射器等等,这里我们使用反射器(我们在R3和R6上配置反射器,当然其他as2里面的路由器都可以做反射器自由选择)
在R3上配置反射器命令
[r3]bgp 64512
[r3-bgp]peer 4.4.4.4 reflect-client
在R6上配置反射器命令
[r6]bgp 64513
[r6-bgp]peer 7.7.7.7 reflect-client
我们在查看bgp路由表
这里我们可以看到每个路由器都学到R1和R8宣告的环回路由
测试(这里我们要带原IP)
做汇总和防环
在R2上配置
[r2]ip route-static 172.16.0.0 16 NULL 0
[r2]bgp 64512
[r2-bgp]network 172.16.0.0 16
在R7上配置
[r7]ip route-static 172.16.0.0 16 NULL 0
[r7]bgp 64513
[r7-bgp]network 172.16.0.0 16
注:不要忘了把as2里的业务网段宣告在bgp中宣告
[r3-bgp]network 172.16.0.0 16
[r4-bgp]network 172.16.0.0 16
[r5-bgp]network 172.16.0.0 16
[r6-bgp]network 172.16.0.0 16
[r7-bgp]network 172.16.0.0 16
因为R1和R8业务网段不能宣告但是要互通,所以我们只能做一个虚拟专线gre互通
在r1上配置
[r1]int Tunnel 0/0/0
[r1-Tunnel0/0/0]ip add 10.1.1.1 24
[r1-Tunnel0/0/0]tunnel-protocol gre
[r1-Tunnel0/0/0]source 1.1.1.1
[r1-Tunnel0/0/0]description 8.8.8.8
[r1]ip route-static 192.168.2.0 24 10.1.1.2
在r8上配置
[r8]int Tunnel 0/0/0
[r8-Tunnel0/0/0]ip add 10.1.1.2 24
[r8-Tunnel0/0/0]tunnel-protocol gre
[r8-Tunnel0/0/0]source 8.8.8.8
[r8-Tunnel0/0/0]description 1.1.1.1
[r8]ip route-static 192.168.1.0 24 10.1.1.1
因为协议上192.168.1.0和192.168.2.0是不可达的所有要在隧道口改源目地址
R1
[r1-Tunnel0/0/0]source 1.1.1.1
[r1-Tunnel0/0/0]destination 8.8.8.8
R8
[r8]int t0/0/0
[r8-Tunnel0/0/0]source 8.8.8.8
[r8-Tunnel0/0/0]destination 1.1.1.1
(注意:目标地址代码为:destination不要打错了)
测试
实验结束!!!