一、简介

本章回顾了最基本的路由知识,重点是增强读者对ACL和路由策略配置操作的熟练程度,因为在后续的实验中会经常用到这方面的知识和配置操作技能。

二、访问控制列表

2.1 原理概述

访问控制列表(ACL:Access Control List)是一种常见的网络技术,它的基本功能是对经过网络设备的报文进行过滤处理。ACL是由permit和deny语句组成的一个有序规则的集合,它首先通过报文匹配过程来实现对报文的分类识别,然后根据报文的分类信息和相关的执行动作来判断哪些报文可以放行,哪些报文不能放行,从而实现对特定报文的过滤处理。除此之外,ACL还有其他一些功能,这些功能常常被Route-Policy、Qos(Quality of Service)、IPsec(IP Security)、Firewall等技术结合起来使用。 ACL的常见类型:基本ACL、高级ACL、二层ACL、用户自定义ACL等,其中应用最广泛的是基本ACL和高级ACL。基本ACL可以根据源IP地址、报文分片标记和时间段信息来定义规则:高级ACL可以根据源/目的IP地址、TCP源/目的端口号、UDP源/目的端口号、协议号、报文优先级、报文大小、时间段等信息来定义规则。高级ACL可以比基本ACL定义出精细度更高的规则。 基本ACL、高级ACL、二层ACL、用户自定义ACL的编号范围分别为2000-2999、3000-3999、4000-4999、5000-5999。使用ACL时,ACL的类型应该与相应的编号范围保持一致。

2.2 访问控制列表配置实验

2.2.1 实验目的

1、掌握基本ACL和高级ACL在安全策略中的应用 2、掌握基于时间信息的ACL配置 3、掌握使用基本ACL保护路由器的VTY线路

2.2.2 实验内容

本实验模拟了一个简单的公司网络,基本组成:一台FTP-Server,一台Web-Server,一台HR部门的终端PC-1,一台SALES部门的终端PC-2,一台IT部门的终端PC-3,一台路由器R1和一台交换机SW1。为了满足公司的安全需求,要求在R1上使用ACL对部门之间的互访,以及用户对服务器的访问进行控制。另外,只允许SW1的VLANIF 1接口的IP地址作为源地址远程登录到R1,以实现对R1的远程控制和管理。

2.2.3 实验拓扑

访问控制列表实验拓扑

2.2.4 实验编制表

设备 接口 IP地址 子网掩码 默认网关
R1(AR1220) E1/0/0 172.16.1.254 255.255.255.0 N/A
R1(AR1220) E1/0/1 172.16.2.254 255.255.255.0 N/A
R1(AR1220) E2/0/0 172.16.3.254 255.255.255.0 N/A
R1(AR1220) E2/0/1 192.168.1.254 255.255.255.0 N/A
SW1(SW3700) Vlanif 1 192.168.1.1 255.255.255.0 N/A
Web-Server E0/0/0 192.168.1.30 255.255.255.0 192.168.1.254
Ftp-Server E0/0/0 192.168.1.10 255.255.255.0 192.168.1.254
PC-1 E0/0/0 172.16.1.1 255.255.255.0 172.16.1.254
PC-2 E0/0/0 172.16.2.1 255.255.255.0 172.16.2.254
PC-3 E0/0/0 172.16.3.1 255.255.255.0 172.16.3.254
### 2.2.5 实验步骤
#### 2.2.5.1 基本配置
根据实验编址表进行相应的基本配置,并使用Ping命令检测R1与PC-1之间的连通性。
##### 2.2.5.1.1 Ftp-Server配置
1、使用eNSP软件设置Ftp-Server,用鼠标右键单击拓扑图中的Ftp-Server图标,选择'设置'选项,出现配置界面。注意,在配置之前不要启动设备。在'基础配置'页面设置IP地址、子网掩码、网关。本实验直接采用IP地址方式访问服务器。所以无需设置域名服务器。
访问控制列表实验——Ftp-Server基础配置

2、点击'服务器信息'页面,在左侧选择栏中选中'FtpServer',设置端口号为21,设置文件根目录为C:\Users\zq\Desktop\FTP-Huawei\Config。根目录下的test.txt文件将作为测试文件在后续测试中使用。在"服务器信息"页面,点击"启动"选项。 访问控制列表实验——Ftp-Server服务器信息

3、设置完成后,"日志信息"页面中出现"FtpServer:FtpServerInfo: Listening!"提示,表明Ftp-Server已正常启动,此时关闭该窗口即可。 访问控制列表实验——Ftp-Server日志信息

2.2.5.1.2 Web-Server配置

1、使用eNSP软件设置Web-Server,用鼠标右键单击拓扑图中的Web-Server图标,选择'设置'选项,出现配置界面。注意,在配置之前不要启动设备。在'基础配置'页面设置IP地址、子网掩码、网关。本实验直接采用IP地址方式访问服务器。所以无需设置域名服务器。 访问控制列表实验——Web-Server基础配置

2、点击'服务器信息'页面,在左侧选择栏中选中HttpServer',设置端口号为80,设置文件根目录为C:\Users\zq\Desktop\Web-Server。根目录下的default.htm.txt文件,文件内容为Hello,Welcome to Huawei.com.将作为测试文件在后续测试中使用。在"服务器信息"页面,点击"启动"选项。

访问控制列表实验——Web-Server服务器配置

3、设置完成后,"日志信息"页面中出现"设备启动"提示,表明Web-Server已正常启动,此时关闭该窗口即可。

访问控制列表实验——Web-Server日志信息

2.2.5.2 为各部门创建安全区域

1、在R1上为HR、SALES、IT这3个部门分别创建安全区域,区域名称和部门名称一样,HR区域的安全级别设置为12,SALES区域的安全级别设置为10,IT区域的安全级别设置为8。再创建Trust区域,设置Trust区域的安全级别为14,Ftp-Server和 Web-Server都属于Trust区域使用。(AR系列路由器默认可以设置16中安全级别,取值范围为0-15,15保留给Local区域使用)

