linux下配置squid代理服务器

来源:互联网 发布:伪装地理位置软件官方 编辑:程序博客网 时间:2024/05/16 01:36
虚拟机linux可以上公网,内网ip是192.168.56.78
修改 /etc/squid/squid.conf,内容如下
http_port 192.168.56.78:8080
cache_mgr qwerty@gmail.com
cache_dir ufs /var/spool/squid 100 16 256
cache_mem 10 MB
cache_swap_low 90
cache_swap_high 95
cache_access_log /var/squid/access.log
cache_log /var/squid/cache.log
cache_store_log /var/squid/store.log
visible_hostname 192.168.56.78
client_netmask 255.255.255.0
acl advance src 192.168.56.2-192.168.56.254
http_access allow advance

执行配置文件验证,看是否有语法错误

squid -k parse

启动代理服务
chkconfig squid on
service squid start


虚拟机xp的上网模式是Host only,ip为192.168.56.23,和linux的192.168.56.78在同一个局域网。
选中IE浏览器的 工具,Internet选项,连接,局域网设置,指定代理服务器的ip为192.168.56.78端口为8080
经测试,IE可以上网,在linux下执行service squid stop,IE浏览器不能上网,再执行service squid start,IE浏览器又可以上网。

这说明linux的代理服务器设置成功了

关于访问控制:

(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)使用正则表达式,拒绝客户机通过代理服务器访问包含有诸如"sex"等关键字的网站: 
acl deny_url url_regex –i sex
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


关于透明代理:

2.6版本以前是:
http_port 3218 
httpd_accel_host virtual 
httpd_accel_port 80
httpd_accel_with_proxy on 
httpd_accel_uses_host_header on
解释:
http_port 3128:一般 squid 的 HTTP 监听端口为 3128,即 squid 默认设置值
httpd_accel_host virtual,httpd_accel_port 80:这两个选项本来是用来定义 squid 加速模式的。
在这里使用virtual来指定为虚拟主机模式。
80 端口为要加速的请求端口。采用这种模式时,Squid 就取消了缓存及ICP功能,假如需要这些功能,必须设置 httpd_accel_with_proxy选项。
httpd_accel_with_proxy on:该选项在透明代理模式下必须设置成on。
在该模式下squid既是web请求的加速器,又是缓存代理服务器。
httpd_accel_uses_host_header on:在透明代理模式下,如果想让代理服务器的缓存功能正确工作,必须将该选项设为on。设为on时,squid 会把存储的对象加上host header。(在HTTP/1.1中,HTTP请求包括一个Host首部,指定主机名或者主机的IP地址,但是HTTP/1.0没有Host 首部)

2.6以后是:
http_port 3128 transparent


设置iptables将目标端口为80的TCP包(HTTP 协议数据包)重定向到3128端口:
#echo 1 > /proc/sys/net/ipv4/ip_forward 
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128

原创粉丝点击