如何在 Ubuntu 20.10 中获取 UFW(可能需要升级 iptables 或你的内核)

如何在 Ubuntu 20.10 中获取 UFW(可能需要升级 iptables 或你的内核)

这是我的 Ubuntu 20.10,如果我理解正确的话,uname 会显示错误版本

# uname -r
4.15.0-60-generic

因为

# ls -la /boot
total 147492
drwxr-xr-x  4 root root     4096 Feb 11 21:21 .
drwxr-xr-x 19 root root     4096 Feb 11 01:07 ..
-rw-r--r--  1 root root   248258 Jan 18 17:01 config-5.8.0-41-generic
-rw-r--r--  1 root root   248258 Feb  5 03:41 config-5.8.0-43-generic
drwxr-xr-x  4 root root     4096 Feb 11 21:21 grub
lrwxrwxrwx  1 root root       27 Feb 11 21:21 initrd.img -> initrd.img-5.8.0-43-generic
-rw-r--r--  1 root root 55795996 Feb 11 01:07 initrd.img-5.8.0-41-generic
-rw-r--r--  1 root root 55798352 Feb 11 21:21 initrd.img-5.8.0-43-generic
lrwxrwxrwx  1 root root       27 Jan 28 07:27 initrd.img.old -> initrd.img-5.8.0-41-generic
drwx------  2 root root    16384 Feb 11 01:07 lost+found
-rw-------  1 root root  5635676 Jan 18 17:01 System.map-5.8.0-41-generic
-rw-------  1 root root  5635676 Feb  5 03:41 System.map-5.8.0-43-generic
lrwxrwxrwx  1 root root       24 Feb 11 21:21 vmlinuz -> vmlinuz-5.8.0-43-generic
-rw-------  1 root root 13715296 Jan 18 17:08 vmlinuz-5.8.0-41-generic
-rw-------  1 root root 13715296 Feb  5 04:04 vmlinuz-5.8.0-43-generic
lrwxrwxrwx  1 root root       24 Jan 28 07:27 vmlinuz.old -> vmlinuz-5.8.0-41-generic
 # dpkg -l | grep linux-
ii  linux-base                           4.5ubuntu4                        all          Linux image base package
ii  linux-firmware                       1.190.3                           all          Firmware for Linux kernel drivers
ii  linux-generic                        5.8.0.43.48                       amd64        Complete Generic Linux kernel and headers
ii  linux-headers-5.8.0-41               5.8.0-41.46                       all          Header files related to Linux kernel version 5.8.0
ii  linux-headers-5.8.0-41-generic       5.8.0-41.46                       amd64        Linux kernel headers for version 5.8.0 on 64 bit x86 SMP
ii  linux-headers-5.8.0-43               5.8.0-43.49                       all          Header files related to Linux kernel version 5.8.0
ii  linux-headers-5.8.0-43-generic       5.8.0-43.49                       amd64        Linux kernel headers for version 5.8.0 on 64 bit x86 SMP
ii  linux-headers-generic                5.8.0.43.48                       amd64        Generic Linux kernel headers
ii  linux-image-5.8.0-41-generic         5.8.0-41.46                       amd64        Signed kernel image generic
ii  linux-image-5.8.0-43-generic         5.8.0-43.49                       amd64        Signed kernel image generic
ii  linux-image-generic                  5.8.0.43.48                       amd64        Generic Linux kernel image
ii  linux-modules-5.8.0-41-generic       5.8.0-41.46                       amd64        Linux kernel extra modules for version 5.8.0 on 64 bit x86 SMP
ii  linux-modules-5.8.0-43-generic       5.8.0-43.49                       amd64        Linux kernel extra modules for version 5.8.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.8.0-41-generic 5.8.0-41.46                       amd64        Linux kernel extra modules for version 5.8.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.8.0-43-generic 5.8.0-43.49                       amd64        Linux kernel extra modules for version 5.8.0 on 64 bit x86 SMP
 #  ls -lha /lib/modules
total 16K
drwxr-xr-x  4 root root 4.0K Feb 11 21:21 .
drwxr-xr-x 47 root root 4.0K Feb 11 21:22 ..
drwxr-xr-x  5 root root 4.0K Jan 28 07:27 5.8.0-41-generic
drwxr-xr-x  5 root root 4.0K Feb 11 21:21 5.8.0-43-generic

当我尝试安装 UFW 时,收到错误 错误:无法确定 iptables 版本 我见过 iptables 版本

# update-alternatives --list iptables
   /usr/sbin/iptables-legacy
   /usr/sbin/iptables-nft

并切换到旧版本

# update-alternatives --set iptables /usr/sbin/iptables-legacy 

并重新启动。但 UFW 仍然不起作用。

 # sudo iptables --list
modprobe: FATAL: Module ip_tables not found in directory /lib/modules/4.15.0-60-generic
iptables v1.8.5 (legacy): can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
# depmod
depmod: ERROR: could not open directory /lib/modules/4.15.0-60-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
 # ufw status verbose
ERROR: problem running iptables: modprobe: FATAL: Module ip_tables not found in directory /lib/modules/4.15.0-60-generic
iptables v1.8.5 (legacy): can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

如何修复这个 ubuntu(参见 Uname)并以正确的方式安装 UFW?

答案1

我终于理解了这个问题。这就是我们对云提供商的全部了解,他们的脚本将操作系统安装到一个磁盘(在我的情况下是 /dev/sdb Ubuntu 20.10),而不是从另一个磁盘启动系统(在我的情况下是 /dev/sda 和 Ubuntu 16.04)

相关内容