我对Ubuntu18.04上的iptables有问题,以前我使用过Centos 7和Red,我只需重新启动
systemctl restart iptables
但在Ubuntu上,它不起作用。我也无法在init.d
下找到iptable。
有人能帮我在Ubuntu18.04上重新启动或重新加载它吗?
发布于 2018-09-07 03:57:26
如果您希望您的Ubuntu防火墙以与RedHat/Fedora类似的方式运行,在Ubuntu 18.04 20.04 22.04中,您可能希望这样做:
sudo apt install iptables-persistent netfilter-persistent
然后在/etc/iptables/rules.v[46]
中编辑规则
其他可能有用的命令:
netfilter-persistent save
netfilter-persistent start
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
systemctl stop netfilter-persistent
systemctl start netfilter-persistent
systemctl restart netfilter-persistent
如果您发现您的规则在引导时没有正确应用,您可以运行以下命令来测试您的配置文件中没有错误:
iptables-restore < /etc/iptables/rules.v4
ip6tables-restore < /etc/iptables/rules.v6
这两个包是相似的,但提供的功能略有不同。如果只安装iptables-persistent
,则无法在systemd中获得用于正确处理的服务定义文件,如/lib/systemd/system/netfilter-persistent.service
如果您只安装netfilter-persistent
,您将发现在引导时没有按照自述文件正确地应用规则。
netfilter-persistent and its plugins
------------------------------------
netfilter-persistent does no work on its own. You need the accompanying
plugins (for example, iptables-persistent) to load and save filter rules.
However, commands are run from netfilter-persistent. For example, to save
all filter rules:
netfilter-persistent save
or to load them:
netfilter-persistent start
For more details, see `man netfilter-persistent`.
The system service will try to load rules at startup if enabled, but by
default it will not flush rules at shutdown. This behaviour can be changed
by editing /etc/default/netfilter-persistent.
发布于 2018-07-07 08:54:00
在较新的发行版中,通常有一个用于配置和管理防火墙的前端。现在最受欢迎的是ufw
和firewalld
,也许还有shorewall
。这些前端还注意在iptables
中添加规则,可以跳过iptables
脚本,或者更好地说应该跳过,因为前端不会直接提取您使用iptables
命令所做的更改。
对于Ubuntu18.04,firewalld
似乎已成为安装ufw
但不活动的默认位置。
root@localhost:~# firewall-cmd --state
running
root@localhost:~# ufw status
Status: inactive
因此,与其创建自己的iptables
遵从规则,还不如使用这些前端来创建防火墙配置。
我不熟悉ufw
,但你肯定会在这里找到信息,使用askubuntu或其他什么地方的互联网。
firewalld
附带了一个GUI (firewall-config
)和一个命令行工具firewall-cmd
。
对于firewalld
,您可以选择添加规则而不立即应用它(永久的),并且只在防火墙重新加载之后应用它。或者,您可以将它们添加到运行时配置中,进行测试,然后将其添加到永久配置中。
要将新添加的永久配置重新加载到运行规则中,您必须按以下方式输入命令,或者在GUI中执行相应的单击。
firewall-cmd --reload
乍一看,它看起来可能更复杂一些,因为firewalld
遵循的是区域和链概念。但是它很好地集成了NetworkManager,发布了一个图形用户界面.
熟悉它的一个好起点是这里。
发布于 2018-07-07 19:06:17
您可以使用以下方法检查包的内容:
dpkg -L iptables-persistent
然后您会发现以下命令是正确的:
/etc/init.d/netfilter-persistent restart
https://askubuntu.com/questions/1052919
复制相似问题