锐捷RSR系列路由器_IP路由协议_路由控制

目录

01  路由控制介绍

02  distribute-list 分发列表

03  route-map 路由图


01  路由控制介绍

ACL 与 prefix-list

相同点:

都可以用来匹配路由前缀

不同点:

ACL可以用来过滤数据包,匹配ip报文的五大元素,prefix-list 只能用来匹配路由前缀

如何选择:

匹配路由前缀时,使用ACL或使用prefix-list 均可以,两者只要选择其一。当需要匹配一个大网段下的不同掩码长度的路由前缀时,使用prefix-list 更加方便。

distribute-list 与 route-map

相同点:

都可以用来做路由过滤

不同点:

1)distribute-list 只能过滤路由条目,无法修改路由属性;route-map除了可以过滤路由条目,还能够修改路由属性。

2)route-map可以强制修改数据包的下一跳,做策略路由。

3)distribute-list 应用的地方为:路由协议重分发时距离矢量路由协议邻居之间的路由传递(距离矢量协议邻居之间传递的是路由,因此可以做路由过滤)及链路状态路由协议将路由提交路由表时(链路状态协议邻居之间传递的是lsa并非路由,不能过滤邻居之间传递的lsa)。

4)route-map应用的地方为:路由协议重分发时,bgp邻居传递路由时。

如何选择:

看具体的应用场景,若distribute-list 与route-map均能够使用,那么若需要修改路由属性,必须使用route-map;若不需要修改路由属性,2者选其一就可以。


02  distribute-list 分发列表

功能介绍:

distribute-list 分发列表,通过distribute-list 工具对路由更新进行控制,只能进行路由条目过滤,不能修改路由的属性

一、组网要求

在R2上把rip路由重分发进ospf,并且在重分发时进行路由过滤,只允许路由 172.16.1.32/28、172.16.1.48/29、172.16.1.56/30重分发进ospf

二、组网拓扑

三、配置要点

1、基本ip地址配置

2、R1、R2启用rip协议,并将对应接口通告到rip进程

3、R2、R3启用ospf协议,并将对应接口通告到ospf进程

4、在R2上把rip学习到的路由重分发进ospf

5、通过acl或前缀列表,把需要学习的路由匹配出来

6、R2 rip路由重分发进ospf,使用distribute-list 过滤路由

四、配置步骤

1、基本ip地址配置

Ruijie(config)#hostname R1

R1(config)#interface fastEthernet 0/0

R1(config-if-FastEthernet 0/0)#ip address 192.168.1.1 255.255.255.0

R1(config-if-FastEthernet 0/0)#exit

R1(config)#interface loopback 1

R1(config-if-Loopback 1)#ip address 172.16.1.1 255.255.255.224

R1(config-if-Loopback 1)#exit

R1(config)#interface loopback 2

R1(config-if-Loopback 2)#ip address 172.16.1.33 255.255.255.240

R1(config-if-Loopback 2)#exit

R1(config)#interface loopback 3

R1(config-if-Loopback 3)#ip address 172.16.1.49 255.255.255.248

R1(config-if-Loopback 3)#exit

R1(config)#interface loopback 4

R1(config-if-Loopback 4)#ip address 172.16.1.57 255.255.255.252

R1(config-if-Loopback 4)#exit

Ruijie(config)#hostname R2

R2(config)#interface fastEthernet 0/2

R2(config-if-FastEthernet 0/2)#ip address 192.168.1.2 255.255.255.0

R2(config-if-FastEthernet 0/2)#exit

R2(config)#interface fastEthernet 0/0

R2(config-if-FastEthernet 0/0)#ip address 192.168.2.1 255.255.255.0

R2(config-if-FastEthernet 0/0)#exit

Ruijie(config)#hostname R3

R3(config)#interface fastEthernet 0/1

R3(config-if-FastEthernet 0/1)#ip address 192.168.2.2 255.255.255.0

R3(config-if-FastEthernet 0/1)#exit

2、R1、R2启用rip协议,并将对应接口通告到rip进程

R1(config)#router rip

R1(config-router)#version 2     //启用rip版本2

R1(config-router)#no auto-summary     //关闭自动汇总

R1(config-router)#network 172.16.0.0     //将172.16.0.0的主类网络通告到rip进程

R1(config-router)#network 192.168.1.0  

R1(config-router)#exit

R2(config)#router rip

R2(config-router)#version 2

R2(config-router)#no auto-summary

R2(config-router)#network 192.168.1.0

R2(config-router)#exit

3、R2、R3启用ospf协议,并将对应接口通告到ospf进程

