基于ACL过滤telnet和特定的网段信息

什么是访问控制列表(ACL)?

应用于路由器接口的指令列表,用于指定哪些数据包可以接收转发,哪些数据包需要拒绝

ACL的工作原理:

  1. 1.读取第三层及第四层包头中的信息
  2. 2.根据预先定义好的规则(Deny or Permit)对包进行过滤

基本类型的访问控制列表,本文主讲扩展的访问控制列表:

  1. 1.标准访问控制列表
  2. 2.扩展访问控制列表
  3. 3.命名的访问控制列表

我们以下面的例子作为实验进行讲解:

描述要求:

1.     使用OSPF协议使得全网互通,需要测试

2.     使用访问控制列表,使主机PC1不可以访问主机PC3,但可以访问其他设备

3.     使用访问控制列表,PC2不可以远程登录Server,其他设备可以远程登录Server

拓扑:

VPLS和VXLAN有什么区别_网络工程师

配置命令:

1.    配置PC机IP地址和网关地址:

2.    如果使用路由器代替PC需要手工配置网关地址

PC1:
PC1(config)#interface Ethernet0/0
PC1(config-if)#ip address 192.168.1.1255.255.255.0
PC1(config)#ip default-gateway 192.168.1.254
PC2:
PC2(config)#interface Ethernet0/0
PC2(config-if)#ip address 192.168.2.1255.255.255.0
PC2(config)#ip default-gateway 192.168.2.254
PC3:
PC3(config)#interface Ethernet0/0
PC3(config-if)#ip address 192.168.3.1255.255.255.0
PC3(config)#ip default-gateway 192.168.3.254
PC4:
PC4(config)#interface Ethernet0/0
PC4(config-if)#ip address 192.168.3.2255.255.255.0
PC4(config)#ip default-gateway 192.168.3.254
3.    配置路由器R1、R2接口IP地址,根据需求使用OSPF路由协议使得全网互通
R1(config)#interface Ethernet0/0
R1(config-if)#ip address 192.168.1.254255.255.255.0
R1(config)#interface Ethernet0/1
R1(config-if)#ip address 192.168.2.254255.255.255.0
R1(config)#interface Ethernet0/2
R1(config-if)#ip address 12.12.12.1255.255.255.252
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 12.12.12.0 0.0.0.3area 0
R1(config-router)#network 192.168.1.0 0.0.0.255area 0
R1(config-router)#network 192.168.2.0 0.0.0.255area 0
R2(config)#interface Ethernet0/0
R2(config-if)#ip address 12.12.12.2255.255.255.252
R2(config)#interface Ethernet0/1
R2(config-if)#ip address 192.168.3.254255.255.255.0
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 12.12.12.0 0.0.0.3area 0
R2(config-router)#network 192.168.3.0 0.0.0.255area 0
4.    进行测试,是否是全网互通,必须检查,否则不知道ACL配置完成后是否有效果
PC1 ping PC2、PC3、PC4:
PC1#ping 192.168.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.1,timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-tripmin/avg/max = 5/5/6 ms
PC1#ping 192.168.3.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.3.1,timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-tripmin/avg/max = 1/1/1 ms
PC1#ping 192.168.3.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.3.2,timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-tripmin/avg/max = 1/1/1 ms

5.    使用访问控制列表进行过滤,使得主机PC1不可以访问主机PC3,但可以访问其他设备

因为标准的访问控制列表是根据源地址进行过滤的,没有办法做到精确匹配,所以我们选择使用扩展的访问控制列表,扩展的访问控制列表是根据五元素组(源IP,目的IP,传输层协议,源端口和目的端口)每个条件都必须匹配,才会施加允许或拒绝条件,使用扩展ACL可以实现更加精确的流量控制,访问控制列表号从100到199

VPLS和VXLAN有什么区别_access exex控制pc_02

所以我们选择在R1进行配置,因为可以精确过滤,所以可以在出方向的接口(距离源地址最近的进出接口进行过滤),我们在R1进接口E0/0接口调用,

配置命令如下:

R1:(注意:一定要在接口调用,否则不会生效)
R1(config)#access-list 100 deny ip host192.168.1.1 host 192.168.3.1
R1(config)#access-list 100 permit ip any any———默认拒绝一切,所以需要放行其他网段
R1(config)#interface e0/0
R1(config-if)#ip access-group 100 in
检查:
PC1#ping 192.168.3.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.3.1, timeout is 2 seconds:
UUUUU
Success rate is 0 percent (0/5)
PC1#ping 192.168.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.1,timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-tripmin/avg/max = 2/4/6 ms
PC1#ping 192.168.3.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.3.2,timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-tripmin/avg/max = 1/1/1 ms
6.    在Server配置远程登录(我的是路由器模拟的)
在配置前需要在R2配置网关地址,并将这个接口宣告进OSPF中,保证可以ping通。
R2:
R2(config)#interface Serial2/0
R2(config-if)#ip address 10.1.1.254255.255.255.0
R2(config-if)#ip ospf 1 area 0
Server:(设置登录密码和enable密码)
Server(config)#line vty 0 4
Server(config-line)#password CCIE
Server(config-line)#login
Server(config-line)#transport input telnet
Server(config)#enable password CCIE

检查:

VPLS和VXLAN有什么区别_访问控制列表_03

7.配置访问控制列表,拒绝主机PC2远程登录到Server,同样在R1的进接口E0/1调用:

R1:

R1(config)#access-list101 deny tcp host 192.168.2.1 host 10.1.1.1 eq telnet(或写端口号23)
R1(config)#access-list 101 permit tcp any any
R1(config)#interface Ethernet0/1
R1(config-if)#ip address 192.168.2.254 255.255.255.0
R1(config-if)#ip access-group 101 in

检查:

VPLS和VXLAN有什么区别_access exex控制pc_04

总结:

正常情况下,我们还可以禁止其他协议的流量,比如ICMP报文有:

⑴echo-request:为ping使用的环路测试请求;
⑵echo-reply:为ping使用的环路测试回应;
⑶packet-too-big:某些程序用来侦测目标地址路径上的MTU;
⑷time to live(TTL)  ttl-exceeded :tracerouter 测试网络报

文生存周期;

⑸destinationhost unreachable:通知会话目标不可达

这些我们都可以通过扩展的访问控制列表进行过滤,注意写的时候不要把端口号写错了,当然也可以直接写这个单词,以上就是关于使用扩展的ACL去过滤某一个特定的网段和过滤一些特定的协议流量(本文案例是Telnet)。