38. Affects the BGP Routing By Path Prepend

1、掌握如何配置路径欺骗影响 BGP 的路由选择。

2、理解 BGP 的路径欺骗是 MED 的替代解决方法,但是其适用范围较小,只能在有限的网络环境下配置使用。

 

这里假设R1和R4之间是一条高速以太网链路。

 

网络图:

image.png


配置各路由器的IP地址等基本信息。

配置各路由器的BGP协议。

 

查看 R1的BGP数据库和路由表:

image.png

 

可以通过修改MED值、本地优先属性值(Local Preference)、权值影响R1的路由选择,还可以通过AS-PATH来影响路由选择。

BGP选路规则之一:优先选择AS-PATH路径最短的路径。

 

在R3上作如下配置,以加大AS-PATH数值:

R3#conf t

R3(config)#access-list 1 permit 150.150.1.0 0.0.0.255

R3(config)#route-map set-path permit 10

R3(config-route-map)#match ip address 1

R3(config-route-map)#set as-path prepend 64514   ---->根据实际情况添加,这里加一个就好,不然在R2上会出现次佳路由

R3(config-route-map)#exit

R3(config)#route-map set-path permit 20

R3(config-route-map)#exit

R3(config)#router bgp 64514

R3(config-router)#neighbor 192.168.2.1 route-map set-path out

R3(config-router)#end

R3#clear ip bgp * soft out  ---->加速收敛

 

在 set as-path prepend 后添加的 AS 号,最好是本地自治系统号,否则可能会产生无效路由。

 

查看R1的BGP数据库和路由表:

R1#show ip bgp

BGP table version is 13, local router ID is 192.168.4.2

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

*  150.150.1.0/24   192.168.1.2                            0 64513 64514 64514 i  ---->路径变长了,不选这个

*>                  192.168.4.1                            0 64515 64514 i

*  192.168.1.0      192.168.1.2              0             0 64513 i

*>                  0.0.0.0                  0         32768 i

*> 192.168.2.0      192.168.1.2              0             0 64513 i

*                   192.168.4.1                            0 64515 64514 i

*  192.168.3.0      192.168.1.2                            0 64513 64514 i

*>                  192.168.4.1              0             0 64515 i

*  192.168.4.0      192.168.4.1              0             0 64515 i

*>                  0.0.0.0                  0         32768 i

 

R1#show ip route

Gateway of last resort is not set

C    192.168.4.0/24 is directly connected, Serial0/1

C    192.168.1.0/24 is directly connected, Serial0/0

B    192.168.2.0/24 [20/0] via 192.168.1.2, 00:28:30

B    192.168.3.0/24 [20/0] via 192.168.4.1, 01:24:19

     150.150.0.0/24 is subnetted, 1 subnets

B       150.150.1.0 [20/0] via 192.168.4.1, 00:35:04

 

测试:

R1#ping 150.150.1.1

 

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 150.150.1.1, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 76/97/140 ms

R1#tracer 150.150.1.1

 

Type escape sequence to abort.

Tracing the route to 150.150.1.1

 

  1 192.168.4.1 92 msec 44 msec 44 msec

  2 192.168.3.1 [AS 64515] 92 msec *  72 msec

 

一切正常。

 

 

 

假如在上面添加的路径中追加了两个AS路径,则在R2上会出现下面这个次佳路由:

R2#show ip bgp

BGP table version is 13, local router ID is 192.168.2.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

*> 150.150.1.0/24   192.168.1.1                            0 64512 64515 64514 i

              ---->长度一样,但是优先选Route-ID小的

*                   192.168.2.2              0             0 64514 64514 64514 i

*  192.168.1.0      192.168.1.1              0             0 64512 i

*>                  0.0.0.0                  0         32768 i

*  192.168.2.0      192.168.2.2              0             0 64514 i

*>                  0.0.0.0                  0         32768 i

*> 192.168.3.0      192.168.2.2              0             0 64514 i

*                   192.168.1.1                            0 64512 64515 i

*  192.168.4.0      192.168.2.2                            0 64514 64515 i

*>                  192.168.1.1              0             0 64512 i

 

 

 

完成。



发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

桂ICP备19000498号-3