首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从码头容器管理主机iptables

从码头容器管理主机iptables
EN

Stack Overflow用户
提问于 2022-10-14 19:35:07
回答 1查看 72关注 0票数 -1

我希望能够从码头容器中看到主机iptables。不一定要管理它,也许只读iptables就足够了。我已经给出了--cap=NET,并且网络模式被设置为host,但是iptables仍然显示在容器中为空。更确切地说,它似乎是一个不同的iptables名称空间或类似的东西。我可以从容器内部添加新规则,但这对主机iptables没有影响,当然。

代码语言:javascript
复制
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           
代码语言:javascript
复制
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的主机上。

为了澄清,我给出了更多的背景。

主机:

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

我认为我的问题与此有关:https://serverfault.com/questions/1097499/warning-iptables-legacy-tables-present-use-iptables-legacy-save-to-see-them

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-14 21:27:36

--network=host是你所需要的。如果使用--network=host,则所有网络接口,包括所有iptables都是共享的。

正如你所发现的,区别在于用户空间。您的主机系统使用的是nftable,而不是iptables。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74074082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档