在 Linux 上使用 iptables 将特定 URL 列入黑名单

在 Linux 上使用 iptables 将特定 URL 列入黑名单

我能够使用以下命令将域/ip 地址列入黑名单,就像 ubuntu 上的 stackoverflow.com 一样

iptables -N mychain;
iptables -I OUTPUT -p tcp --dport 80 -j mychain;
iptables -I OUTPUT -p tcp --dport 443 -j mychain;
iptables -A mychain -m string --algo bm --string "stackoverflow.com" -j DROP

或者

iptables -A mobicontrol -d stackoverflow.com -j REJECT

问题:如果我必须屏蔽“https://stackoverflow.com/questions”而不是 stackoverflow.com,那么我如何才能仅屏蔽此特定网址。我尝试使用字符串算法,例如

iptables -A mychain -m string --algo bm --string "stackoverflow.com/questions" -j DROP
or
iptables -A mychain -m string --algo bm --string "questions" -j DROP

但无法阻止“https://stackoverflow.com/questions”和stackoverflow.com/documentation

答案1

iptables 在 OSI 的第 3/4 层上工作。即阻止对某些 IP 和端口的访问。您要求的是 URL 过滤。

iptables 不能用于执行 URL 过滤。

你可以使用类似微型代理过滤掉特定的 URL。

[1][https://tinyproxy.github.io/]

相关内容