R2(config)#router ospf 1    //启用ospf进程 1

R2(config-router)#network 192.168.2.1 0.0.0.0 area 0    //将192.168.2.1对应的接口通告到ospf 进程1的区域 0

R2(config-router)#exit

R3(config)#router ospf 1

R3(config-router)#network 192.168.2.2 0.0.0.0 area 0

R3(config-router)#exit

4、在R2上把rip学习到的路由重分发进ospf

R2(config)#router ospf 1

R2(config-router)#redistribute rip subnets    //将rip路由重分发进ospf,必须加subnet

R2(config-router)#exit

5、通过acl或前缀列表,把需要学习的路由匹配出来

注意:

1)匹配路由条目的工具有acl和前缀列表两种,只要选择其中一种就可以

2)若需要匹配一个大网段下的不同掩码长度的路由前缀时,前缀列表会更方便一些,当然用acl也是可以的,只是要写多个条目

如下示例,匹配路由条目172.16.1.32/27、172.16.1.48/28和172.16.1.56/29,acl需要写3个ace条目,前缀列表只要1个条目

1)使用acl匹配路由条目

注意:

此处acl匹配的是路由条目,掩码用0.0.0.0精确匹配对应的路由条目

R2(config)#ip access-list standard 1

R2(config-std-nacl)#10 permit 172.16.1.32 0.0.0.0

R2(config-std-nacl)#20 permit 172.16.1.48 0.0.0.0

R2(config-std-nacl)#30 permit 172.16.1.56 0.0.0.0

R2(config-std-nacl)#exit                 

2)使用前缀列表匹配路由条目

注意:

1)前缀列表只能用来匹配路由条目,不能用来做数据包过滤

2)前缀列表匹配的是一个网段下的子网,ge代表大于等于多少位掩码,le代表小于多少位掩码

3)前缀列表也是从上往下匹配,最后隐含一条deny any

R2(config)#ip prefix-list ruijie seq 10 permit 172.16.1.0/24 ge 28 le 30   //定义前缀列表ruijie,匹配前缀为172.16.1.0/24,子网掩码大于等于28小于等于30的路由条目

6、R2 rip路由重分发进ospf,使用distribute-list 过滤路由

注意

1)distribute-list过滤的路由条目是由acl和前缀列表匹配出来的,具体过滤什么路由条目是由acl和前缀列表决定的

2)distribute-list可以运用的地方为,路由协议重分发时距离矢量路由协议邻居之间的路由传递(距离矢量协议邻居之间传递的是路由,因此可以做路由过滤)及链路状态路由协议将路由提交路由表时(链路状态协议邻居之间传递的是lsa并非路由,不能过滤邻居之间传递的lsa)。

如下以distribute-list 调用acl及前缀列表做路由过滤,分别举例:

1)distribute-list 调用acl做路由过滤

R2(config)#router ospf 1   

R2(config-router)#distribute-list 1 out rip     //把rip路由重分发进ospf时做路由过滤(注意方向必须是out

R2(config-router)#exit

2)distribute-list 调用前缀列表做路由过滤

R2(config)#router ospf 1

R2(config-router)#distribute-list prefix ruijie out rip    //把rip路由重分发进ospf时做路由过滤(注意方向必须是out

R2(config-router)#exit

补充:

1)距离矢量协议使用distribute-list 过滤邻居之间传递的路由条目,命令如下:

R2(config)#router rip

R2(config-router)#distribute-list 1 in fastEthernet 0/2   //1代表acl 列表 1,也可用前缀列表; in代表从邻居学习的路由,若为out则是传递给邻居的路由;还可以加上具体的接口

2)链路状态协议使用distribute-list 过滤提交给路由表的路由条目

R2(config)#router ospf 1

R2(config-router)#distribute-list 1 in    //代表acl 列表 1,也可用前缀列表; 方向必须为in

五、配置验证

查看R3的路由条目,若R3学习到的路由条目为 172.16.1.32/28、172.16.1.48/29、172.16.1.56/30 则distribute-list做路由过滤配置正确

R3#show ip route

Codes:  C - connected, S - static, R - RIP, B - BGP

        O - OSPF, IA - OSPF inter area

        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

        E1 - OSPF external type 1, E2 - OSPF external type 2

        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2

        ia - IS-IS inter area, * - candidate default

Gateway of last resort is no set

O E2 172.16.1.32/28 [110/20] via 192.168.2.1, 00:02:45, FastEthernet 0/1

