如果它只是iptables规则管理器,为什么必须在启动时重新启动UFW?

来自源包的README说:

When installing ufw from source, you will also need to integrate it into your boot process for the firewall to start when you restart your system. Depending on your needs, this can be as simple as adding the following to a startup script (eg rc.local for systems that use it): # /lib/ufw/ufw-init start For systems that use SysV initscripts, an example script is provided in doc/initscript.example. See doc/upstart.example for an Upstart example. Consult your distribution's documentation for the proper way to modify your boot process. 

在我的系统上我有这个:

 # /etc/ufw/ufw.conf # # Set to yes to start on boot. If setting this remotely, be sure to add a rule # to allow your remote connection before starting ufw. Eg: 'ufw allow 22/tcp' ENABLED=yes 

那么,为什么需要在启动时启动简单的iptables规则管理器? 这有什么秘密,或者只是检查所有规则是否到位?

引导系统时,没有防火墙规则。 内核不会将它们保存到任何地方。

如果您不启动UFW(或其他防火墙管理器),则您的iptables为空。 此外,每个链(FORWARD,INPUT,OUTPUT)的默认规则是ACCEPT,因此允许所有内容。

因此,UFW不只是检查,它实际上是在制定这些规则,并创建用于规则管理的其他链。

当您运行iptables(用于在Linux中操作netfilter防火墙规则的低级工具)时,规则仅加载到内核中,因此位于RAM中。 当您关闭或重新启动时,内核会重新初始化,因为RAM不是永久内存,并且默认为所有表(或没有防火墙)的ACCEPT。

因此,要在引导后使用防火墙,必须将iptables规则加载到内核中。 您可以通过将iptables规则添加到在引导时运行的脚本(例如/etc/rc.local)来手动执行此操作,或者使用工具为您执行此操作。 ufw是一个这样的工具,如果它被启用,它将负责为你启动加载防火墙规则,如果它被集成到启动过程中,如README所说。 如果ufw是为您的发行版打包的,就像在Ubuntu中一样,那么打包将为您处理。 简单地说,在Ubuntu中通过apt-get安装ufw之后,除了运行’sudo ufw enable’之外,你不必再做任何事情来将它集成到系统中。

要保存ufw状态,您必须运行以下命令:

 sudo invoke-rc.d iptables-persistent save 

那么您的规则将在重启后保存并加载。