[R1]firewall zone HR    
[R1-zone-HR]priority 12 
[R1-zone-HR]firewall zone SALES 
[R1-zone-SALES]priority 10
[R1-zone-SALES]firewall zone IT 
[R1-zone-IT]priority 8  
[R1-zone-IT]firewall zone trust 
[R1-zone-trust]priority 14

2、将R1上连接不同部门的接口加入到相应部门的安全区域中,E2/0/1接口加入到Trust区域中。

[R1]int e1/0/0  
[R1-Ethernet1/0/0]zone HR
[R1-Ethernet1/0/0]int e1/0/1
[R1-Ethernet1/0/1]zone SALES
[R1-Ethernet1/0/1]int e2/0/0
[R1-Ethernet2/0/0]zone IT
[R1-Ethernet2/0/0]int e2/0/1
[R1-Ethernet2/0/1]zone trust

3、配置完成后,使用dis firewall zone命令查看相应区域的优先级,区域内包含接口名称、接口数量等信息。

[R1]dis firewall zone
zone IT
 priority is 8
 interface of the zone is (total number 1):
 Ethernet2/0/0

zone SALES
 priority is 10
 interface of the zone is (total number 1):
 Ethernet1/0/1

zone HR
 priority is 12
 interface of the zone is (total number 1):
 Ethernet1/0/0

zone trust
 priority is 14
 interface of the zone is (total number 1):
 Ethernet2/0/1

zone Local
 priority is 15
 interface of the zone is (total number 0):

 total number is : 5

注意:在配置AR系列路由器的防火墙特性时需要注意流量的走向。从较高安全级别区域去往较低安全区域的报文称为Outbound报文,从较低安全级别区域去往较高安全级别区域的报文称为Inbound报文。AR系列路由器的防火墙特性允许管理员在不同的区域之间进行报文的过滤处理。

2.2.5.3 禁止SALES部门和HR部门之间的互访

1、启用SALES区域和HR区域的域间防火墙

[R1]firewall interzone SALES HR     
[R1-interzone-HR-SALES]firewall enable 

说明:firewall enable是启用域间防火墙。缺省情况下,当域间防火墙启用之后,安全级别较高的区域能够访问安全级别较低的区域,并且应答的报文能够返回到安全级别较高的区域,但是安全级别较低的区域无法访问安全级别较高的区域。这条命令只开启了HR区域和SALES区域之间的访问墙特性,不会对HR区域和SALES区域与其他区域之间报文运动有任何影响。 2、配置完成后,使用dis firewall interzone HR SALES命令查看区域间的默认策略。观察到,区域间的默认策略为Inbound报文被拒绝通过,区域间的默认策略为Outbound报文被允许通过。由于HR区域的安全级别是12,SALES区域的安全级别是10,所以从HR区域到SALES区域是Outbound报文,反之,则是Inbound报文。

[R1]dis firewall interzone HR SALES 
interzone HR SALES
 firewall enable
 packet-filter default deny inbound
 packet-filter default permit outbound

3、使用Ping命令测试PC-1与PC-2之间的连通性。判定,Outbound方向的报文是被放行的,返回的Inbound方向也是被放行的。

PC-1>ping 172.16.2.1

Ping 172.16.2.1: 32 data bytes, Press Ctrl_C to break
From 172.16.2.1: bytes=32 seq=1 ttl=254 time=15 ms
From 172.16.2.1: bytes=32 seq=2 ttl=254 time=16 ms
From 172.16.2.1: bytes=32 seq=3 ttl=254 time=15 ms
From 172.16.2.1: bytes=32 seq=4 ttl=254 time=16 ms
From 172.16.2.1: bytes=32 seq=5 ttl=254 time=16 ms

--- 172.16.2.1 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 15/15/16 ms

4、测试PC-2与PC-1的连通性。右键PC-2,选择"设置"选项,然后在"基础设置"页面上进行ping测试,目的IP地址输入172.16.1.1,次数为10,点击"发送"。观察到结果显示失败,其原因可以推断为Inbound方向的报文被拒绝通行。

访问控制列表实验——PC2pingPC1

5、由于默认SALES区域不能访问HR区域,所以只需在Outbound方向将HR去往SALES的报文全部过滤掉。创建高级ACL3000来定义从HR到SALES的报文,步长设置为10(默认为5)。

[R1]acl 3000    
[R1-acl-adv-3000]step 10    
[R1-acl-adv-3000]rule deny ip source 172.16.1.0 0.0.0.255 destination 172.16.2.0
 0.0.0.255
[R1-acl-adv-3000]firewall interzone HR SALES
[R1-interzone-HR-SALES]packet-filter 3000 outbound 

6、配置完成后,在R1上使用dis acl 3000命令查看ACL配置,观察到,ACL 3000中只有1条规则,步长为10,规则序列号也为10。

[R1]dis acl 3000
Advanced ACL 3000, 1 rule
Acl's step is 10
 rule 10 deny ip source 172.16.1.0 0.0.0.255 destination 172.16.2.0 0.0.0.255

7、查看SALES和HR的域间Firewall策略,观察到,ACL 3000已经被应用到SALES和HR的域间Outbound方向上了。

[R1]dis firewall interzone HR SALES 
interzone HR SALES
 firewall enable
 packet-filter default deny inbound
 packet-filter default permit outbound
 packet-filter 3000 outbound

8、在PC-1上重新测试与PC-2的连通性。观察到,在PC-1上现在无法ping通PC-2。

PC-1>ping 172.16.2.1

Ping 172.16.2.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
Request timeout!
Request timeout!
Request timeout!
Request timeout!

--- 172.16.2.1 ping statistics ---
  5 packet(s) transmitted
  0 packet(s) received
  100.00% packet loss

2.2.5.4 实现对Web-Server和Ftp-Server访问的控制

2.2.5.4.1 要求SALES部门的用户可以访问公司的Web-Server,不可以访问Ftp-Server

1、开启SALES区域和trust区域间的防火墙。

[R1]firewall interzone SALES trust  
[R1-interzone-trust-SALES]firewall enable

