实验目的:
1、掌握如何配置路径欺骗影响BGP的路由选择。
2、理解BGP的路径欺骗是MED的替代解决方法。
实验拓扑:
接口IP配置、路由协议基本配置详见:
CSDNhttps://mp.csdn.net/mp_blog/creation/editor/125206691
R1#show ip bgp
BGP table version is 6, local router ID is 14.14.14.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 3.3.3.0/24 12.12.12.2 0 2 3 i
* 14.14.14.4 0 4 3 i
//由于R2与R4同时向R1通告BGP的路由,而且其AS-PATH路径长度相同。
//因此R1可能是因此时间差或是BGP Router-ID的原因导致了选择12.12.12.2 作为其下一跳
//到达目标网络3.3.3.0/24
*> 12.12.12.0/24 0.0.0.0 0 32768 i
* 12.12.12.2 0 0 2 i
*> 14.14.14.0/24 0.0.0.0 0 32768 i
* 14.14.14.4 0 0 4 i
*> 23.23.23.0/24 12.12.12.2 0 0 2 i
* 14.14.14.4 0 4 3 i
* 34.34.34.0/24 12.12.12.2 0 2 3 i
*> 14.14.14.4 0 0 4 i
查看R1的路由表:
R1#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
B 34.34.34.0 [20/0] via 14.14.14.4, 00:01:46
3.0.0.0/24 is subnetted, 1 subnets
B 3.3.3.0 [20/0] via 12.12.12.2, 00:01:46
23.0.0.0/24 is subnetted, 1 subnets
B 23.23.23.0 [20/0] via 12.12.12.2, 00:01:46
12.0.0.0/24 is subnetted, 1 subnets
C 12.12.12.0 is directly connected, FastEthernet0/0
14.0.0.0/24 is subnetted, 1 subnets
C 14.14.14.0 is directly connected, FastEthernet0/1
在之前实验中,可以通过MED和Local Preference属性才影响R1选择路由。其实还可以通过AS-PATH来影响路由选择。其参照的是BGP的选路规则:优先选择AS-PATH最短的路径。
为了验证AS-PATH对路由选择的影响,在R3路由器上作如下配置:
R3(config)#access-list 1 permit 3.3.3.0 0.0.0.255
R3(config)#route-map set_prepend permit 10
R3(config-route-map)#match ip address 1
//匹配ACL 1的路由,在其路由的AS-PATH尾部添加两个as 3的自治系统编号。
R3(config-route-map)#set as-path prepend 3 3
R3(config)#router bgp 3
R3(config-router)#neighbor 23.23.23.2 route-map set_prepend out
//对于发向R2的路由路由进行策略配置。
需要注意的是:在set as-path prepend后添加的AS号,最好是本地自治系统号,否则可能会产生无效路由。
查看R1的BGP的数据库:
R1#show ip bgp
BGP table version is 7, local router ID is 14.14.14.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 3.3.3.0/24 12.12.12.2 0 2 3 3 3 i
*> 14.14.14.4 0 4 3 i
//由于两条路由,拥有不同长度的AS-PATH。因此BGP会选择最短路径的路由到达目标网络。
*> 12.12.12.0/24 0.0.0.0 0 32768 i
* 12.12.12.2 0 0 2 i
*> 14.14.14.0/24 0.0.0.0 0 32768 i
* 14.14.14.4 0 0 4 i
*> 23.23.23.0/24 12.12.12.2 0 0 2 i
* 14.14.14.4 0 4 3 i
*> 34.34.34.0/24 14.14.14.4 0 0 4 i
继续查看R1的路由表:
R1#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
B 34.34.34.0 [20/0] via 14.14.14.4, 00:01:25
3.0.0.0/24 is subnetted, 1 subnets
B 3.3.3.0 [20/0] via 14.14.14.4, 00:01:25
23.0.0.0/24 is subnetted, 1 subnets
B 23.23.23.0 [20/0] via 12.12.12.2, 00:01:25
12.0.0.0/24 is subnetted, 1 subnets
C 12.12.12.0 is directly connected, FastEthernet0/0
14.0.0.0/24 is subnetted, 1 subnets
C 14.14.14.0 is directly connected, FastEthernet0/1