O E2 172.16.1.48/29 [110/20] via 192.168.2.1, 00:02:29, FastEthernet 0/1

O E2 172.16.1.56/30 [110/20] via 192.168.2.1, 00:02:21, FastEthernet 0/1

C    192.168.2.0/24 is directly connected, FastEthernet 0/1

C    192.168.2.2/32 is local host.


03  route-map 路由图

功能介绍:

route-map 路由图,通过route-map工具可以对路由更新进行控制,并且能够修改路由的属性

一、组网要求

在R2上把rip路由重分发进ospf,并且在重分发时进行路由过滤,只允许路由 172.16.1.32/28、172.16.1.48/29、172.16.1.56/30重分发进ospf ,引入的外部路由类型为OE1,metric为50。

二、组网拓扑

三、配置要点

1、基本ip地址配置

2、R1、R2启用rip协议,并将对应接口通告到rip进程

3、R2、R3启用ospf协议,并将对应接口通告到ospf进程

4、在R2上把rip学习到的路由重分发进ospf

5、通过acl或前缀列表,把需要学习的路由匹配出来

6、配置route-map

7、R2将rip路由重分发进ospf,调用route-map做路由控制

四、配置步骤

1、基本ip地址配置

Ruijie(config)#hostname R1

R1(config)#interface fastEthernet 0/0

R1(config-if-FastEthernet 0/0)#ip address 192.168.1.1 255.255.255.0

R1(config-if-FastEthernet 0/0)#exit

R1(config)#interface loopback 1

R1(config-if-Loopback 1)#ip address 172.16.1.1 255.255.255.224

R1(config-if-Loopback 1)#exit

R1(config)#interface loopback 2

R1(config-if-Loopback 2)#ip address 172.16.1.33 255.255.255.240

R1(config-if-Loopback 2)#exit

R1(config)#interface loopback 3

R1(config-if-Loopback 3)#ip address 172.16.1.49 255.255.255.248

R1(config-if-Loopback 3)#exit

R1(config)#interface loopback 4

R1(config-if-Loopback 4)#ip address 172.16.1.57 255.255.255.252

R1(config-if-Loopback 4)#exit

Ruijie(config)#hostname R2

R2(config)#interface fastEthernet 0/2

R2(config-if-FastEthernet 0/2)#ip address 192.168.1.2 255.255.255.0

R2(config-if-FastEthernet 0/2)#exit

R2(config)#interface fastEthernet 0/0

R2(config-if-FastEthernet 0/0)#ip address 192.168.2.1 255.255.255.0

R2(config-if-FastEthernet 0/0)#exit

Ruijie(config)#hostname R3

R3(config)#interface fastEthernet 0/1

R3(config-if-FastEthernet 0/1)#ip address 192.168.2.2 255.255.255.0

R3(config-if-FastEthernet 0/1)#exit

2、R1、R2启用rip协议,并将对应接口通告到rip进程

R1(config)#router rip

R1(config-router)#version 2     //启用rip版本2

R1(config-router)#no auto-summary     //关闭自动汇总

R1(config-router)#network 172.16.0.0     //将172.16.0.0的主类网络通告到rip进程

R1(config-router)#network 192.168.1.0  

R1(config-router)#exit

R2(config)#router rip

R2(config-router)#version 2

R2(config-router)#no auto-summary

R2(config-router)#network 192.168.1.0

R2(config-router)#exit

3、R2、R3启用ospf协议,并将对应接口通告到ospf进程

R2(config)#router ospf 1    //启用ospf进程 1

R2(config-router)#network 192.168.2.1 0.0.0.0 area 0    //将192.168.2.1对应的接口通告到ospf 进程1的区域 0

R2(config-router)#exit

R3(config)#router ospf 1

R3(config-router)#network 192.168.2.2 0.0.0.0 area 0

R3(config-router)#exit

4、在R2上把rip学习到的路由重分发进ospf

R2(config)#router ospf 1

R2(config-router)#redistribute rip subnets    //将rip路由重分发进ospf,必须加subnet

R2(config-router)#exit

5、通过acl或前缀列表,把需要学习的路由匹配出来

注意:

1)匹配路由条目的工具有acl和前缀列表两种,只要选择其中一种就可以

2)若需要匹配一个网段下的几个子网路由,那么用前缀列表会更方便一线,当然用acl也是可以的,只是要写多个条目

如下示例,匹配路由条目172.16.1.32/27、172.16.1.48/28和172.16.1.56/29,acl需要写3个ace条目,前缀列表只要1个条目

1)使用acl匹配路由条目

注意:

