现在我们个需求:允许内网主机访问外部网络,而外部网络不能访问我们的内网,如果我们使用router(config)#access-list {access-list-number} deny ip any any 并在指定接口调用,那么,外部网络是不能够访问内部网络的,但内部网络的数据出去之后也回不来了,显然,我们并不想要这种结果。
我们知道TCP在建立连接之前,有一个三次握手过程,在TCP的包头里面有一个标志位,我们的扩展访问控制列表可以对这个标志位进行控制。我们分析下,内部主机向外发起连接的时候,SYN位为1,而外部的主机回应包里面为 SYN=1 ACK=1,而一个外部主机要想内部发起连接,他的第一个包只是SYN=1,而ACK=0,所以,我们可以使用Established ACL来达到我们想要的结果,命令如
R2(config)#ip access-list extended tcp
R2(config-ext-nacl)#permit tcp any any established
并在指定接口调用,然而Established ACL有一个致命的缺陷,它必须指定某一应用,如TCP,但我们可能会用到UDP、ICMP、PING等,为了解决这一问题,我们可以用自反ACL。接下来我们用实验来一一说明。
拓扑图:
#**#要求:R1能够Telnet到R3上,但R3不能够Telnet到R1上。
一、配置路由,使网络能够互通
R1的配置
R1(config)#int lo 0
R1(config-if)#ip address 10.1.1.1 255.255.255.0
R1(config-if)#int e0/1
R1(config-if)#ip address 12.1.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config)#router ospf 100
R1(config-router)#router-id 10.1.1.1
R1(config-router)#network 10.1.1.1 0.0.0.0 a 0
R1(config-router)#network 12.1.1.1 0.0.0.0 a 0
R2的配置
R2(config)#int lo 0
R2(config-if)#ip address 10.2.2.2 255.255.255.0
R2(config-if)#int e0/0
R2(config-if)#ip address 12.1.1.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#int e0/1
R2(config-if)#ip address 23.1.1.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exi
R2(config)#router ospf 100
R2(config-router)#router-id 10.2.2.2
R2(config-router)#network 10.2.2.2 0.0.0.0 a 0
R2(config-router)#network 12.1.1.2 0.0.0.0 a 0
R2(config-router)#network 23.1.1.2 0.0.0.0 a 0
R3的配置
R3(config)#int lo 0
R3(config-if)#ip address 10.3.3.3 255.255.255.0
R3(config-if)#int e0/0
R3(config-if)#ip address 23.1.1.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exi
R3(config)#router ospf 100
R3(config-router)#router-id 10.3.3.3
R3(config-router)#network 10.3.3.3 0.0.0.0 a 0
R3(config-router)#network 23.1.1.3 0.0.0.0 a 0
测试
R1#ping 10.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.3.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/6 ms
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:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/5 ms
二、配置Telnet
R1上配置Telnet
R1(config)#username xiaoming privilege 15 password xiaoming
R1(config)#line vty 0 4
R1(config-line)#login local
R1(config-line)#end
R3上配置Telnet
R3(config)#username xiaozhang privilege 15 password xiaozhang
R3(config)#line vty 0 4
R3(config-line)#login local
R3(config-line)#end
测试
R1#telnet 10.3.3.3
Trying 10.3.3.3 ... Open
User Access Verification
Username: xiaozhang
Password:
R3#
R1能够Telnet到R3上
R1#ping 10.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.3.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 2/3/6 ms
R1能ping通R3
R3#telnet 10.1.1.1
Trying 10.1.1.1 ... Open
User Access Verification
Username: xiaoming
Password:
R1#
R3能够Telnet到R1
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:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/2 ms
R3能ping通R1
由于并未做任何控制,R1与R3是可以相互Telnet的。
三、配置Established acl
R2(config)#ip access-list extended tcp //ACL的命名写法
R2(config-ext-nacl)#permit tcp any any established
R2(config-ext-nacl)#permit ospf any any //保持ospf路由正常运行
R2(config)#int e0/1 //在in方向调用
R2(config-if)#ip access-group tcp in
测试
R1#telnet 10.3.3.3
Trying 10.3.3.3 ... Open
User Access Verification
Username: xiaozhang
Password:
R3#
R1能够Telnet到R3
R1#ping 10.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.3.3.3, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
R1不能ping通R3
这个时候,我们发现R1不能ping通R3了,原为什么呢?
我们在访问控制列表中没有允许ICMP协议,所以返回的数据包在R2上面被拒绝掉了,但是telnet成功了,因为我们在进来的访问控制列表里允许了TCP。
R3#telnet 10.1.1.1
Trying 10.1.1.1 ...
% Destination unreachable; gateway or host down
R3#
R3不能够Telnet到R1
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:
.....
Success rate is 0 percent (0/5)
R3不能ping通R1
我们看R3是不能访问R1的任何东西了,为什么呢?ping不通的原因是我们在R2上阻止了ICMP,而telnet为什么不行呢,虽然我们允许了TCP包,但是因为是R3向R1发起初始化连接,TCP里面的标志位SYN=1,ACK=0,而我们的访问控制列表的关键词established定义了只有ACK=1的包才能被允许,所以,这个初始连接包就被拒绝了,那么我们这种做法就满足了试验要求。
但如果我们不仅想让R1能Telnet到R3,还能够ping通R3,可以用自反ACL
四、配置自反ACL
先在R2上删除Established acl
然后再配置自反acl
R2(config)#ip access-list extended k1
R2(config-ext-nacl)#permit ip any any reflect zifanlist
R2(config-ext-nacl)#permit ospf any any
R2(config-ext-nacl)#exit
R2(config)#ip access-list extended k2
R2(config-ext-nacl)#evaluate zifanlist
R2(config-ext-nacl)#permit ospf any any
R2(config-ext-nacl)#exit
R2(config)#int e0/1
R2(config-if)#ip access-group k1 out
R2(config-if)#ip access-group k2 in
查看路由
R1#sho ip route
Gateway of last resort is not set
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C 10.1.1.0/24 is directly connected, Loopback0
L 10.1.1.1/32 is directly connected, Loopback0
O 10.2.2.2/32 [110/11] via 12.1.1.2, 01:29:18, Ethernet0/1
O 10.3.3.3/32 [110/21] via 12.1.1.2, 00:58:43, Ethernet0/1
12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 12.1.1.0/24 is directly connected, Ethernet0/1
L 12.1.1.1/32 is directly connected, Ethernet0/1
23.0.0.0/24 is subnetted, 1 subnets
O 23.1.1.0 [110/20] via 12.1.1.2, 00:58:43, Ethernet0/1
R3#sho ip rou
R3#sho ip route
Gateway of last resort is not set
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
O 10.1.1.1/32 [110/21] via 23.1.1.2, 00:58:48, Ethernet0/0
O 10.2.2.2/32 [110/11] via 23.1.1.2, 00:58:48, Ethernet0/0
C 10.3.3.0/24 is directly connected, Loopback0
L 10.3.3.3/32 is directly connected, Loopback0
12.0.0.0/24 is subnetted, 1 subnets
O 12.1.1.0 [110/20] via 23.1.1.2, 00:58:48, Ethernet0/0
23.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 23.1.1.0/24 is directly connected, Ethernet0/0
L 23.1.1.3/32 is directly connected, Ethernet0/0
测试
R1#telnet 10.3.3.3
Trying 10.3.3.3 ... Open
User Access Verification
Username: xiaozhang
Password:
R3#
R1能够Telnet到R3
R1#ping 10.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.3.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/2 ms
R1能够ping通R3
R3#telnet 10.1.1.1
Trying 10.1.1.1 ...
% Destination unreachable; gateway or host down
R3不能够Telnet到R1
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也不能ping通R1
以上测验可以看出,R1内网主机不仅能够Telnet到R3内网主机,还能够ping通R3内网主机,但R3却不能够访问R1的任何数据。
写的不好,以后会来补充。
原文地址:http://blog.51cto.com/13596342/2123562