iptables 命令和 iptables.service 服务 有什么关系 ?

news/2024/7/2 8:59:13

写在前面


  • 关于iptables 命令 和 iptabls.service 的一些疑惑
  • 理解不足小伙伴帮忙指正

傍晚时分,你坐在屋檐下,看着天慢慢地黑下去,心里寂寞而凄凉,感到自己的生命被剥夺了。当时我是个年轻人,但我害怕这样生活下去,衰老下去。在我看来,这是比死亡更可怕的事。--------王小波


我对 iptables 命令 和 iptabls.service 的一些疑惑,在 unix.stackexchange.com 提了相关问题,有小伙伴为我做了解答,下面为问题和答案

我一直以为因为有 iptables.service 服务才可以使用 iptables 命令,实际上并不是这样的,iptalbes 是基于内核的,和 iptables.service 没有关系,不用安装任何工具包就可以使用 iptable 命令添加的防火墙规则,只是添加的规则是临时的,基于内存的,会在系统重启前消失,所以需要 iptables.service,firewalld.service 来对添加的规则进行保存。在系统重启后重载对应的防火墙规则,在系统关机时卸载对应的规则。


问题:

What is the difference between the iptables command and iptables.service?

I always thought I could only use the iptables command if I had the iptables.service service installed, but then I found out I was wrong

┌──[root@vms16.liruilongs.github.io]-[~]
└─$systemctl status iptables.service
Unit iptables.service could not be found.
┌──[root@vms16.liruilongs.github.io]-[~]
└─$iptables -A INPUT -p icmp --icmp-type 13 -j DROP
┌──[root@vms16.liruilongs.github.io]-[~]
└─$iptables -A OUTPUT -p icmp --icmp-type 14 -j DROP

After adding the rule, it took effect immediately

Without the iptables.service service, the command can still be used

┌──[root@vms16.liruilongs.github.io]-[~]
└─$whereis iptables
iptables: /usr/sbin/iptables /usr/libexec/iptables /usr/share/man/man8/iptables.8.gz
┌──[root@vms16.liruilongs.github.io]-[~]
└─$which iptables
/usr/sbin/iptables

I’m curious why we need iptables.service and what it means, for simplicity we can use firewalld.service.


┌──[root@vms16.liruilongs.github.io]-[~]
└─$yum -y install  iptables-services.x86_64 > /dev/null
┌──[root@vms16.liruilongs.github.io]-[~]
└─$systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
   Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

I installed it and found only the configuration file

┌──[root@vms16.liruilongs.github.io]-[~]
└─$rpm -qlc iptables
/etc/sysconfig/ip6tables-config
/etc/sysconfig/iptables-config

What else does iptable.service do?

Can I assume so? iptables is kernel related and does not require iptables.service to be installed to work, but I see a lot of people reloading configuration files and restarting iptable.service after changing iptable rules, is that the right idea?


答案:

The iptables command is used to add or delete rules and chains and can be used without the service file. What iptables.service does is to automatically load a saved ruleset on boot and to unload the rules at shutdown. There’s a few safety checks in the scripts, like setting default chain policies to ACCEPT on shutdown, to prevent the system from having unusable rulesets. If you want to manually load rules every time you boot the system you can, the service just makes it easier.

firewalld presents a simpler interface to defining rules than iptables but that is really the major difference. And underneath the covers, firewalld uses iptables to implement the rules. Personally, I prefer using iptables but I have gotten used to the configuration over the years. The choice of iptables or firewalld is really up to what you’re comfortable with.


Thank you very much, it solved my doubts. Am I to understand that the rules configured with iptables are temporary, in-memory behavior (like /proc), not persistent, and if the system is rebooted, the rules are gone unless you export the data before shutting down. iptables.service automatically saves these rules and loads them automatically after a reboot. @doneal24 –
山河以无恙


@山河以无恙 Your understanding is correct. Any changes made by the iptables command will disappear when you reboot unless you save them and then reload after the boot. –
doneal24


在这里插入图片描述

博文参考

https://unix.stackexchange.com/questions/727282/what-is-the-difference-between-the-iptables-command-and-iptables-service-or-wha


http://lihuaxi.xjx100.cn/news/326935.html

相关文章

LeetCode简单题之回环句

题目 句子 是由单个空格分隔的一组单词,且不含前导或尾随空格。 例如,“Hello World”、“HELLO”、“hello world hello world” 都是符合要求的句子。 单词 仅 由大写和小写英文字母组成。且大写和小写字母会视作不同字符。 如果句子满足下述全部条…

Vue2 开发/学习 笔记

路由监听 新增/修改之后返回到主页面时,重新调一下查询接口watch: {$route(to, from) {if (to.name == InvestStructureAdjust) {this.handleQuery

人工智能与机器学习

欢迎关注博主 Mindtechnist 或加入【Linux C/C/Python社区】一起探讨和分享Linux C/C/Python/Shell编程、机器人技术、机器学习、机器视觉、嵌入式AI相关领域的知识和技术。 人工智能与机器学习📝人工智能相关概念☞什么是人工智能、机器学习、深度学习☞人工智能发…

信号和电源隔离的有效设计技术

介绍 如今,电子产品设计师比以往任何时候都更面临着一系列共同的目标:实现更高的吞吐量、更高的分辨率、更高效的系统和缩短上市时间。在工业自动化、医疗电子或电信系统等领域,通常需要电隔离多个信号,以使子系统能够共享数据或…

第九章 聚类

9.1 聚类任务 在无监督学习中,训练样本的标记信息是未知的,目标是通过对无标记训练样本的学习来揭示数据的内在性质及规律。为进一步的数据分析提供基础。此类学习任务中研究最多、应用最广的是“聚类”。 聚类试图将数据集中的样本划分为若干个通常是不…

【机器学习实战】对加州住房价格数据集进行数据探索(读书笔记)

1. 数据集描述及获取 数据集下载地址:housing.csv数据集的结构: 其中数据集有10个属性,分别为经度、纬度、housing_median_age、房间总数、卧室总数、人口数、家庭数、收入中位数、房价中位数、ocean_proximity。 2. 对数据集进行探索 2.…

优品汇系统开发机制介绍

优品汇系统通过通过消费增值模式,促进商品流通,打造中g最大的供应链。作为对政策的回应,绿点刺激实体经济。前期通过科学合理的业务体系,将大部分利润分配给客户和朋友,从而快速创造人气和粉丝数据。中期将逐步完善产品…

解决 Android 分享到小程序 封面显示不全

参考:解决Android 微信分享小程序图片显示不全_Keung丶的博客-CSDN博客_小程序分享图片显示不全 上面分享的封面还是不满足需求,我们需求是填充满高度或者宽度,在原基础上做修改: 修改后: /*** Bitmap 分享到小程…