R2#conf t Enter configuration commands, one per line. End with CNTL/Z. R2(config)#access-list 1 deny 30.1.1.0 0.0.0.255 R2(config)#access-Ust 1 permit any R2(config)#int s0 R2(config-if)#ip access-group 1 in R2(config-if)#^Z R2#sh 14:34:20: %SYS-5-CONFIG_1: Configured from console by console R2#sh ip access-list 1 Standard IP access list 1 deny 30.1.1.0,wukdcard buts 0.0.0.255 check=2 permit any(2 matches) R2#sh ip int s0 Serial0 is up, line protocol is up Internet address is 20.1.1.2/24 Broadcast address is 255.255.255.255 Address determined by setup command MTU is 1500 bytes Helper address is not set Directed broadcast forwarding is disabled Multicast reserved groups joined: 224.0.0.9 Outgoing access list is not set Inbound access list is 1 Proxy ARP is enabled Security level is default ... (输出省略) R2#clear access-list counters
R2#sh ip access-1 1 Standard IP access list 1 deny 30.1 .IA wildcard bits 0.0.0.255 permit any R2# Term_Server#3 [Resuming connection 3 to R3 ... ]
R3#ping 10.1.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echosto 10.1.1.1, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5). round-tri/min/avg/max=:32/37/48 ms R3#ping Protocol [ip]: Target IP address: 10.1.1.1 Repeat count [5]: Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: y Source address or interface: 30.1.1.3 Type of service [0]: Set DF bit in IP header? [no]: Validate reply data? [no]: Data pattern [0xABCD]: Loose, Strict, Record, Timestamp, Verbose[none]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 5,100-byte ICMP Echos to 10.1.1.1,timeout is 2 seconds: U.U.U Success rate is 0 percent (0/5) R3#^Z Term_Server#2 [Resuming connection 3 to R2 ... ] R2#sh ip access-1 1 Standard IP access list 1 deny 30.1.1.0, wildcard bits 0.0.0.255 (5 matches) checks 15 permit any (5 matches)
(1)在定义访问控制列表时,要特别注意语句输入的先后顺序,因为路由器在执行该列表时的顺序是自上而下的。 另一个应注意的问题是路由器不对由自身产生的IP进行过滤,在实验时应由其他的设备发包进行测试。 (2)配置标准IP访问控制列表1时,定义了除30.1.1.0/24网段外的所有网段都被接受。 (3)在R2路由器S0接口的进入方向引用了访问控制列表1,目的是过滤来自30.1.1.0/24网段的数据包,允许其他所有网段的数据包通过。 在接口上引用访问控制列表时,使用in或out子命令。这里的in和out是指以路由器本身为参考点,数据包是进入 (in)还是离开(out)路由器。 (4)show ip access-list命令列出了所定义的访问控制列表的情况,可以看到"permit any"一行有2个匹配包的报告,表示已经有2个匹配此行条件的数据包被S0接口接收。 (5)show ip int sO命令列出的信息中加阴影的2行是关于访问控制列表引用情况的信息,表明在进入路由器的方向(而)引用了访问控制列表1。 (6)接下来用clear access-list counters指令清空了访问控制列表的计数器。以便观察实验结果。所谓清空计数器,就是把访问控制列表各行的匹配数清空。 再次使用show ip access-list命令查看显示了我们想得到的结果。 (7)使用ping和扩展的ping命令测试访问控制列表1的定义和引用情况,结果为: 从20.1.1.3发往10.1.1.1的IP包被R2接收和路由. 从30.1.1.3发往10.1.1.1的IP包被R2过滤掉。 测试结果符合访问控制列表的设置。 (8)再次查看访问控制列表的匹配情况,可以看到,在访问控制列表1中,2条语句各有5个相匹配的包,即5个ICMP Echo包。
R2#conft Enter configuration commands, one per line. End with CNTL/Z. R2(config)#access-list 101 deny icmp 20.1.1.0 0.0.0.255 10.1.1.0 0.0.0.255 echo R2(config)#access-list 101 permit ip any any R2(config)#int e0 R2(config-if)#ip access-g 101 out R2(config-if)#int s0 R2(config-if)#no ipaccess-g 1 in R2(config-if)#^Z R2# R2#sh ip access-list Standard IP access list 1 deny 30.1.1.0, wildcard bits 0.0.0.255 (8 matches) check=20 permit any (20 matches) permit ip any any
R2# Term_Server#3 [Resuming connection 3 to R3 ...] R3#ping 10.1.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds: U.U.U Success rate is 0 percent(0/5) R3#telnet 10.1.1.1 Trying 10.1.1.1... Open
[Connection to 10.1.1.1 closed by foreign host] R3# Term_Server#2 [Resuming connection 2 to R2 ... ]
R2#sh ip access-list 101 Extended IP access list 101 deny icmp 20.1.1.0 0.0.0.255 10.1.1.0.0.0.0.255 echo(8 matches) permit ip any any (40 matches) R2#