2、由于SALES区域的安全级别为10,Trust区域的安全级别为14,访问流量的方向是Inbound方向。根据区域间防火墙默认规则,SALES部门的用户是无法访问Trust区域间的服务器。创建ACL3001,在Inbound方向上明确放行SALES区域访问Trust区域的Web-Server报文,其他访问报文被默认规则拒绝通行。

[R1]acl 3001 
[R1-acl-adv-3001]rule permit tcp source 172.16.2.0 0.0.0.255 destination 192.168
.1.30 0.0.0.0 destination-port eq 80
[R1]firewall interzone SALES trust  
[R1-interzone-trust-SALES]packet-filter 3001 inbound 

3、配置完成后,测试PC-2能否访问Web-Server和FTP-Server。观察到,PC-2可以正常访问Web-Server,但是无法访问FTP-Server。

访问控制列表实验——PC2访问Ftp-Server 访问控制列表实验——PC2访问WebServer

2.2.5.4.2 要求IT部门的用户可以访问公司的Ftp-Server,但只能在每天的14:00-16:00才能访问Web-Server,IT部门的用户随时Ping通Ftp-Server和Web-Server

1、开启IT和Trust之间的域间防火墙

[R1]firewall interzone IT trust     
[R1-interzone-trust-IT]firewall enable 

2、配置时间跨度为每天的14:00-16:00.

[R1]time-range pc-web 14:00 to 16:00 daily 

3、创建ACL 3003,放行IT到Trust的Inbound方向的FTP、HTTP、ICMP的ECHO报文,步长设置为10。

[R1]acl 3003
[R1-acl-adv-3003]rule permit tcp source 172.16.3.0 0.0.0.255 destination 192.168
.1.30 0.0.0.0 destination-port eq 80 time-range pc-web      
[R1-acl-adv-3003]rule permit tcp source 172.16.3.0 0.0.0.255 destination 192.168
.1.10 0.0.0.0 destination-port eq 21    
[R1-acl-adv-3003]rule permit icmp source 172.16.3.0 0.0.0.255 destination 192.16
8.1.10 0.0.0.0
[R1-acl-adv-3003]rule permit icmp source 172.16.3.0 0.0.0.255 destination 192.16
8.1.30 0.0.0.0

4、配置完成后,在R1上查看ACL配置。观察到,rule10后面的Inactive说明这条规则没有被激活(只在设备时间为time-range所指定的范围时才会被激活)。当ACL有多条规则时,默认情况下路由器将按照规则的序列号从低到高依次将报文与规则进行匹配,一旦某个报文匹配上了某条规则,则按规则指定的动作进行处理,不会再继续往下匹配;对于没有匹配上任何规则的报文,则按默认规则进行处理。

[R1]dis acl 3003
Advanced ACL 3003, 4 rules
Acl's step is 10
 rule 10 permit tcp source 172.16.3.0 0.0.0.255 destination 192.168.1.30 0 desti
nation-port eq www time-range pc-web (Inactive) 
 rule 20 permit tcp source 172.16.3.0 0.0.0.255 destination 192.168.1.10 0 desti
nation-port eq ftp 
 rule 30 permit icmp source 172.16.3.0 0.0.0.255 destination 192.168.1.10 0 
 rule 40 permit icmp source 172.16.3.0 0.0.0.255 destination 192.168.1.30 0 

5、将ACL 3003应用在IT区域和Trust区域之间的Inbound方向上,并查看配置情况。

[R1]firewall interzone IT trust     
[R1-interzone-trust-IT]packet-filter 3003 inbound 

[R1]dis firewall interzone IT trust 
interzone trust IT
 firewall enable
 packet-filter default deny inbound
 packet-filter default permit outbound
 packet-filter 3003 inbound

6、测试PC-3是否能访问Web-Server和Ftp-Server,以及是否能Ping通这两个服务器。

访问控制列表实验——PC3访问Ftp-Server 访问控制列表实验——PC3访问Web-Server

访问控制列表实验——PC3访问Ftp-Server2

访问控制列表实验——PC3访问Web-Server2

注意:在测试Ftp-Server时,文件传输模式请选择PORT模式;正确的结果是能Ping通,能以PORT模式访问Ftp-Server。

2.2.5.5 实现对设备的安全控制和管理

1、为了实现对R1的安全控制和管理,只允许SW1上的VLANIF 1接口的IP地址192.168.1.1能够作为源地址登录到R1。在SW1上创建VLANIF 1接口,配置IP地址为192.168.1.1/24,在R1上配置VTY用户接口,允许远程主机通过Telnet管理R1。

[SW1]int vlan 1
[SW1-Vlanif1]ip add 192.168.1.1 24
[R1]user-interface vty 0 4 
[R1-ui-vty0-4]authentication-mode password  
Please configure the login password (maximum length 16):huawei

2、使用基本ACL对路由器的VTY终端进行保护,只允许源地址为192.168.1.1的报文访问R1的VTY终端。

[R1]acl 2000
[R1-acl-basic-2000]rule permit source 192.168.1.1 0 
[R1]user-interface vty 0 4  
[R1-ui-vty0-4]acl 2000 inbound 

3、在SW1上使用命令telnet,按照提示输入密码后,就可以登录到R1上。

<SW1>telnet 192.168.1.254
Trying 192.168.1.254 ...
Press CTRL+K to abort
Connected to 192.168.1.254 ...

Login authentication

Password:
<R1>

4、测试,将SW1的VLANIF 1接口的IP地址修改为192.168.1.2。

[SW1]int vlan 1 
[SW1-Vlanif1]ip add 192.168.1.2 24

5、在SW1的用户视图下,再次测试是否能登录到R1。观察到登录失败。

<SW1>telnet 192.168.1.254 
Trying 192.168.1.254 ...
Press CTRL+K to abort
Error: Failed to connect to the remote host.

2.3 思考

ACL中的通配符(Wildcard Mask)的作用是什么?如果需要将172.16.16.0/24-172.16.31.0/24这个范围内的所有IP地址用一条ACL规则表示,那么通配符掩码应该是多少? 答:(1)rule permit source 172.16.16.0 0.0.15.255。(2)使用通配符掩码与原地址或者是目标地址一起来分辨匹配的地址范围.

三、基本的路由策略配置

3.1 原理概述

