寻找 iptables 示例

寻找 iptables 示例

我可以给出一个使用 iptables 仅允许访问两个网站的 bash 脚本示例吗?

我想使用它来在本地建立白名单并将我对网络的访问限制在有限的几个地方。

我想在我的工作站(我的台式电脑)上运行它

谢谢

答案1

你通常不会用 iptables 来做这个,你可以使用类似乌贼具有合适 acl 的代理,例如

acl OKSites dstdomain "/usr/local/etc/allowed-sites.squid"

#
# Add this at the top of the http_access section of squid.conf
#
http_access allow OKSites
http_access deny all

其中,allowed-sites.squid 文件包含允许的站点列表

google.com
oterhdomain.co.uk

如果你真的必须使用 iptables 来做到这一点,那么

# deny everything
iptables -P OUTPUT DROP

# Allow DNS
iptables -I OUPUT -p udp --dport 53 -j ACCEPT

iptables -I OUTPUT -p tcp -d serverfault.com --dport 80 -j ACCEPT
iptables -I OUTPUT -p tcp -d stackoverflow.com --dport 80 -j ACCEPT

将允许访问 DNS。请注意,使用此方法,只有将规则添加到过滤器时,站点的 IP 地址才会更新。如果站点的 IP 地址发生变化,则将再次启用访问,因此您需要重新加载规则。

相关内容