🔗 Linux 上的 Squid 和浏览器流量拦截
- 作者:Joshua N Pritikin
🔗 目录
无需任何客户端配置即可透明拦截 Web 请求。当 Web 流量由运行 Squid 的机器生成时。
NP:对于大多数非 Windows 盒子,设置 http_proxy 环境变量(http_proxy=”http://SQUIDIP:3128/”)是以下拦截的首选替代方案。
NP:其他用户报告设置传出的 TOS 并基于此进行过滤,而不是基于进程 gid,也有效。
🔗 iptables 配置
-
将 SQUIDIP 替换为 Squid 可能用于其监听端口和出站连接的公共 IP。每个 iptables 行重复一次,对应一个 Squid 出站 IP。
iptables -t nat -F # clear table
# normal transparent proxy
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -j REDIRECT --to-port 3127
# handle connections on the same box (SQUIDIP is a loopback instance)
gid=`id -g proxy`
iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner --gid-owner $gid -j ACCEPT
iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination SQUIDIP:3127
🔗 Squid 配置文件
您需要像这样配置 Squid 以便它知道 IP 地址正在被拦截:
http_port 3127 transparent
-
在 Squid 3.1+ 中,transparent 选项已被拆分。使用 ‘intercept 来捕获 DNAT 数据包。
http_port 3127 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
导航:站点搜索、站点页面、分类、🔼 向上