Route-Policy由一个或多个节点(Node)构成,Node之间是"或"的关系,每个Node都有一个编号,路由项按照Node编号由小到大的顺序通过各个Node。每个Node下可以有若干个if-match和apply子句(特殊情况下可以完全没有if-match和apply子句),if-match之间是"与"的关系。if-match子句用来定义匹配规则,即路由项通过当前Node所需要满足的条件,匹配对象是路由项的某些属性,比如路由前缀、Next Hop、Cost、路由优先级等;apply子句用来规定处理动作。 Route-Policy的每个Node都有对应的permit或deny模式。如果是permit模式,则当路由项满足该Node的所有If-match子句时,就被允许通过该Node的过滤并执行该Node的apply语句,不会进入下一个Node;如果路由项没有满足该Node的所有If-match子句,则会进入下一个Node继续进行过滤。如果是deny模式,则当该路由项满足该Node的所有If-match子句时,就被拒绝通过该Node的过滤,这时apply子句不会被执行,并且不进入下一个Node;否则就进入下一个Node继续进行过滤。

3.2 基本的路由策略配置实验

3.2.1 实验目的

1、掌握Route-Policy的基本配置方法 2、掌握使用Route-Policy进行路由过滤 3、掌握使用Route-Policy进行OSPF路由属性的修改

3.2.2 实验内容

本实验中,R2、R3、R4为某公司总部的路由器,R1为合作方的路由器,R1与R2和R4之间运行RIPv2,R3与R2和R4之间运行OSPF。R1的LoopBack1、LoopBack2、LoopBack3、LoopBack4分别用来模拟合作方内部的4个网段。网络管理员希望通过配置路由策略来实现R3去往192.168.1.0/24网段和192.168.3.0/24网段的流量经由路径R3-R2-R1,而去往192.168.2.0/24网段和192.168.4.0/24网段的流量经由路径R3-R4-R1,并且这两条路径互为备份。

3.2.3 实验拓扑

路由策略基本配置实验拓扑

3.2.4 实验编制表

设备 接口 IP地址 子网掩码 默认网关
R1(AR2220) S1/0/0 10.0.12.1 255.255.255.0 N/A
R1(AR2220) S1/0/1 10.0.14.1 255.255.255.0 N/A
R1(AR2220) Loop0 10.0.1.1 255.255.255.255 E3
R1(AR2220) Loop1 192.168.1.1 255.255.255.0 N/A
R1(AR2220) Loop2 192.168.2.1 255.255.255.0 N/A
R1(AR2220) Loop3 192.168.3.1 255.255.255.0 N/A
R1(AR2220) Loop4 192.168.4.1 255.255.255.0 N/A
R2(AR2220) S1/0/0 10.0.12.2 255.255.255.0 N/A
R2(AR2220) S1/0/1 10.0.23.1 255.255.255.0 N/A
R3(AR2220) S1/0/0 10.0.34.2 255.255.255.0 N/A
R3(AR2220) S1/0/1 10.0.23.2 255.255.255.0 N/A
R4(AR2220) S1/0/0 10.0.14.2 255.255.255.0 N/A
R4(AR2220) S1/0/1 10.0.34.1 255.255.255.0 N/A
### 3.2.5 实验步骤
#### 3.2.5.1 基本配置
根据实验编址表进行相应的基本配置,并使用ping命令检测R2与R1之间的连通性。
#### 3.2.5.2 搭建OSPF和RIP网络
1、R1、R2、R4之间运行RIPv2,R3与R2和R4之间运行OSPF。在R2和R4上将RIP路由引入到OSPF协议中。
[R1]rip 1
[R1-rip-1]version 2
[R1-rip-1]undo summary  
[R1-rip-1]network 10.0.0.0  
[R1-rip-1]network 192.168.1.0
[R1-rip-1]network 192.168.2.0
[R1-rip-1]network 192.168.3.0
[R1-rip-1]network 192.168.4.0

[R2]rip 1
[R2-rip-1]version 2
[R2-rip-1]undo summary 
[R2-rip-1]network 10.0.0.0
[R2-rip-1]ospf 
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 10.0.23.1 0.0.0.0

[R3]ospf 
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 10.0.23.2 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 10.0.34.2 0.0.0.0

[R4]rip 1
[R4-rip-1]
[R4-rip-1]version 2
[R4-rip-1]undo summary  
[R4-rip-1]network 10.0.0.0
[R4-rip-1]ospf 1
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network 10.0.34.1 0.0.0.0

[R2]ospf 1  
[R2-ospf-1]import-route rip

[R4]ospf 1  
[R4-ospf-1]import-route rip 

2、配置完成后,查看R3的路由表,检查R3是否收到了RIP路由信息。观察到,RIP进程中的路由已经被成功引进到OSPF进程中。默认情况下,被引入到OSPF中的路由的Cost值为1,Cost Type为Type-2,协议优先级的值为150。还观察到,由于R2和R4都做了路由引入,所以出现了路由冗余的现象。

[R3]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 19       Routes : 26       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.1.1/32  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
      10.0.12.0/24  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
      10.0.14.0/24  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
      10.0.23.0/24  Direct  0    0           D   10.0.23.2       Serial1/0/1
      10.0.23.1/32  Direct  0    0           D   10.0.23.1       Serial1/0/1
      10.0.23.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
    10.0.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
      10.0.34.0/24  Direct  0    0           D   10.0.34.2       Serial1/0/0
      10.0.34.1/32  Direct  0    0           D   10.0.34.1       Serial1/0/0
      10.0.34.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.34.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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
    192.168.1.0/24  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
    192.168.2.0/24  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
    192.168.3.0/24  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
    192.168.4.0/24  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

3.2.5.3 使用Route-Policy对引入到OSPF进程的路由进行过滤和修改。