此处acl匹配的是路由条目,掩码用0.0.0.0精确匹配对应的路由条目

R2(config)#ip access-list standard 1

R2(config-std-nacl)#10 permit 172.16.1.32 0.0.0.0

R2(config-std-nacl)#20 permit 172.16.1.48 0.0.0.0

R2(config-std-nacl)#30 permit 172.16.1.56 0.0.0.0

R2(config-std-nacl)#exit                 

2)使用前缀列表匹配路由条目

注意:

1)前缀列表只能用来匹配路由条目,不能用来做数据包过滤

2)前缀列表匹配的是一个网段下的子网,ge代表大于等于多少位掩码,le代表小于多少位掩码

3)前缀列表也是从上往下匹配,与acl的匹配顺序及规则是一样的

R2(config)#ip prefix-list ruijie seq 10 permit 172.16.1.0/24 ge 28 le 30   //定义前缀列表ruijie,匹配前缀为172.16.1.0/24,子网掩码大于等于28小于等于30的路由条目

6、配置route-map

注意:

1)route-map除了可以用来做路由过滤,还能够修改路由的属性

2)route-map可以match的条件比较多(包括 路由条目、metric、metric-type等条件),distribute-list只能匹配路由条目

3)route-map的执行顺序从上到下,最后隐含一条deny any

4)route-map的执行逻辑如下:

route-map aaa permit 10
match x y z   
//多个match条件横着写,是or的关系,只要满足其中一个条件,该match语句就算匹配
match a 
      set b   //
多个set语句竖着写,会同时执行多个set动作
      set c

route-map aaa permit 20
   match p

    match q       //多个match条件竖着写,是and的关系,要多个条件同时满足,该match语句才算匹配
      set r

route-map aaa deny any (系统隐含)

执行逻辑如下:

 If (x or y or z)
then set(b and c)
else if (p and q)
      then set r
      else deny

route-map的match ip address 可以匹配acl列表,也可以匹配前缀列表,只要选择其中一种就可以,如下分别示例:

1)match ip address 使用acl列表匹配

R2(config)#route-map aaa permit 10

R2(config-route-map)#match ip address 1     //匹配acl列表1的路由条目

R2(config-route-map)#set metric-type type-1     //配置引入的外部路由类型为类型1

R2(config-route-map)#set metric 50  //配置引入的外部路由 metric为50

R2(config-route-map)#exit

2)match ip address 使用前缀列表匹配

R2(config)#route-map aaa permit 10

R2(config-route-map)#match ip address prefix-list ruijie   //匹配前缀列表ruijie的路由条目

R2(config-route-map)#set metric-type type-1  

R2(config-route-map)#set metric 50

R2(config-route-map)#exit

7、R2将rip路由重分发进ospf,调用route-map做路由控制

注意:

route-map的调用位置可以为路由重分发以及BGP协议neighbor指邻居

R2(config)#router ospf 1

R2(config-router)#redistribute rip subnets route-map aaa    //将rip路由重分发进ospf时,调用route-map aaa

R2(config-router)#exit

补充:

BGP协议指neighbor调用route-map的配置命令如下

R2(config)#router bgp 1

R2(config-router)#neighbor 10.1.1.1 route-map aaa in   // 方向in代表对从该邻居学习的路由做控制,方向out代表发给该邻居的路由做控制(对bgp邻居使用route-map做路由控制,配置route-map后,需要通过软清除bgp邻居的路由,才能使配置生效,该操作请勿在业务高峰期进行)

五、配置验证

查看R3的路由条目,若R3学习到的路由条目为 172.16.1.32/28、172.16.1.48/29、172.16.1.56/30,且为OE1的路由,并叠加内部cost, 则route-map做路由控制配置正确

R3#show ip route

Codes:  C - connected, S - static, R - RIP, B - BGP

        O - OSPF, IA - OSPF inter area

        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

        E1 - OSPF external type 1, E2 - OSPF external type 2

        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2

        ia - IS-IS inter area, * - candidate default

Gateway of last resort is no set

O E1 172.16.1.32/28 [110/51] via 192.168.2.1, 00:03:14, FastEthernet 0/1

O E1 172.16.1.48/29 [110/51] via 192.168.2.1, 00:03:14, FastEthernet 0/1

O E1 172.16.1.56/30 [110/51] via 192.168.2.1, 00:03:14, FastEthernet 0/1

C    192.168.2.0/24 is directly connected, FastEthernet 0/1

C    192.168.2.2/32 is local host.

猜你喜欢

转载自blog.csdn.net/weixin_57099902/article/details/132231689