先根据拓扑图把基础的IP地址添加好。
[Huawei]sy ar1
[ar1]in g0/0/0
[ar1-GigabitEthernet0/0/0]ip add 12.1.1.1 24
[ar1-GigabitEthernet0/0/0]q
[ar1]int lo
[ar1]int LoopBack 0
[ar1-LoopBack0]ip add 1.1.1.1 32
[ar1-LoopBack0]q
[Huawei]sy ar2
[ar2]in g0/0/0
[ar2-GigabitEthernet0/0/0]ip add 12.1.1.2 24
[ar2-GigabitEthernet0/0/0]q
[ar2]in g0/0/1
[ar2-GigabitEthernet0/0/0]ip add 23.1.1.2 24
[ar2-GigabitEthernet0/0/0]q
[ar2]int lo
[ar2]int LoopBack 0
[ar2-LoopBack0]ip add 2.2.2.2 32
[ar2-LoopBack0]q
[Huawei]sy ar3
[ar3]in g0/0/0
[ar3-GigabitEthernet0/0/0]ip add 34.1.1.3 24
[ar3-GigabitEthernet0/0/0]q
[ar3]in g0/0/1
[ar3-GigabitEthernet0/0/0]ip add 23.1.1.3 24
[ar3-GigabitEthernet0/0/0]q
[ar3]int lo
[ar3]int LoopBack 0
[ar3-LoopBack0]ip add 3.3.3.3 32
[ar3-LoopBack0]q
[Huawei]sy ar4
[ar4]in g0/0/0
[ar4-GigabitEthernet0/0/0]ip add 34.1.1.4 24
[ar4-GigabitEthernet0/0/0]q
[ar4]int lo
[ar4]int LoopBack 0
[ar4-LoopBack0]ip add 4.4.4.4 32
[ar4-LoopBack0]q
AR2
[ar2]ospf router-id 2.2.2.2
[ar2-ospf-1]area 0
[ar2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[ar2-ospf-1-area-0.0.0.0]network 23.1.1.0 0.0.0.255
注意:这里不需要宣告12.1.1.0
AR3
[ar3]ospf router-id 3.3.3.3
[ar3-ospf-1]area 0
[ar3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[ar3-ospf-1-area-0.0.0.0]network 23.1.1.0 0.0.0.255
[ar3-ospf-1-area-0.0.0.0] network 34.1.1.0 0.0.0.255
AR4
[ar4]ospf router-id 4.4.4.4
[ar4-ospf-1]area 0
[ar4-ospf-1-area-0.0.0.0]net 34.1.1.0 0.0.0.255
[ar4-ospf-1-area-0.0.0.0]net 4.4.4.4 0.0.0.0
[ar4-ospf-1-area-0.0.0.0]q
[ar1]bgp 100
[ar1-bgp]peer 12.1.1.2 as-number 200
[ar2]bgp 200
[ar2-bgp]peer 12.1.1.1 as-number 100
[ar2-bgp]peer 3.3.3.3 as-number 200
[ar2-bgp]peer 3.3.3.3 connect-interface LoopBack0
[ar2-bgp]peer 3.3.3.3 next-hop-local #将到达3.3.3.3的源地址改为2.2.2.2
[ar2-bgp]q
[ar3]bgp 200
[ar3-bgp]peer 2.2.2.2 as-number 200
[ar3-bgp]peer 2.2.2.2 connect-interface LoopBack0
[ar3-bgp]peer 4.4.4.4 as-number 200
[ar3-bgp]peer 4.4.4.4 connect-interface LoopBack0
[ar4]bgp 200
[ar4-bgp]peer 3.3.3.3 as-number 200
[ar4-bgp]peer 3.3.3.3 connect-interface LoopBack0
[ar4-bgp]q
注意:EBGP邻居只能使用物理接口,不能使用1.1.1.1的loopback接口
验证:
就是把设备中已经存在的路由引入到BGP路由器中,也可以理解为调用。
引入方式:
注意事项:在引入路由时,必须和路由表中的路由完全一样,不得修改字掩码
[ar2-bgp]dis ip rou
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 15 Routes : 15
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 EBGP 255 0 D 12.1.1.1 GigabitEthernet0/0/0
2.2.2.2/32 Direct 0 0 D 127.0.0.1 LoopBack0
3.3.3.3/32 OSPF 10 1 D 23.1.1.3 GigabitEthernet0/0/1
4.4.4.4/32 OSPF 10 2 D 23.1.1.3 GigabitEthernet0/0/1
12.1.1.0/24 Direct 0 0 D 12.1.1.2 GigabitEthernet0/0/0
12.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
12.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
23.1.1.0/24 Direct 0 0 D 23.1.1.2 GigabitEthernet0/0/1
23.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
23.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
34.1.1.0/24 OSPF 10 2 D 23.1.1.3 GigabitEthernet0/0/1
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[ar2-bgp]import-route ospf 1 #将所有OSPF路由引入BGP中
<ar2>dis bgp routing-table
BGP Local router ID is 2.2.2.2
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 6
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.1/32 12.1.1.1 0 0 100i
*> 2.2.2.2/32 0.0.0.0 0 0 ?
*> 3.3.3.3/32 0.0.0.0 1 0 ?
*> 4.4.4.4/32 0.0.0.0 2 0 ?
*> 23.1.1.0/24 0.0.0.0 0 0 ?
*> 34.1.1.0/24 0.0.0.0 2 0 ?
既然路由已经有了,我们就来测试一下连通性
<ar1>ping 2.2.2.2
PING 2.2.2.2: 56 data bytes, press CTRL_C to break
Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=20 ms
Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=10 ms
--- 2.2.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 10/24/30 ms
<ar1>ping 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
<ar3>ping 1.1.1.1
PING 1.1.1.1: 56 data bytes, press CTRL_C to break
Reply from 1.1.1.1: bytes=56 Sequence=1 ttl=254 time=40 ms
Reply from 1.1.1.1: bytes=56 Sequence=2 ttl=254 time=20 ms
Reply from 1.1.1.1: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 1.1.1.1: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 1.1.1.1: bytes=56 Sequence=5 ttl=254 time=20 ms
--- 1.1.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/28/40 ms
<ar1>ping 4.4.4.4
PING 4.4.4.4: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- 4.4.4.4 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
<ar4>ping 1.1.1.1
PING 1.1.1.1: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- 1.1.1.1 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
感觉不太靠谱,有通的,也有不通的。这个时候我们引入一个概念“BGP通告原则”
问题1:如果我们在AR2中不加这一条peer 3.3.3.3 next-hop-local
,则AR3是无法ping通1.1.1.1的。
解决办法:就是将到达3.3.3.3的源地址改为2.2.2.2,因此就有了这一条peer 3.3.3.3 next-hop-local
。但是这种方法在AR4中就无法使用了。因为我们看到上面第三条:“通过IBGP获得的最优路由不会发布给其他的IBGP邻居”,所以现在我们的AR4无法ping通1.1.1.1。
<ar4>dis bgp rou
空
因为bgp中我们所引入的OSPF路由,在AR4中是空的。所以AR4是没有学到任何BGP路由。
问题2:那么如何让AR4和AR1通信呢?
解决办法:在AR3上面做反射器。配置如下:
[ar3]bgp 200
[ar3-bgp]peer 4.4.4.4 re
[ar3-bgp]peer 4.4.4.4 reflect-client #使4.4.4.4成为反射器的客户端
[ar3-bgp]dis th
[V200R003C00]
#
bgp 200
peer 2.2.2.2 as-number 200
peer 2.2.2.2 connect-interface LoopBack0
peer 4.4.4.4 as-number 200
peer 4.4.4.4 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
peer 2.2.2.2 enable
peer 4.4.4.4 enable
peer 4.4.4.4 reflect-client
#
return
[ar3-bgp]
验证AR4的bgp路由:
<ar4>dis bgp rou
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 5
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 2.2.2.2 0 100 0 100i
*>i 3.3.3.3/32 2.2.2.2 1 100 0 ?
*>i 4.4.4.4/32 2.2.2.2 2 100 0 ?
*>i 23.1.1.0/24 2.2.2.2 0 100 0 ?
*>i 34.1.1.0/24 2.2.2.2 2 100 0 ?
终于是通了,到时候无论有多少IBGP,只要这一条命令就搞定了。
验证:
<ar1>ping -a 1.1.1.1 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=50 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=20 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=40 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=40 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/36/50 ms
<ar1>
<ar1>
<ar1>ping -a 1.1.1.1 4.4.4.4
PING 4.4.4.4: 56 data bytes, press CTRL_C to break
Reply from 4.4.4.4: bytes=56 Sequence=1 ttl=253 time=40 ms
Reply from 4.4.4.4: bytes=56 Sequence=2 ttl=253 time=50 ms
Reply from 4.4.4.4: bytes=56 Sequence=3 ttl=253 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=4 ttl=253 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=5 ttl=253 time=30 ms
--- 4.4.4.4 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/36/50 ms
<ar1>