1、默认情况下,引入路由的操作会将被被引入协议的所有路由都引入到目标协议中;如果需要对引入的路由信息进行某些过滤处理,或者对引入的路由信息的某些属性进行修改,则可以使用Route-Policy。现要求从R3去往192.168.1.0/24和192.168.3.0/24这两个网段的流量经由路径R3-R2-R1,同时还要求这两个网段的路由在R2上被引进OSPF时的Cost值为20,Cost Type为Type-1。另一方面,为了实现路由冗余,在R4上引入这两条路由时的Cost值为30,Cost Type为Type-1。当R3-R2-R1路径失效时,使用R3-R4-R1备份路径。 2、使用ACL将192.168.1.0/24和192.168.3.0/24这两个网段匹配出来。由于192.168.1.0/24和192.168.3.0/24的第三个字节都是奇数,可以通过下面的ACL通配符掩码直接进行匹配。

[R2]acl 2000    
[R2-acl-basic-2000]rule permit source 192.168.1.0 0.0.254.255

[R4]acl 2000    
[R4-acl-basic-2000]rule permit source 192.168.1.0 0.0.254.255

3、创建route-policy,在R2上将192.168.1.0/24和192.168.3.0/24引入到OSPF时Cost设置为20,Cost-type设置为type-1;在R4上将192.168.1.0/24和192.168.3.0/24引入到OSPF时Cost设置为30,Cost-type设置为type-1。

[R2]route-policy import-ospf permit node 5 
Info: New Sequence of this List.
[R2-route-policy]if-match acl 2000
[R2-route-policy]apply cost 20 
[R2-route-policy]apply cost-type type-1

[R4]route-policy import-ospf permit node 5 
Info: New Sequence of this List.
[R4-route-policy]if-match acl 2000  
[R4-route-policy]apply cost 30      
[R4-route-policy]apply cost-type type-1

4、在R2、R4上将RIP引入到OSPF时,应用Route-policy。

[R2]ospf 1
[R2-ospf-1]import rip route-policy import-ospf 

[R4]ospf 1  
[R4-ospf-1]import rip route-policy import-ospf

5、配置完成后,查看R3的IP路由表。可以看到,R3去往192.168.1.0/24和192.168.3.0/24的下一跳地址为10.0.23.1,即R2。

<R3>dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 14       Routes : 14       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      10.0.23.0/24  Direct  0    0           D   10.0.23.2       Serial1/0/1
      10.0.23.1/32  Direct  0    0           D   10.0.23.1       Serial1/0/1
      10.0.23.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
    10.0.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
      10.0.34.0/24  Direct  0    0           D   10.0.34.2       Serial1/0/0
      10.0.34.1/32  Direct  0    0           D   10.0.34.1       Serial1/0/0
      10.0.34.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.34.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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
    192.168.1.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.3.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

6、将R3上的S1/0/1接口关闭,观察路径是否能切换到R3-R4-R1上。观察到路径已切换到R3-R4-R1。

[R3]int s1/0/1
[R3-Serial1/0/1]shutdown 

[R3]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 10       Routes : 10       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      10.0.34.0/24  Direct  0    0           D   10.0.34.2       Serial1/0/0
      10.0.34.1/32  Direct  0    0           D   10.0.34.1       Serial1/0/0
      10.0.34.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.34.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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
    192.168.1.0/24  O_ASE   150  78          D   10.0.34.1       Serial1/0/0
    192.168.3.0/24  O_ASE   150  78          D   10.0.34.1       Serial1/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

7、重新开启R3的S1/0/1接口,恢复网络路由选择。

[R3]int s1/0/1  
[R3-Serial1/0/1]undo shutdown

8、现要求从R3去往192.168.2.0/24和192.168.4.0/24这两个网段的流量经由路径R3-R4-R1。同时要求这两个网段的路由在R4上被引进OSPF时Cost值为20、Cost-type为Type-2。为了实现路由冗余,在R2上引入两条路由时,Cost值为30、Cost-type为Type-2。当R3-R4-R1路径失效时,使用R3-R2-R1这条备份路径。 9、在R2和R4上配置ACL2001,匹配192.168.2.0/24和192.168.4.0/24这两个网段。

[R2]acl 2001
[R2-acl-basic-2001]rule permit source 192.168.2.0 0.0.254.255

[R4]acl 2001    
[R4-acl-basic-2001]rule permit source 192.168.2.0 0.0.254.255

10、在R2和R4上添加新的策略Node。

[R2]route-policy import-ospf permit node 10
Info: New Sequence of this List.
[R2-route-policy]if-match acl 2001
[R2-route-policy]apply cost 30 
[R2-route-policy]apply cost-type type-2

[R4]route-policy import-ospf permit node 10
Info: New Sequence of this List.    
[R4-route-policy]if-match acl 2001
[R4-route-policy]apply cost 20 
[R4-route-policy]apply cost-type type-2

11、配置完成后,查看R3的路由表。观察到从R3去往192.168.2.0/24和192.168.4.0/24这两个网段的流量经由路径R3-R4-R1。

<R3>dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 16       Routes : 16       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      10.0.23.0/24  Direct  0    0           D   10.0.23.2       Serial1/0/1
      10.0.23.1/32  Direct  0    0           D   10.0.23.1       Serial1/0/1
      10.0.23.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
    10.0.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
      10.0.34.0/24  Direct  0    0           D   10.0.34.2       Serial1/0/0
      10.0.34.1/32  Direct  0    0           D   10.0.34.1       Serial1/0/0
      10.0.34.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.34.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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
    192.168.1.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.2.0/24  O_ASE   150  20          D   10.0.34.1       Serial1/0/0
    192.168.3.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.4.0/24  O_ASE   150  20          D   10.0.34.1       Serial1/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

12、将R3上的S1/0/0接口关闭,观察路径是否能切换到R3-R2-R1上。观察到路径已切换到R3-R2-R1。

[R3]int s1/0/0
[R3-Serial1/0/0]shutdown

[R3]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 12       Routes : 12       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      10.0.23.0/24  Direct  0    0           D   10.0.23.2       Serial1/0/1
      10.0.23.1/32  Direct  0    0           D   10.0.23.1       Serial1/0/1
      10.0.23.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
    10.0.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/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
    192.168.1.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.2.0/24  O_ASE   150  30          D   10.0.23.1       Serial1/0/1
    192.168.3.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.4.0/24  O_ASE   150  30          D   10.0.23.1       Serial1/0/1
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

