Squid Web Cache Wiki

Squid Web Cache 文档

🔗 Linux 流量源头拦截使用 DNAT

🔗 目录

:warning: 除非作为其他系统的最后备份,否则不建议使用 NAT 拦截。还有其他方法,例如 Proxy WPAD/PAC、Linux http_proxy 环境变量以及 Windows 浏览器配置策略强制执行。所有这些方法都同样有效,并且在涉及多个客户端时遇到的问题更少。

此配置旨在利用 NAT 拦截在与 Squid 运行在同一台机器上的其他软件生成的 Web 请求,而无需任何客户端应用程序配置或代理支持。这种方法具有极强的侵入性,除非能够完全控制客户端机器(例如,恶意应用程序服务器),否则不适用。

:information_soiurce: NAT 配置仅在 **在 Squid 服务器上** 使用时才有效。这是准确且安全地执行拦截所必需的。要从网关机拦截并将流量导向独立的 Squid 服务器,请使用 策略路由

🔗 iptables 配置

:warning:SQUIDIP 替换为 Squid 可用于监听端口和出站连接的公共 IP 地址。

:information_source: 您可能还需要将 Squid 运行的 UID “squid” 替换为 cache_effective_user 账户。这可能取决于您的操作系统,可能是使用默认值“nobody”、“squid”或“proxy”。

    iptables -t nat -A OUTPUT --match owner --uid-owner squid -p tcp --dport 80 -j ACCEPT    
    iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination SQUIDIP:3129

🔗 Squid 配置文件

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

http_port 3129 transparent

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

http_port 3129 intercept

⚠️ 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

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