实验拓扑以及实验目的
实验思路:
分析拓扑图可以知道,要想基于BGP实现可以访问每个环回地址,那么我们需要做联邦和反射。很明显联邦已经展现出来了,我们选择R3和R6做反射比较合适,对于这个图来说,RR的两边连接的都是对等体,RR从ENGP对等体学来的路由会发给所有客户,非客户。所以只需要随便指认一个路由器为客户即可。
实验步骤:
IP地址的划分
AS2:
把172.16.0.0 16 一分为二,一个给AS64512 一个给AS64513
因为区域间的骨干链路自己给,我们就用路由器编号直接给链路命名即可,掩码长度为24.那么64512里就需要三个环回两个链路的网段,我们直接把0.0网段划分彻底给两个链路使用。之后给环回配24位的环回在总共网段中挑选即可,我这里用的三个是路由器的编号对应的。
配置IP地址
[Huawei]sys R1
[R1]int g 0/0/0
[R1-GigabitEthernet0/0/0]ip address 12.1.1.1 24
Jul 29 2023 17:00:04-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[R1-GigabitEthernet0/0/0]int l 0
[R1-LoopBack0]ip address 192.168.1.1 24
[R1-LoopBack0]int l 1
[R1-LoopBack1]ip address 1.1.1.1 24
[Huawei]sys R2
[R2]int g 0/0/0
[R2-GigabitEthernet0/0/0]ip address 12.1.1.2 24
[R2-GigabitEthernet0/0/0]int g 0/0/1
[R2-GigabitEthernet0/0/1]ip address 172.16.0.1 30
[R2-GigabitEthernet0/0/1]int g 0/0/2
[R2-GigabitEthernet0/0/2]ip address 25.1.1.2 24
[R2-GigabitEthernet0/0/2]int l 0
[R2-LoopBack0]ip address 172.16.2.1 24
[Huawei]sys R3
[R3]int g 0/0/0
[R3-GigabitEthernet0/0/0]ip address 172.16.0.2 30
[R3-GigabitEthernet0/0/0]int g 0/0/1
[R3-GigabitEthernet0/0/1]ip address 172.16.0.5 30
[R3-GigabitEthernet0/0/1]int l 0
[R3-LoopBack0]ip address 172.16.3.1 24
[Huawei]sys R4
[R4]int g 0/0/0
[R4-GigabitEthernet0/0/0]ip address 172.16.0.6 30
[R4-GigabitEthernet0/0/0]int g 0/0/1
[R4-GigabitEthernet0/0/1]ip address 47.1.1.4 24
[R4-GigabitEthernet0/0/1]int l 0
[R4-LoopBack0]ip address 172.16.4.1 24
[Huawei]sys R5
[R5]int g 0/0/0
[R5-GigabitEthernet0/0/0]ip address 25.1.1.5 24
[R5-GigabitEthernet0/0/0]int g 0/0/1
[R5-GigabitEthernet0/0/1]ip address 172.16.128.1 30
[R5-GigabitEthernet0/0/1]int l 0
[R5-LoopBack0]ip address 172.16.155.1 24
[Huawei]sys R6
[R6-GigabitEthernet0/0/1]int g 0/0/0
[R6-GigabitEthernet0/0/0]ip address 172.16.128.1 30
[R6-GigabitEthernet0/0/0]int g 0/0/1
[R6-GigabitEthernet0/0/1]ip address 172.16.128.5 30
[R6-GigabitEthernet0/0/1]int l 0
[R6-LoopBack0]ip address 172.16.166.1 24
[Huawei]sys R7
[R7]int g 0/0/1
[R7-GigabitEthernet0/0/1]ip address 172.16.128.6 30
[R7-GigabitEthernet0/0/1]int g 0/0/2
[R7-GigabitEthernet0/0/2]ip address 78.1.1.7 24
[R7-GigabitEthernet0/0/2]int g 0/0/0
[R7-GigabitEthernet0/0/0]ip address 47.1.1.7 24
[R7-GigabitEthernet0/0/0]int l 0
[R7-LoopBack0]ip address 172.16.177.1 24
[Huawei]sys R8
[R8]int g 0/0/0
[R8-GigabitEthernet0/0/0]ip address 78.1.1.8 24
[R8-GigabitEthernet0/0/0]int l 0
[R8-LoopBack0]ip address 192.168.2.1 24
[R8-LoopBack0]int l 1
[R8-LoopBack1]ip address 8.8.8.8 24
起OSPF
AS64512:
[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.2.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 172.16.0.1 0.0.0.0
[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.3.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 172.16.0.2 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 172.16.0.5 0.0.0.0
[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1]ar
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]ne
[R4-ospf-1-area-0.0.0.0]network 172.16.4.0 0.0.0.255
[R4-ospf-1-area-0.0.0.0]ne
[R4-ospf-1-area-0.0.0.0]network 172.16.0.6 0.0.0.0
AS64513:
[R5]ospf 1 router-id 5.5.5.5
[R5-ospf-1]area 0
[R5-ospf-1-area-0.0.0.0]ne
[R5-ospf-1-area-0.0.0.0]network 172.16.155.0 0.0.0.255
[R5-ospf-1-area-0.0.0.0]network 172.16.128.1 0.0.0.0
[R6]ospf 1 router-id 6.6.6.6
[R6-ospf-1]area 0
[R6-ospf-1-area-0.0.0.0]ne
[R6-ospf-1-area-0.0.0.0]network 172.16.166.0 0.0.0.255
[R6-ospf-1-area-0.0.0.0]network 172.16.128.2 0.0.0.0
[R6-ospf-1-area-0.0.0.0]network 172.16.128.5 0.0.0.0
[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.177.0 0.0.0.255
[R7-ospf-1-area-0.0.0.0]network 172.16.128.6 0.0.0.0
在小区域里面互相ping一下保障OSPF的协议正常
起BGP:
先配置静态路由
[R1]ip route-static 172.16.2.1 24 12.1.1.2
[R2]ip route-static 192.168.1.1 24 12.1.1.1
[R7]ip route-static 192.168.2.1 24 78.1.1.8
[R8]ip route-static 172.6.177.1 24 78.1.1.7
建立EBGP关系
AS1-AS2
[R1]bgp 1
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 172.16.2.1 as-number 2
[R1-bgp]peer 172.16.2.1 connect-interface LoopBack 0
[R1-bgp]peer 172.16.2.1 ebgp-max-hop 2
[R2]bgp 64512
[R2-bgp]router-id 2.2.2.2
[R2-bgp]confederation id 2
[R2-bgp]peer 192.168.1.1 as-number 1
[R2-bgp]peer 192.168.1.1 connect-interface LoopBack 0
[R2-bgp]peer 192.168.1.1 ebgp-max-hop 2
AS2-AS3
[R7]bgp 64513
[R7-bgp]confederation id 2
[R7-bgp]peer 192.168.2.1 as-number 3
[R7-bgp]peer 192.168.2.1 connect-interface LoopBack 0
[R7-bgp]peer 192.168.2.1 ebgp-max-hop 2
[R8]bgp 3
[R8-bgp]peer 172.16.177.1 as-number 2
[R8-bgp]peer 172.16.177.1 connect-interface LoopBack 0
[R8-bgp]peer 172.16.177.1 ebgp-max-hop 2
使用环回做目标IP地址的时候注意一定要修改TTL为2,否则会导致环回建邻失败。
AS2内部建EBGP邻居关系
R2-R4:
[R2-bgp]peer 172.16.3.1 as-number 64512
[R2-bgp]peer 172.16.3.1 connect-interface LoopBack 0
[R2-bgp]peer 172.16.3.1 next-hop-local
[R3]bgp 64512
[R3-bgp]confederation id 2
[R3-bgp]peer 172.16.2.1 as-number 64512
[R3-bgp]peer 172.16.2.1 connect-interface LoopBack 0
[R3-bgp]peer 172.16.4.1 as-number 64512
[R3-bgp]peer 172.16.4.1 connect-interface LoopBack 0
[R3-bgp]peer 172.16.4.1 next-hop-local
[R4-bgp]peer 172.16.3.1 as-number 64512
[R4-bgp]peer 172.16.3.1 connect-interface LoopBack 0
[R4-bgp]peer 172.16.3.1 next-hop-local
R5-R7
[R7]bgp 64513
[R7-bgp]confederation id 2
[R7-bgp]peer 172.16.166.1 as-number 64513
[R7-bgp]peer 172.16.166.1 connect-interface LoopBack 0
[R7-bgp]peer 172.16.166.1 next-hop-local
[R6]bgp 64513
[R6-bgp]confederation id 2
[R6-bgp]peer 172.16.177.1 as-number 64513
[R6-bgp]peer 172.16.177.1 connect-interface LoopBack 0
[R6-bgp]peer 172.16.177.1 next-hop-local
[R6-bgp]peer 172.16.155.1 as-number 64513
[R6-bgp]peer 172.16.155.1 connect-interface LoopBack 0
[R6-bgp]peer 172.16.155.1 next-hop-local
[R5]bgp 64513
[R5-bgp]confederation id 2
[R5-bgp]peer 172.16.166.1 as-number 64513
[R5-bgp]peer 172.16.166.1 connect-interface LoopBack 0
[R5-bgp]peer 172.16.166.1 next-hop-local
R2和5 R4和R7建EBGP的时候需要注意,建邻之前需要互相指认
切记不可忘记编写静态路由指向两端的环回地址
[R2]bgp 64512
[R2-bgp]confederation peer-as 64513
[R2-bgp]peer 172.16.155.1 as-number 64513
[R2-bgp]peer 172.16.155.1 connect-interface LoopBack 0
[R2-bgp]peer 172.16.155.1 ebgp-max-hop 2
[R5-bgp]confederation peer-as 64512
[R5-bgp]peer 172.16.2.1 as-number 64512
[R5-bgp]peer 172.16.2.1 connect-interface l 0
[R5-bgp]peer 172.16.2.1 ebgp-max-hop 2
[R7]ip route-static 172.16.4.0 24 47.1.1.4
[R7]bgp 64513
[R7-bgp]confederation peer-as 64512
[R7-bgp]peer 172.16.4.1 as-number 64512
[R7-bgp]peer 172.16.4.1 connect-interface l 0
[R7-bgp]peer 172.16.4.1 ebgp-max-hop 2
[R4]ip route-static 172.16.177.0 24 47.1.1.7
[R4]bgp 64513
Error: BGP is already running. The AS is 64512.
[R4]bgp 64512
[R4-bgp]confederation peer-as 64513
[R4-bgp]peer 172.16.177.1 as-number 64513
[R4-bgp]peer 172.16.177.1 connect-interface l 0
[R4-bgp]pe 172.16.177.1 ebgp-max-hop 2
查看路由器的BGP邻居就可以发现已经全部建邻居了。
配置路由反射器:
R3
[r3]bgp 64512
[r3-bgp]peer 172.16.2.1 reflect-client
R6
[r6]bgp 64513
[r6-bgp]peer 172.16.177.1 reflect-client
查看R1,R8的BGP表
目前除了两个192.168.0.0网段都可以互相访问了。
减少路由条目
R2
[r2]ip route-static 172.16.0.0 21 NULL 0
[r2]bgp 64512
[r2-bgp]network 172.16.0.0 21
R7
[r7]ip route-static 172.16.0.0 22 NULL 0
[r7]bgp 64513
[r7-bgp]network 172.16.0.0 21
未宣告网段的通讯
可以通过隧道来构建,建立一个GRE隧道,并且配一个静态路由即可
R1
[r1]int t0/0/0
[r1-Tunnel0/0/0]ip a 192.168.10.1 24
[r1-Tunnel0/0/0]tunnel-protocol gre
[r1-Tunnel0/0/0]source 10.0.0.1
[r1-Tunnel0/0/0]destination 11.0.0.1
[r1]ip route-static 192.168.1.0 24 99.0.0.2
R8
[r8]int t0/0/0
[r8-Tunnel0/0/0]ip a 192.168.10.2 24
[r8-Tunnel0/0/0]tunnel-protocol gre
[r8-Tunnel0/0/0]source 11.0.0.1
[r8-Tunnel0/0/0]destination 10.0.0.1
[r8]ip route-static 192.168.2.0 24 99.0.0.1