13、将R3上的S1/0/0接口恢复。

[R3]int s1/0/0  
[R3-Serial1/0/0]undo shutdown 

14、在route-policy中添加一个Node号相对最大的、模式为permit的Node,该Node下不需要定义任何if-match子句和apply子句,其含义是任何路由项都可以通过该Node。

[R2]route-policy import-ospf permit node 200
Info: New Sequence of this List.

[R4]route-policy import-ospf permit node 200
Info: New Sequence of this List.

15、配置完成后,查看R3的路由表。观察到R3接收到了关于10.0.1.1/32的路由信息。另外R1和R2互联的网段10.0.12.0/24以及R1和R4互联的网段10.0.14.0/24也被引进了OSPF中。

[R3]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 19       Routes : 22       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.1.1/32  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
      10.0.12.0/24  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
      10.0.14.0/24  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
      10.0.23.0/24  Direct  0    0           D   10.0.23.2       Serial1/0/1
      10.0.23.1/32  Direct  0    0           D   10.0.23.1       Serial1/0/1
      10.0.23.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
    10.0.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
      10.0.34.0/24  Direct  0    0           D   10.0.34.2       Serial1/0/0
      10.0.34.1/32  Direct  0    0           D   10.0.34.1       Serial1/0/0
      10.0.34.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.34.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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
    192.168.1.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.2.0/24  O_ASE   150  20          D   10.0.34.1       Serial1/0/0
    192.168.3.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.4.0/24  O_ASE   150  20          D   10.0.34.1       Serial1/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

16、针对R1和R2互联的网段10.0.12.0/24以及R1和R4互联的网段10.0.14.0/24,公司不希望将它们引入到OSPF中,要求在路由引入的时候,过滤掉这两个网段。使用前缀列表将这两个网段匹配出来,并在Route-Policy中增加新的Node,Node的模式为Deny。

[R2]ip ip-prefix hcdp index 10 permit 10.0.12.0 24 
[R2]ip ip-prefix hcdp index 20 permit 10.0.14.0 24
[R2]route-policy import-ospf deny node 15 
Info: New Sequence of this List.    
[R2-route-policy]if-match ip-prefix hcdp 

[R4]ip ip-prefix hcdp index 10 permit 10.0.12.0 24
[R4]ip ip-prefix hcdp index 20 permit 10.0.14.0 24
[R4]route-policy import-ospf deny node 15 
[R4-route-policy]if-match ip-prefix hcdp

17、在R2上查看路由策略的配置情况。

[R2]dis route-policy
Route-policy : import-ospf
  permit : 5 (matched counts: 16)
    Match clauses : 
      if-match acl 2000
    Apply clauses : 
      apply cost 20 
      apply cost-type type-1 
  permit : 10 (matched counts: 18)
    Match clauses : 
      if-match acl 2001
    Apply clauses : 
      apply cost 30 
      apply cost-type type-2
  deny : 15 (matched counts: 6)
    Match clauses : 
      if-match ip-prefix hcdp
  permit : 200 (matched counts: 6)

18、在R3上查看IP路由表。观察到,关于10.0.12.0/24和10.0.24.0/24的路由信息已经消失,而10.0.1.1/32依然存在,需求已满足。

<R3>dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 17       Routes : 18       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.1.1/32  O_ASE   150  1           D   10.0.23.1       Serial1/0/1
                    O_ASE   150  1           D   10.0.34.1       Serial1/0/0
      10.0.23.0/24  Direct  0    0           D   10.0.23.2       Serial1/0/1
      10.0.23.1/32  Direct  0    0           D   10.0.23.1       Serial1/0/1
      10.0.23.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
    10.0.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
      10.0.34.0/24  Direct  0    0           D   10.0.34.2       Serial1/0/0
      10.0.34.1/32  Direct  0    0           D   10.0.34.1       Serial1/0/0
      10.0.34.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.34.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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
    192.168.1.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.2.0/24  O_ASE   150  20          D   10.0.34.1       Serial1/0/0
    192.168.3.0/24  O_ASE   150  68          D   10.0.23.1       Serial1/0/1
    192.168.4.0/24  O_ASE   150  20          D   10.0.34.1       Serial1/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

3.3 思考

定义ACL的规则时会用到permit,定义Route-Policy的Node时也会用到permit一词,这两处的permit各是什么含义? 答:ACL中规则中的permit代表的是匹配该节点if-match子句。Route-Policy的Node中的permit代表的是整个路由策略的行为是permit。路由在本节点允许通过Route-Policy,匹配结束,不匹配if-match子句的路由进行Route-Policy下一个节点的匹配。

四、控制RIP路由的发布及路由引入

4.1 原理概述

RIP协议是一种在现实网络中得到广泛应用的路由协议,相比于其他路由协议,RIP最大特点就是非常简单而且易于实现。 RIP协议中,每台RIP路由器都会定时向它的直连邻居发布它所知道的所有路由信息,同时又不断接收直连邻居发来的路由信息并以及更新自己的路由表,如此反复迭代,从而实现整个网络的路由收敛。 利用一些策略工具来对引入到RIP进程中的路由进行过滤处理,从而实现某些特殊的网络需求。

4.2 控制RIP路由的发布及路由引入配置实验

4.2.1 实验目的

1、掌握使用Filter-Policy实现对RIP路由发布的控制。 2、加深对ACL规则匹配过程的理解。

4.2.2 实验内容

本实验通过一个简单场景,介绍了如何使用Filter-Policy和ACL来控制RIP协议的路由发布,以及如何使用Route-Policy和ACL对引入到RIP中的路由进行过滤处理。

4.2.3 实验拓扑

控制RIP路由的发布及路由引入实验拓扑

4.2.4 实验编制表

