WPAD+Squid

目标:匹配域名关键字,实现特定域名自动代理

环境如下:

1、客户端:Windows 7+Chrome

2、2台CentOS 6.4服务器,1台做DNS,1台做Squid+HTTP

3、DHCP服务器(华为交换机)

步骤:

一、DHCP Server启地址池,并指定option252

ip pool xxx
 gateway-list x.x.x.x
 network x.x.x.x mask x.x.x.x
 dns-list x.x.x.x
 option 252 ascii http://proxy.test.com/proxy.pac

二、DNS服务器增加proxy.test.com解析

1、named.conf文件

zone "test.com" {
      type master;
      file "test.com.db";
      allow-update { 127.0.0.1; };
};

2、test.com.db文件

$TTL 1D
@       IN SOA  ns.test.com. mail.test.com.(
                                        2016050801      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      ns.test.com.
@       A       x.x.x.x
ns      A       x.x.x.x
mail    A       x.x.x.x
proxy   A       Squid服务器的IP1
proxy   A       Squid服务器的IP2

三、HTTP+Squid服务

1、HTTP

启HTTP是为了让客户端从Squid服务器获取pac文件的内容

yum -y install httpd

vi /var/www/html/proxy.pac

这里按照格式写需要匹配的域名的关键字

function FindProxyForURL(url, host)
{
if (
shExpMatch(host, "*google*") ||
shExpMatch(host, "*facebook*") ||
shExpMatch(host, "*youtube*") ||
shExpMatch(host, "*twitter*") ||
)
return 'PROXY proxy.test.com:3128';
return 'DIRECT';
}

重启http服务:/etc/init.d/httpd restart

2、squid

yum -y install squid

/etc/init.d/squid start

四、客户端配置

1、IE和chrome浏览器设置

2、其他浏览器设置

posted @ 2016-05-08 23:36  OhLee  阅读(387)  评论(0编辑  收藏  举报