我是 iptables 新手,我想阻止除“user”和 root 之外的所有用户的网络访问。我设置iptables如下:
$ sudo iptables -L OUTPUT
target prot opt source destination
ACCEPT all -- anywhere anywhere owner UID match user
ACCEPT all -- anywhere anywhere owner UID match root
ACCEPT all -- anywhere anywhere owner socket exists
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
然后我以“其他”身份登录并执行以下操作(使用 Google 的 IP 地址之一):
$ whoami
other
$ wget http://172.217.19.36
--2020-06-25 18:43:16-- http://172.217.19.36/
Connecting to 172.217.19.36:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2020-06-25 18:43:16-- http://www.google.com/
Resolving www.google.com (www.google.com)... failed: Name or service not known.
wget: unable to resolve host address 'www.google.com'
换句话说,iptables 允许非“用户”或 root 用户使用 wget 访问 Google。
我究竟做错了什么?
根据 EchoMike444 的有用建议,我现在有以下规则集:
iptables -A OUTPUT -m owner --uid-owner user -j ACCEPT
iptables -A OUTPUT -m owner --uid-owner root -j ACCEPT
iptables -A OUTPUT -m owner --uid-owner systemd-resolve -j ACCEPT
iptables -A OUTPUT -o lo -p icmp -j ACCEPT
iptables -A OUTPUT -j REJECT
这似乎可以解决问题:我仍然可以访问外部世界,其他用户不能,但是由于规则 4,仍然允许来自规则 5 的 ICMP 拒绝消息通过。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句