设备 接口 IP地址 子网掩码 默认网关
R1(AR2220) S1/0/0 10.0.12.1 255.255.255.0 N/A
R1(AR2220) S1/0/0 10.0.12.2 255.255.255.0 N/A
R1(AR2220) LoopBack0 10.0.1.1 255.255.255.255 N/A
R1(AR2220) LoopBack1 10.0.2.1 255.255.255.0 N/A
R1(AR2220) LoopBack2 10.0.3.1 255.255.255.0 N/A
R1(AR2220) LoopBack3 10.0.4.1 255.255.255.0 N/A
### 4.2.5 实验步骤
#### 4.2.5.1 基本配置
根据编址表进行相对应的配置,并使用ping命令检测R1和R2之间的连通性。
#### 4.2.5.2 使用Filter-Policy和ACL控制RIP协议的路由发布
1、在R1、R2上配置RIPv2的路由协议,并在R2上引入所有LoopBack接口的直连路由。
[R1]rip 1
[R1-rip-1]version 2
[R1-rip-1]undo summary 
[R1-rip-1]network 10.0.0.0

[R2]rip 1
[R2-rip-1]version 2
[R2-rip-1]undo summary  
[R2-rip-1]network 10.0.0.0  
[R2-rip-1]import-route direct 

2、配置完成后,查看R1的路由表。观察到R1已经接收到了关于R2上LoopBack接口的路由。

[R1]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 12       Routes : 12       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.1.1/32  RIP     100  1           D   10.0.12.2       Serial1/0/0
       10.0.2.0/24  RIP     100  1           D   10.0.12.2       Serial1/0/0
       10.0.3.0/24  RIP     100  1           D   10.0.12.2       Serial1/0/0
       10.0.4.0/24  RIP     100  1           D   10.0.12.2       Serial1/0/0
      10.0.12.0/24  Direct  0    0           D   10.0.12.1       Serial1/0/0
      10.0.12.1/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      10.0.12.2/32  Direct  0    0           D   10.0.12.2       Serial1/0/0
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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

3、在R2上利用Filter-Policy和ACL,禁止R2向R1发布10.0.1.1/32和10.0.3.0/24这两条路由信息。

[R2]acl 2000
[R2-acl-basic-2000]rule 5 deny source 10.0.1.0 0.0.254.255 
[R2-acl-basic-2000]rule permit source any 

[R2]rip 
[R2-rip-1]filter-policy 2000 export s1/0/0

4、配置完成后,查看R1的路由表。观察到10.0.1.1/32和10.0.3.0/24这两条路由信息已经消失。

[R1]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 10       Routes : 10       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.2.0/24  RIP     100  1           D   10.0.12.2       Serial1/0/0
       10.0.4.0/24  RIP     100  1           D   10.0.12.2       Serial1/0/0
      10.0.12.0/24  Direct  0    0           D   10.0.12.1       Serial1/0/0
      10.0.12.1/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      10.0.12.2/32  Direct  0    0           D   10.0.12.2       Serial1/0/0
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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

4.2.5.3 配置静态路由

1、在R1上配置静态路由,用以模拟外部网络。

ip route-static 1.0.0.0 255.0.0.0 NULL0
ip route-static 1.1.0.0 255.255.0.0 NULL0
ip route-static 1.1.1.0 255.255.255.0 NULL0
ip route-static 1.1.1.0 255.255.255.128 NULL0
ip route-static 1.1.1.1 255.255.255.255 NULL0

2、配置完成后,查看R1的IP路由表。观察到,配置的静态路由已经生效。

[R1]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 15       Routes : 15       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.0.0.0/8   Static  60   0           D   0.0.0.0         NULL0
        1.1.0.0/16  Static  60   0           D   0.0.0.0         NULL0
        1.1.1.0/24  Static  60   0           D   0.0.0.0         NULL0
        1.1.1.0/25  Static  60   0           D   0.0.0.0         NULL0
        1.1.1.1/32  Static  60   0           D   0.0.0.0         NULL0
       10.0.2.0/24  RIP     100  1           D   10.0.12.2       Serial1/0/0
       10.0.4.0/24  RIP     100  1           D   10.0.12.2       Serial1/0/0
      10.0.12.0/24  Direct  0    0           D   10.0.12.1       Serial1/0/0
      10.0.12.1/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      10.0.12.2/32  Direct  0    0           D   10.0.12.2       Serial1/0/0
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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

4.2.5.4 使用Route-Policy和ACL对引入到RIP中的路由进行过滤处理

1、在R1上将静态路由引入到RIP进程中,但只允许1.1.0.0/16被引入。使用ACL匹配1.1.0.0/16,规则号的步长设置为10.

[R1]acl 2000
[R1-acl-basic-2000]step 10  
[R1-acl-basic-2000]rule permit source 1.1.0.0 0.0.0.0

2、配置Route-Policy

[R1]route-policy import-rip permit node 10
[R1-route-policy]if-match acl 2000

3、引入静态路由,并应用route-policy对引入的静态路由进行控制

[R1]rip 1   
[R1-rip-1]import-route static route-policy import-rip 

4、配置完成后,查看R2的IP路由表。观察到仅有1.1.0.0/16路由被引入。

[R2]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 19       Routes : 19       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.0.0/16  RIP     100  1           D   10.0.12.1       Serial1/0/0
       10.0.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
       10.0.2.0/24  Direct  0    0           D   10.0.2.1        LoopBack1
       10.0.2.1/32  Direct  0    0           D   127.0.0.1       LoopBack1
     10.0.2.255/32  Direct  0    0           D   127.0.0.1       LoopBack1
       10.0.3.0/24  Direct  0    0           D   10.0.3.1        LoopBack2
       10.0.3.1/32  Direct  0    0           D   127.0.0.1       LoopBack2
     10.0.3.255/32  Direct  0    0           D   127.0.0.1       LoopBack2
       10.0.4.0/24  Direct  0    0           D   10.0.4.1        LoopBack3
       10.0.4.1/32  Direct  0    0           D   127.0.0.1       LoopBack3
     10.0.4.255/32  Direct  0    0           D   127.0.0.1       LoopBack3
      10.0.12.0/24  Direct  0    0           D   10.0.12.2       Serial1/0/0
      10.0.12.1/32  Direct  0    0           D   10.0.12.1       Serial1/0/0
      10.0.12.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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

5、现需要将1.1.1.0/24和1.1.1.0/25引入到RIP中。在ACL中添加新规则。

