🔗 在 Linux 上使用 IPFW 拦截流量
作者:Brian Feeny
🔗 目录
此配置信息截至 Linux 2.0.33* 最新
NAT 配置仅在**在 squid 服务器上**使用时才有效。这是准确和安全地执行拦截所必需的。要从网关机器拦截流量并将其定向到单独的 squid 服务器,请使用 策略路由
🔗 ipfwadm 配置 (/etc/rc.d/rc.local)
将 SQUIDIP 替换为 squid 可能用于发送流量的公共 IP。对于 squid 使用的每个此类 IP,请重复 ipfwadm 行。
# Accept all on loopback
ipfwadm -I -a accept -W lo
# Accept my own IP, to prevent loops (repeat for each interface/alias)
ipfwadm -I -a accept -P tcp -D SQUIDIP 80
# Send all traffic destined to port 80 to Squid on port 3129
ipfwadm -I -a accept -P tcp -D 0/0 80 -r 3129
它在端口 80 上接受数据包,并将它们重定向到 3127,这是我的 squid 进程正在运行的端口。
🔗 Squid 配置
首先,编译并安装 Squid。它需要以下选项
./configure --enable-ipfw-transparent
您需要像这样配置 Squid 以便它知道 IP 地址正在被拦截:
http_port 3129 transparent
-
在 Squid 3.1+ 中,transparent 选项已被拆分。使用 ‘intercept 来捕获 IPFW 数据包。
http_port 3129 intercept
🔗 测试
要测试是否有效,请使用 **nc** 工具。停止 squid,然后从 root 命令提示符中输入
nc -l 3129
然后重新启动 squid 并尝试浏览一个页面。
您现在应该看到类似以下的输出
> 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
导航:站点搜索、站点页面、分类、🔼 向上