我希望能够从码头容器中看到主机iptables。不一定要管理它,也许只读iptables就足够了。我已经给出了--cap=NET,并且网络模式被设置为host,但是iptables仍然显示在容器中为空。更确切地说,它似乎是一个不同的iptables名称空间或类似的东西。我可以从容器内部添加新规则,但这对主机iptables没有影响,当然。
root@host:~# iptables -xnvL OUTPUT
# Warning: iptables-legacy tables present, use iptables-legacy to see them
Chain OUTPUT (policy ACCEPT 1104394 packets, 407916631 bytes)
pkts bytes target prot opt in out source destination
16498 3125381 all -- * * 8.8.8.8 0.0.0.0/0
107211 59743643 all -- * * 192.168.0.1 0.0.0.0/0 root@host:~# docker exec ct_monitor_1 iptables -xnvL OUTPUT
Chain OUTPUT (policy ACCEPT 33081662 packets, 12617923760 bytes)
pkts bytes target prot opt in out source destination
206142 41989385 all -- * * 1.1.1.1 0.0.0.0/0
3686279 1919571839 all -- * * 172.0.0.1 0.0.0.0/0(规则是假的,只是为了表明容器有不同的iptables)
谢谢!
更新
我注意到这个问题发生在带有Ubuntu22.04和港口容器Ubuntu <=20.04的主机上。
为了澄清,我给出了更多的背景。
主机:
root@host:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
root@zitz:~# iptables -nvL OUTPUT
# Warning: iptables-legacy tables present, use iptables-legacy to see them
Chain OUTPUT (policy ACCEPT 437K packets, 229M bytes)
pkts bytes target prot opt in out source destination
285K 142M all -- * * 8.8.8.8 0.0.0.0/0
120K 83M all -- * * 192.168.0.1 0.0.0.0/0工作示例,请注意im使用ubuntu:jammy-20221003
root@zitz:~# docker run --rm -it --network=host --cap-add=NET_ADMIN ubuntu:jammy-20221003 bash
root@zitz:/# apt -qq -y update && apt install -qq -y iptables
root@zitz:/# iptables -nvL OUTPUT
# Warning: iptables-legacy tables present, use iptables-legacy to see them
Chain OUTPUT (policy ACCEPT 436K packets, 229M bytes)
pkts bytes target prot opt in out source destination
285K 142M all -- * * 8.8.8.8 0.0.0.0/0
120K 82M all -- * * 192.168.0.1 0.0.0.0/0非工作示例,我正在使用任何版本的ubuntu更低或等于20.04
root@zitz:~# docker run --rm -it --network=host --cap-add=NET_ADMIN ubuntu:focal bash
root@zitz:/# apt -qq update && apt install -y -qqq iptables
.
.
.
root@zitz:/# iptables -nvL OUTPUT
Chain OUTPUT (policy ACCEPT 148K packets, 53M bytes)
pkts bytes target prot opt in out source destination在这些情况下,iptables是“空”的。
更新2
发布于 2022-10-14 21:27:36
--network=host是你所需要的。如果使用--network=host,则所有网络接口,包括所有iptables都是共享的。
正如你所发现的,区别在于用户空间。您的主机系统使用的是nftable,而不是iptables。
https://stackoverflow.com/questions/74074082
复制相似问题