[R1]acl 2000
[R1-acl-basic-2000]rule 20 permit source 1.1.1.0 0.0.0.127

6、配置完成后,查看R1的ACL信息。

[R1]dis acl 2000
Basic ACL 2000, 2 rules
Acl's step is 10
 rule 10 permit source 1.1.0.0 0 (2 matches)
 rule 20 permit source 1.1.1.0 0.0.0.127 (3 matches)

7、查看R2的IP路由表。观察到除1.1.1.0/24和1.1.1.0/25之外还引入了1.1.1.1/32路由。

[R2]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 22       Routes : 22       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.0.0/16  RIP     100  1           D   10.0.12.1       Serial1/0/0
        1.1.1.0/24  RIP     100  1           D   10.0.12.1       Serial1/0/0
        1.1.1.0/25  RIP     100  1           D   10.0.12.1       Serial1/0/0
        1.1.1.1/32  RIP     100  1           D   10.0.12.1       Serial1/0/0
       10.0.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
       10.0.2.0/24  Direct  0    0           D   10.0.2.1        LoopBack1
       10.0.2.1/32  Direct  0    0           D   127.0.0.1       LoopBack1
     10.0.2.255/32  Direct  0    0           D   127.0.0.1       LoopBack1
       10.0.3.0/24  Direct  0    0           D   10.0.3.1        LoopBack2
       10.0.3.1/32  Direct  0    0           D   127.0.0.1       LoopBack2
     10.0.3.255/32  Direct  0    0           D   127.0.0.1       LoopBack2
       10.0.4.0/24  Direct  0    0           D   10.0.4.1        LoopBack3
       10.0.4.1/32  Direct  0    0           D   127.0.0.1       LoopBack3
     10.0.4.255/32  Direct  0    0           D   127.0.0.1       LoopBack3
      10.0.12.0/24  Direct  0    0           D   10.0.12.2       Serial1/0/0
      10.0.12.1/32  Direct  0    0           D   10.0.12.1       Serial1/0/0
      10.0.12.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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

8、ACL中添加一条拒绝规则。

[R1]acl 2000    
[R1-acl-basic-2000]rule deny source 1.1.1.1 0.0.0.0

9、配置完成后,继续查看R2的IP路由表。观察到,路由1.1.1.1/32仍然在路由表中。这是因为ACL在匹配规则时,假如前面规则匹配完后,就不再匹配后面的规则了。

[R2]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 22       Routes : 22       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.0.0/16  RIP     100  1           D   10.0.12.1       Serial1/0/0
        1.1.1.0/24  RIP     100  1           D   10.0.12.1       Serial1/0/0
        1.1.1.0/25  RIP     100  1           D   10.0.12.1       Serial1/0/0
        1.1.1.1/32  RIP     100  1           D   10.0.12.1       Serial1/0/0
       10.0.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
       10.0.2.0/24  Direct  0    0           D   10.0.2.1        LoopBack1
       10.0.2.1/32  Direct  0    0           D   127.0.0.1       LoopBack1
     10.0.2.255/32  Direct  0    0           D   127.0.0.1       LoopBack1
       10.0.3.0/24  Direct  0    0           D   10.0.3.1        LoopBack2
       10.0.3.1/32  Direct  0    0           D   127.0.0.1       LoopBack2
     10.0.3.255/32  Direct  0    0           D   127.0.0.1       LoopBack2
       10.0.4.0/24  Direct  0    0           D   10.0.4.1        LoopBack3
       10.0.4.1/32  Direct  0    0           D   127.0.0.1       LoopBack3
     10.0.4.255/32  Direct  0    0           D   127.0.0.1       LoopBack3
      10.0.12.0/24  Direct  0    0           D   10.0.12.2       Serial1/0/0
      10.0.12.1/32  Direct  0    0           D   10.0.12.1       Serial1/0/0
      10.0.12.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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

10、将ACL中rule30删除,重新配置一个规则,并使规则的序列号小于20.

[R1]acl 2000
[R1-acl-basic-2000]undo rule 30 
[R1-acl-basic-2000]rule 15 deny source 1.1.1.1 0

11、配置完成后,查看ACL以及IP路由表。

[R1]dis acl 2000
Basic ACL 2000, 3 rules
Acl's step is 10
 rule 10 permit source 1.1.0.0 0 (3 matches)
 rule 15 deny source 1.1.1.1 0 (2 matches)
 rule 20 permit source 1.1.1.0 0.0.0.127 (2 matches)

[R2]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 21       Routes : 21       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.0.0/16  RIP     100  1           D   10.0.12.1       Serial1/0/0
        1.1.1.0/24  RIP     100  1           D   10.0.12.1       Serial1/0/0
        1.1.1.0/25  RIP     100  1           D   10.0.12.1       Serial1/0/0
       10.0.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
       10.0.2.0/24  Direct  0    0           D   10.0.2.1        LoopBack1
       10.0.2.1/32  Direct  0    0           D   127.0.0.1       LoopBack1
     10.0.2.255/32  Direct  0    0           D   127.0.0.1       LoopBack1
       10.0.3.0/24  Direct  0    0           D   10.0.3.1        LoopBack2
       10.0.3.1/32  Direct  0    0           D   127.0.0.1       LoopBack2
     10.0.3.255/32  Direct  0    0           D   127.0.0.1       LoopBack2
       10.0.4.0/24  Direct  0    0           D   10.0.4.1        LoopBack3
       10.0.4.1/32  Direct  0    0           D   127.0.0.1       LoopBack3
     10.0.4.255/32  Direct  0    0           D   127.0.0.1       LoopBack3
      10.0.12.0/24  Direct  0    0           D   10.0.12.2       Serial1/0/0
      10.0.12.1/32  Direct  0    0           D   10.0.12.1       Serial1/0/0
      10.0.12.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
      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

4.3 思考

通配符掩码和反掩码(Inverted Subnet Mask)实质上是同一个概念吗? 答:(1)不是同一个概念(2)通配符掩码:1为严格匹配,0为任意匹配;通配符掩码可以使用不连续的1,它只匹配对应位置的1;反掩码:掩码的反码;反掩码必须使用连续的1。