Squid访问控制方法的实例

安全 数据安全
《Squid访问控制:ACL元素以及访问列表》这篇文章为大家详细讲述了ACL元素以及http_access访问控制列表的语法以及使用过程中需要注意的问题,本文将给出使用这些访问控制方法的实例。

《Squid访问控制:ACL元素以及访问列表》这篇文章为大家详细讲述了ACL元素以及http_access访问控制列表的语法以及使用过程中需要注意的问题,下面给出使用这些访问控制方法的实例:

(1)允许网段61.0.3.188/24以及172.190.96.33/24内的所有客户机访问代理服务器,并且允许在文件/etc/squid/guest列出的客户机访问代理服务器,除此之外的客户机将拒绝访问本地代理服务器:

acl clients src 61.0.3.188/24 172.190.96.33/24

acl guests src “/etc/squid/guest”

acl all src 0.0.0.0/0.0.0.0

http_access allow clients

http_access allow guests

http_access deny all

其中,文件“/etc/squid/guest”中的内容为:

172.168.10.3/24

210.113.24.8/16

10.0.1.24/25

(2)允许域名为job.net、gdfq.edu.cn的两个域访问本地代理服务器,其他的域都将拒绝访问本地代理服务器:

acl permitted_domain src job.net gdfq.edu.cn

acl all src 0.0.0.0/0.0.0.0

http_access allow permitted_domain

http_access deny all

(3)使用正则表达式,拒绝客户机通过代理服务器访问包含有诸如“sexy”等关键字的网站:

acl deny_url url_regex –i sexy

http_access deny deny_url

(4)拒绝客户机通过代理服务器访问文件中指定IP或者域名的网站,其中文件/etc/squid/ deny_ip中存放有拒绝访问的IP地址,文件/etc/squid/deny_dns中存放有拒绝访问的域名:

acl deny_ip dst “etc/squid/deny_ip”

acl deny_dns dst “etc/squid/deny_dns”

http_access deny deny_ip

http_access deny deny_dns

(5)允许和拒绝指定的用户访问指定的网站,其中,允许客户1访问网站http://www.sina. com.cn,而拒绝客户2访问网站http://www.163.com:

acl client1 src 192.168.0.118

acl client1_url url_regex ^http://www.sina.com.cn

acl client2 src 192.168.0.119

acl client2_url url_regex ^http://www.163.com

http_access allow client1 client1_url

http_access deny client2 client2_url

(6)允许所有的用户在规定的时间内(周一至周四的8:30到20:30)访问代理服务器,只允许特定的用户(系统管理员,其网段为:  192.168.10.0/24)在周五下午访问代理服务器,其他的在周五下午一点至六点一律拒绝访问代理服务器:

acl allclient src 0.0.0.0/0.0.0.0

acl administrator 192.168.10.0/24

acl common_time time MTWH 8:30-20:30

acl manage_time time F 13:00-18:00

http_access allow allclient common_time

http_access allow administrator manage_time

http_access deny manage_time

(7)/etc/squid.conf,系统软件包提供、推荐的最小化配置如下,用户可以根据实际情况来进行定制

acl all src 0.0.0.0/0.0.0.0

acl manager proto cache_object

acl localhost src 192.168.10.3/255.255.255.255

acl SSL_ports port 443 563

acl Safe_ports port 80          # http

acl Safe_ports port 21          # ftp

acl Safe_ports port 443 563    # https, snews

acl Safe_ports port 70          # gopher

acl Safe_ports port 210         # wais

acl Safe_ports port 1025-65535 # unregistered ports

acl Safe_ports port 280         # http-mgmt

acl Safe_ports port 488         # gss-http

acl Safe_ports port 591         # filemaker

acl Safe_ports port 777         # multiling http

acl Safe_ports port 901         # SWAT

acl purge method PURGE

acl CONNECT method CONNECT

(...)

# Only allow cachemgr access from localhost

http_access allow manager localhost

http_access deny manager

# Only allow purge requests from localhost

http_access allow purge localhost

http_access deny purge

# Deny requests to unknown ports

http_access deny !Safe_ports

# Deny CONNECT to other than SSL ports

http_access deny CONNECT !SSL_ports

#

# INSERT YOUR OWN RULE(S)HERE TO ALLOW ACCESS FROM YOUR CLIENTS

#

http_access allow localhost

# And finally deny all other access to this proxy

http_access deny all

#Default:

# icp_access deny all

#

#Allow ICP queries from eveyone

icp_access allow all

配置带认证的代理服务抑制非法用户使用代理服务

默认时,Squid本身不带任何认证程序,但是可以通过外部认证程序来实现用户认证。一般有以下的认证程序:LDAP认证、SMB认证、基于mysql的认证、基于sock5的密码认证和基于Radius的认证。

下面介绍常用的ncsa实现的认证,ncsa是Squid源代码包自带的认证程序之一,从squid 2.5开始都包含了ncsa的模块。在Red Hat Enterprise Linux 发行套件的/usr/lib/squid目录下可以找到ncsa_auth文件。

要使用该认证服务,首先需要创建认证用户和密码:

#htpasswd -c /usr/local/squid/etc/ps_file guest

如果是以后添加用户的话就把-c的参数去掉。

然后,再更改/etc/squid/squid.conf主配置文件,添加如下:

//配置认证文件和用户文件

auth_param basic program /usr/lib/squid/ncsa_auth /usr/local/squid/etc/ ps_file

//指定认证程序的进程数

auth_param basic children 5

//代理服务器的名称

auth_param basic realm Squid proxy-caching web server

//认证有效时间为2小时

auth_param basic credentialsttl 2 hours

//只有认证用户才能访问

acl normal proxy_auth REQUIRED

http_Access allow normal

最后,重启squid服务即可。在浏览器里配上这个代理,打开任意网站,如果弹出了输入用户名和密码的对话框,就证明配置成功了。

责任编辑:蓝雨泪 来源: TechTarget中国
相关推荐

2012-09-18 09:43:14

Squid代理服务器安全网关

2010-09-01 16:43:26

Squid ACLSquid访问列表Squid

2009-02-01 10:54:00

MAC地址访问控制

2009-06-09 10:30:48

思科控制列表配置实例

2010-04-19 09:35:58

Oracle细粒度

2015-07-17 10:45:42

Squid服务器访问控制系统

2009-12-15 15:19:30

Ruby访问控制

2011-08-03 10:20:27

网络智能手机

2011-08-03 10:01:28

网络智能手机

2010-08-06 10:10:17

思科路由器动态访问列表

2013-08-22 09:55:14

2013-08-20 10:19:38

2009-02-05 10:12:00

访问控制列表限制访问

2011-03-04 14:24:49

FTP访问

2011-05-20 10:53:01

2020-12-23 09:40:17

物联网安全访问控制

2023-12-06 21:50:40

2011-03-14 17:50:27

访问控制列表

2011-03-10 15:22:08

访问控制机制Java

2010-04-14 15:45:49

Oracle 数据库
点赞
收藏

51CTO技术栈公众号