1、IP规划及配置
为简单IP规划操作,各路由器环回地址均为X.X.X.X;最终IP规划如下:
1.1.1.1 / 24 —R1环回
1.1.2.1 / 24 —R1环回
2.2.2.2 / 24 —R2环回
3.3.3.3 / 24 —R3环回
4.4.4.4 / 24 —R4环回
5.5.5.5 / 24 —R5环回
6.6.6.6 / 24 —R6环回
12.1.1.0 / 24 R1—R2间IP
13.1.1.0 / 24 R1—R3间IP
24.1.1.0 / 24 R2—R4间IP
35.1.1.0 / 24 R3—R5间IP
46.1.1.0 / 24 R4—R6间IP
56.1.1.0 / 24 R5—R6间IP
[R1]interface GigabitEthernet0/0/0
[R1-GigabitEthernet0/0/0]ip address 12.1.1.1 24
[R1]interface LoopBack0
[R1-LoopBack0]ip address 1.1.1.1 24
2、AS2内IGP路由协议(OSPF)
在AS2 启用OSPF路由协议,使得AS2内部畅通;
R2:
ospf 1 router-id 2.2.2.2
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 23.1.1.1 0.0.0.0
network 24.1.1.1 0.0.0.0
R3:
ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 23.1.1.2 0.0.0.0
network 35.1.1.1 0.0.0.0
R4:
ospf 1 router-id 4.4.4.4
area 0.0.0.0
network 4.4.4.4 0.0.0.0
network 24.1.1.2 0.0.0.0
network 45.1.1.1 0.0.0.0
network 46.1.1.1 0.0.0.0
R5:
ospf 1 router-id 5.5.5.5
area 0.0.0.0
network 5.5.5.5 0.0.0.0
network 35.1.1.2 0.0.0.0
network 45.1.1.2 0.0.0.0
network 56.1.1.1 0.0.0.0
R6:
ospf 1 router-id 6.6.6.6
area 0.0.0.0
network 6.6.6.6 0.0.0.0
network 46.1.1.2 0.0.0.0
network 56.1.1.2 0.0.0.0
3、建立BGP邻居
我们这里用环回作为源,但是IP不可达,首先写两条静态路由,使得R1的环回可以访问R2/3的环回,为避免后面宣告BGP路由时出现问题,这儿宣告32位掩码的静态路由;
R1:
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
ip route-static 3.3.3.3 255.255.255.255 13.1.1.2
R2:
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
R3:
ip route-static 1.1.1.1 255.255.255.255 13.1.1.1
此时可以建立BGP邻居,但是默认EBGP邻居间TTL值为1,需要修改;另外还要将环回作为源以及修改下一跳
bgp 1
router-id 1.1.1.1
peer 2.2.2.2 as-number 2
peer 2.2.2.2 ebgp-max-hop 2
peer 2.2.2.2 connect-interface LoopBack0
peer 3.3.3.3 as-number 2
peer 3.3.3.3 ebgp-max-hop 2
peer 3.3.3.3 connect-interface LoopBack0
bgp 2
router-id 2.2.2.2
peer 1.1.1.1 as-number 1
peer 1.1.1.1 ebgp-max-hop 2
peer 1.1.1.1 connect-interface LoopBack0
peer 3.3.3.3 as-number 2
peer 3.3.3.3 connect-interface LoopBack0
peer 4.4.4.4 as-number 2
peer 4.4.4.4 connect-interface LoopBack0
peer 5.5.5.5 as-number 2
peer 5.5.5.5 connect-interface LoopBack0
bgp 2
router-id 3.3.3.3
peer 1.1.1.1 as-number 1
peer 1.1.1.1 ebgp-max-hop 2
peer 1.1.1.1 connect-interface LoopBack0
peer 2.2.2.2 as-number 2
peer 2.2.2.2 connect-interface LoopBack0
peer 4.4.4.4 as-number 2
peer 4.4.4.4 connect-interface LoopBack0
peer 5.5.5.5 as-number 2
peer 5.5.5.5 connect-interface LoopBack
bgp 2
router-id 4.4.4.4
peer 2.2.2.2 as-number 2
peer 2.2.2.2 connect-interface LoopBack0
peer 3.3.3.3 as-number 2
peer 3.3.3.3 connect-interface LoopBack0
peer 5.5.5.5 as-number 2
peer 5.5.5.5 connect-interface LoopBack0
peer 6.6.6.6 as-number 2
peer 6.6.6.6 connect-interface LoopBack0
bgp 2
router-id 5.5.5.5
peer 2.2.2.2 as-number 2
peer 2.2.2.2 connect-interface LoopBack0
peer 3.3.3.3 as-number 2
peer 3.3.3.3 connect-interface LoopBack0
peer 4.4.4.4 as-number 2
peer 4.4.4.4 connect-interface LoopBack0
peer 6.6.6.6 as-number 2
peer 6.6.6.6 connect-interface LoopBack0
bgp 2
router-id 6.6.6.6
peer 4.4.4.4 as-number 2
peer 4.4.4.4 connect-interface LoopBack0
peer 5.5.5.5 as-number 2
peer 5.5.5.5 connect-interface LoopBack0
R4,R5 作为路由反射器(RR),将路由传递给R6;
peer 2.2.2.2 reflect-client
peer 3.3.3.3 reflect-client
将路由宣告到BGP中,查看BGP表:
因为默认的选路规则,面临AS1到AS2选路不佳的问题,
ip ip-prefix as index 10 permit 5.5.5.0 24
ip ip-prefix as index 20 permit 3.3.3.0 24
#
route-policy as permit node 10
if-match ip-prefix as
apply as-path 1 1 1 additive
#
route-policy as permit node 20
if-match ip-prefix as
apply as-path 1 1 1 additive
#
route-policy as permit node 30
peer 2.2.2.2 route-policy as import
ip ip-prefix p index 10 permit 1.1.1.0 24
#
route-policy p permit node 10
if-match ip-prefix p
apply local-preference 101
#
route-policy p permit node 20
#
peer 5.5.5.5 route-policy p export
可以看到,R2、R4,下一跳为2.2.2.2;而R3、R5下一跳为3.3.3.3;
R6上开启BGP负载均衡;
[R6-bgp]load-balancing as-path-ignore
5、制定规则,使得R4/5/6访问R1两个换回负载分担;
首先为R4,默认选路为上方链路,修改访问1.1.2.0 时走下方链路:
ip ip-prefix med index 10 permit 1.1.2.0 24
#
route-policy med permit node 10
if-match ip-prefix med
apply cost 2
#
route-policy med permit node 20
peer 2.2.2.2 route-policy med export
在R1路由传递时,将COSt值加大为2,迫使访问1.1.2.0 的流量通过下方链路;同样的,R5默认走下方链路,将下方访问1.1.1.0 的流量cost值加大为2 ,迫使访问1.1.1.0 的流量走上方链路;
ip ip-prefix med index 10 permit 1.1.1.0 24
route-policy med permit node 30
if-match ip-prefix med
apply cost 2
#
peer 3.3.3.3 route-policy med export
环回可以互相访问;