WSL2无法启用ufw



对WSL2感兴趣。这是我接触Linux的方式,在我决定安装Nginx并允许它在ufw中运行之前,我乱了一段时间。当我用:

启用它时
sudo ufw enable 

它回复:

ERROR: problem running ufw-init
iptables-restore v1.8.4 (legacy): Couldn't load match `limit':No such file or directory
Error occurred at line: 63
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.8.4 (legacy): Couldn't load match `limit':No such file or directory
Error occurred at line: 21
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Problem running '/etc/ufw/before.rules'
Problem running '/etc/ufw/user.rules'

所以,我已经尝试了很多事情。首先,重新启动服务,然后重置ufw,删除并重新安装。在某个时候,我决定把Ubuntu 18.04换成20.04,结果出现了一个非常相似的错误。

ERROR: problem running ufw-init
modprobe: FATAL: Module nf_conntrack_ftp not found in directory /lib/modules/5.4.72-microsoft-standard-WSL2
modprobe: FATAL: Module nf_nat_ftp not found in directory /lib/modules/5.4.72-microsoft-standard-WSL2
modprobe: FATAL: Module nf_conntrack_netbios_ns not found in directory /lib/modules/5.4.72-microsoft-standard-WSL2
iptables-restore: line 75 failed
iptables-restore: line 27 failed
ip6tables-restore: line 27 failed
Problem running '/etc/ufw/before.rules'
Problem running '/etc/ufw/user.rules'
Problem running '/etc/ufw/user6.rules'

我到文件中注释这行,并取得了一些成功,可以解决前两个错误,但不能解决最后一个错误。我为Windows防火墙添加了一条规则,尝试使用Debian发行版,结果返回的结果比前两个糟糕得多。

ERROR: problem running ufw-init
modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/5.4.72-microsoft-standard-WSL2/modules.dep.bin'
modprobe: FATAL: Module nf_conntrack_ftp not found in directory /lib/modules/5.4.72-microsoft-standard-WSL2
modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/5.4.72-microsoft-standard-WSL2/modules.dep.bin'
modprobe: FATAL: Module nf_nat_ftp not found in directory /lib/modules/5.4.72-microsoft-standard-WSL2
modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/5.4.72-microsoft-standard-WSL2/modules.dep.bin'
modprobe: FATAL: Module nf_conntrack_netbios_ns not found in directory /lib/modules/5.4.72-microsoft-standard-WSL2
iptables-restore v1.8.2 (nf_tables):
line 22: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 23: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 24: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 25: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 26: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 27: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 29: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 30: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 31: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 32: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 33: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 34: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 36: RULE_APPEND failed (No such file or directory): rule in chain FORWARD
line 41: RULE
iptables-restore v1.8.2 (nf_tables): Couldn't load match `conntrack':No such file or directory
Error occurred at line: 2
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.8.2 (nf_tables):
line 5: RULE_APPEND failed (No such file or directory): rule in chain ufw-skip-to-policy-input
line 6: RULE_APPEND failed (No such file or directory): rule in chain ufw-skip-to-policy-output
line 7: RULE_APPEND failed (No such file or directory): rule in chain ufw-skip-to-policy-forward
iptables-restore v1.8.2 (nf_tables): Couldn't load match `conntrack':No such file or directory
Error occurred at line: 25
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.8.2 (nf_tables): unknown option "--dport"
Error occurred at line: 19
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.8.2 (nf_tables): unknown option "--log-prefix"
Error occurred at line: 21
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.8.2 (nf_tables): Chain 'ufw-before-input' does not exist
ip6tables-restore v1.8.2 (nf_tables):
line 22: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 23: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 24: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 25: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 26: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 27: RULE_APPEND failed (No such file or directory): rule in chain INPUT
line 29: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 30: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 31: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 32: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 33: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 34: RULE_APPEND failed (No such file or directory): rule in chain OUTPUT
line 36: RULE_APPEND failed (No such file or directory): rule in chain FORWARD
line 41: RULE
ip6tables-restore v1.8.2 (nf_tables): Couldn't load match `conntrack':No such file or directory
Error occurred at line: 2
Try `ip6tables-restore -h' or 'ip6tables-restore --help' for more information.
ip6tables-restore v1.8.2 (nf_tables):
line 5: RULE_APPEND failed (No such file or directory): rule in chain ufw6-skip-to-policy-input
line 6: RULE_APPEND failed (No such file or directory): rule in chain ufw6-skip-to-policy-output
line 7: RULE_APPEND failed (No such file or directory): rule in chain ufw6-skip-to-policy-forward
ip6tables-restore v1.8.2 (nf_tables): Couldn't load match `rt':No such file or directory
Error occurred at line: 24
Try `ip6tables-restore -h' or 'ip6tables-restore --help' for more information.
ip6tables-restore v1.8.2 (nf_tables): unknown option "--dport"
Error occurred at line: 19
Try `ip6tables-restore -h' or 'ip6tables-restore --help' for more information.
ip6tables-restore v1.8.2 (nf_tables): unknown option "--log-prefix"
Error occurred at line: 21
Try `ip6tables-restore -h' or 'ip6tables-restore --help' for more information.
ip6tables-restore v1.8.2 (nf_tables): Chain 'ufw6-before-input' does not exist
Problem running '/etc/ufw/before.rules'
Problem running '/etc/ufw/after.rules'
Problem running '/etc/ufw/user.rules'
Problem running '/etc/ufw/before6.rules'
Problem running '/etc/ufw/after6.rules'
Problem running '/etc/ufw/user6.rules'

所以,我大胆猜测并想象这个问题来自Windows本身而不是WSL2,但我在网上没有找到任何可以帮助我的东西。有些我在这里。

有人知道什么可以帮助我吗?谢谢。

首先,您需要启用systemd,因为UFW是作为systemd服务运行的:

在Windows 11上启用WSL 2中的systemd

TLDR添加到您的/etc/wsl.conf:

[boot]
systemd=true

然后在admin PowerShell中:

wsl --shutdown

然后重新打开你的Ubuntu终端以"重启";


这些错误表明ufw还需要一些默认情况下当前未在WSL2内核中启用的内核模块。我知道我必须重新编译WSL2内核,并对防火墙进行一些调整才能正常工作。

但首先我要尝试系统部分,这可能已经解决了你的问题。请回来报告。

相关内容

  • 没有找到相关文章

最新更新