Squid Web Cache Wiki

Squid Web Cache 文档

🔗 使用 FreeBSD 上的 PF 拦截流量

基于 Chris Benech 的 OpenBSD 示例

🔗 目录

此配置适用于 FreeBSD 8/9、MP 内核和 Squid 2.6 或更高版本。

:information_source: NAT配置仅在在squid盒子上使用时才有效。这是准确和安全地执行拦截所必需的。要从网关机拦截并将流量指向单独的squid盒,请使用策略路由

🔗 Squid 配置

首先,编译并安装 Squid。它需要以下选项

./configure --with-pthreads --enable-pf-transparent --with-nat-devpf

您需要像这样配置 Squid 以便它知道 IP 地址正在被拦截:

http_port 3129 transparent

:warning: 在 Squid 3.1+ 中,*transparent* 选项已被拆分。使用 **intercept** 来捕获 PF 数据包。

http_port 3129 intercept

🔗 pf.conf 配置

在 pf.conf 中,需要进行以下更改。

在顶部设置内部接口的 skip 的部分,删除那些行。它们告诉 pf 过滤器不要处理来自内部接口的数据包。

#set skip on $int_if << These lines commented out 
#set skip on $wi_if

# redirect only IPv4 web traffic to squid 
rdr pass inet proto tcp from 192.168.231.0/24 to any port 80 -> 192.168.231.1 port 3129

block in
pass in quick on $int_if
pass in quick on $wi_if
pass out keep state

一些提示

🔗 测试

要测试是否有效,请使用 **nc** 工具。停止 squid,然后从 root 命令提示符中输入

nc -l 3129

然后重新启动 squid 并尝试浏览一个页面。

您现在应该看到类似以下的输出

<root:openbsd> [/root]
> nc -l 3129
GET / HTTP/1.1
User-Agent: Mozilla/5.0 (compatible; GNotify 1.0.25.0)
Host: example.com
Connection: keep-alive
...

从那时起,只需正常设置您的浏览器,无需代理服务器,您就应该看到缓存已满,并且您的浏览速度加快。


⚠️ Disclaimer: Any example presented here is provided "as-is" with no support
or guarantee of suitability. If you have any further questions about
these examples please email the squid-users mailing list.

类别: ConfigExample

导航:站点搜索站点页面分类🔼 向上