首先,我的理解是 iptables 是用户空间的客户端工具,用于对真正的防火墙服务 netfilter 进行规则创建等功能。那么 firewalld 又是啥?
为啥我关闭防火墙是关闭 systemctl stop firewalld ?
如果我关闭了防火墙,是不是意味着我 iptables-save 输出的一系列防火墙规则其实是没用的? 但是我部署在上面的 k8s 集群好像又表现得很正常。
因为安装 linkerd 出现一个容器启动错误,说是没有 modprobe: can't change directory to '/lib/modules': No such file or directory\niptables-save v1.8.8 (legacy): Cannot initialize: iptables who? (do you need to insmod?) 所以就查阅了一些,越查越困惑。这里我理解我的主机是 centos8 ,用 iptables -V 查看时新版本的 iptables ,所以没有加载旧版本的。那么这里我在宿主机上加载新旧两个版本的 iptables 会有什么问题吗?
1 wonderblank 2023-01-03 10:11:03 +08:00 建议去看书,这里提问问不出来有实质性的答案,而且很多都是错的。 |
![]() | 2 NoahNye 2023-01-03 10:23:31 +08:00 ![]() netfilter:里世界,实际应用规则的人,但不能直接操作, iptables:因为不能直接操作里世界,所以在表世界映射成 iptables 供用户使用, firewall 、ufw:让用户使用更爽的一层 iptables 封装。 |
![]() | 3 ysc3839 2023-01-03 10:25:34 +08:00 个人理解,netfilter 是内核提供的 API ,允许其他模块 hook 网络流量,iptables 通过调用 netfilter API 来实现各种功能。 firewalld 是用户模式的 iptables 管理工具,通过一些简化的语法来生成对应复杂的 iptables 规则。 |
4 lolizeppelin 2023-01-03 10:32:38 +08:00 ![]() --------先给你解释 iptable 和 firewalld 的关系 假设实际的防火墙规则是一条条内核中的记录 那么 iptable-save 就是用自己格式输出、保存的防火墙规则 iptabale 的其他命令行工具能对防火墙规则进行增删改查 iptable 本质就是清空防火墙规则 保存防火墙规则 推送保存的防火墙规则的工具 由于 iptable 对复杂规则的使用不够友好,所以设计了 firewalld 这个以 xml 存储防火墙规则的程序 但是无论是 iptable 还是 firewalld,最后操作的都是内核中的记录,所以无论使用 firewalld 还是 iptable 修改、列出的规则都是内核中的规则 现在都是尽量避免使用 iptable 来操作防火墙,都是用 firewalld 来配置 -------这里解释容器相关防火墙 容器实现靠的是操作系统的 namespace,每个 namespace 有自己的路由和防火墙规则 默认所有操作都在 default namespace 中, 你直接执行 iptable-save 导出的是 default namespace 的防火墙规则 default namespace 是系统中所有正常启动的进程所在的 namespace 你想获取容器中的防火墙规则,需要切换到指定容器对应的 namespace 中执行 iptable-save 具体的 namespace exce 命令随便查下就知道了 |
![]() | 5 dzdh 2023-01-03 10:36:05 +08:00 ![]() 防火墙本体是内核的 NetFilter 。 iptables 是 mysql-cli firewalld 是 navicat ufw 是 heidisql |
![]() | 6 isno 2023-01-03 10:55:41 +08:00 |
![]() | 7 zhangsanfeng2012 2023-01-03 11:01:03 +08:00 还有 nftables |
![]() | 8 mrzx 2023-01-03 14:04:04 +08:00 最底层的是 NetFilter 然后实际操作层是 iptables 而 firewall 我认为是 iptables 命令简化版的 gui 作为 12 年的运维工程师,还是更偏向于 iptables 新生代更偏向于用 firewall ,因为命令更简单,通俗易懂. 现在基于 ubuntu 的程序员更多,所以他们更喜欢用傻瓜相机版的 ufw |
9 lolizeppelin 2023-01-03 14:35:58 +08:00 ufw 不知道,filewall 本质还是 iptable 比如 filewall 标准语法不能描述的规则都用 direct 实现 direct 里面都是 iptable 的语法 话说前端娱乐圈搞那么多状态管理.... linux 搞两三个防火墙管理怎么了!! 才两三个你们就叫,写前端不得疯 |
![]() | 10 uncat 2023-01-03 14:53:34 +08:00 @NoahNye 最新的 firewalld 不使用 iptables 了,使用的是 nftables 不直接使用 iptables ,使用 firewalld 是因为: firewalld 是有状态的,可以实现有状态运维管理(基于 ansible + git 的代码化运维) |
11 leonshaw 2023-01-03 15:16:17 +08:00 >> 因为安装 linkerd 出现一个容器启动错误,说是没有 modprobe 宿主机上把需要的内核模块先装上。用户态不同版本一般没关系。 |
![]() | 12 FabricPath 2023-01-03 15:25:15 +08:00 netfilter 是个框架,iptables 是用户态工具(iptables之类的命令)+内核模块( lsmod|grep -i ipt),在 netfilter 有几个 iptables 的 hook ,firewalld 就是一个 iptables 规则生成器。 不过这个年代别学 iptables 了,马上就被 nft 替代了,你看到的 iptables-legacy 就是传统 iptables ,在新的发行版本里面 iptables 就是 nftable 的一层皮 |
13 kaneg 2023-01-03 15:37:07 +08:00 你这个容器貌似需要高级权限的操作,可能需要设置 privileged: true |
![]() | 15 swsh007 2023-01-03 15:42:55 +08:00 via Android 还是习惯 iptables |
![]() | 17 stephenyin 2023-01-03 18:48:17 +08:00 @dzdh #5 本来挺了解的东西,直接被你比喻到我的知识盲区了。。。 |
![]() | 18 dzdh 2023-01-03 22:16:25 +08:00 @stephenyin #17 :) |
![]() | 19 tomychen 2023-01-06 16:52:37 +08:00 ![]() 如果把 netfilter 理解为防火墙的核心的话,iptables/firewalld/ufw 这些就都算是跟核心通话的传话员。 老板说把 192.168.1.100 那龟孙给我拦下 iptables call netfilter 老板说了,192.168.1.100 那龟孙给 drop 了,然后那龟孙就被 drop 了。 192.168.1.200 那小子是我家亲戚放他进来 iptables call netfilter 老板说了,192.168.1.200 那小子可以进场,然后他 accept 了 至于 iptables firewalld ufw 的区别呢 其实都是传话的。 Redhat 系 把 firewalld 这马甲推出来呢,想让大家觉得这玩意更像个防火墙,但还是个传话筒 Ubuntu 系 不服,你搞个 firewalld ,我也得整活,我来个 ufw ,再配置个牛 X 的名字“Uncomplicated Firewall”,于是 ufw 就这么出来了.. iptables 笑而不语,换个名字,还真当自己进内核了?还不是传话筒... |
![]() | 20 raysonx 2023-01-06 17:57:16 +08:00 另外补充,iptables 已经过时了,现在新的发行版用的都是 nftables ,新版 firewalld 也是用 nftables 作后端。 |