UFW Troubleshooting – Fixing UFW Enable Crashing OS

command-line-interfacefail2banUbuntuufwvps

Where the problems started:

First i tried to install fail2ban from the ISPmanager UI, the fail2ban was installed but i got a error related to the package coremanager-pkg-fail2ban, and the fail2ban was not working so i tried to uninstalled it using the ISPmanager UI and using the command apt-get remove coremanager-pkg-fail2ban but it said that there's no package with this name, and this error still remains:
error

I did apt-get remove fail2ban and apt-get purge auto-remove fail2ban after this i reinstalled fail2ban using the command apt-get install fail2ban and i was getting this error: failed to validate path /var/run/fail2ban too many levels of symbolic links. I searched a bit and i found this answear https://serverfault.com/a/949286/521284, what did solved my problem with the fail2ban, and now fail2ban is running on my server:

root# systemctl status fail2ban 
fail2ban.service - Fail2Ban Service
    Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
    Active: active (running) since Mon 2019-04-29 15:44:15 EDT; 18min ago
    Docs: man:fail2ban(1)
    Process: 293 ExecStart=/usr/bin/fail2ban-client -x start (code=exited, status=0/SUCCESS)
    Main PID: 411 (fail2ban-server)
    CGroup: /system.slice/fail2ban.service
           └─411 /usr/bin/python3 /usr/bin/fail2ban-server -s /var/run/fail2ban/fail2ban.sock -p /var/run/fail2ban/fail2ban.pid -x -b

Apr 29 15:44:13 testdomain systemd[1]: Starting Fail2Ban Service...
Apr 29 15:44:14 testdomain fail2ban-client[293]: 2019-04-29 15:44:14,540 fail2ban.server [374]: INFO Starting Fail2ban v0.9.3
Apr 29 15:44:14 testdomain fail2ban-client[293]: 2019-04-29 15:44:14,541 fail2ban.server [374]: INFO Starting in daemon mode
Apr 29 15:44:15 testdomain systemd[1]: Started Fail2Ban Service.

But when i do ufw enable i get this error and my OS crashes and i need to restart the OS:

root# ufw enable
ERROR: problem running ufw-init
modprobe: ERROR: ../libkmod/libkmod.c:514 lookup_builtin_file() could not open builtin file '/lib/modules/2.6.32-042stab127.2/modules.builtin.bin'
modprobe: FATAL: Module nf_conntrack_ftp not found in directory /lib/modules/2.6.32-042stab127.2
modprobe: ERROR: ../libkmod/libkmod.c:514 lookup_builtin_file() could not open builtin file '/lib/modules/2.6.32-042stab127.2/modules.builtin.bin'
modprobe: FATAL: Module nf_nat_ftp not found in directory /lib/modules/2.6.32-042stab127.2
modprobe: ERROR: ../libkmod/libkmod.c:514 lookup_builtin_file() could not open builtin file '/lib/modules/2.6.32-042stab127.2/modules.builtin.bin'
modprobe: FATAL: Module nf_conntrack_netbios_ns not found in directory /lib/modules/2.6.32-042stab127.2
iptables-restore: line 4 failed
iptables-restore: line 77 failed
iptables-restore: line 30 failed
ip6tables-restore: line 4 failed
ip6tables-restore: line 138 failed
ip6tables-restore: line 30 failed
sysctl: permission denied on key 'net.ipv4.tcp_sack'

Problem running '/etc/ufw/before.rules'
Problem running '/etc/ufw/user.rules'
Problem running '/etc/ufw/before6.rules'
Problem running '/etc/ufw/user6.rules'

I'm tring to solve this problem with the ufw, could someone help? My ubuntu version is 16.04. And i'm using Apache2

Best Answer

Your "virtual machine" is not a true virtual machine, but an OpenVZ "container" (and not a modern container, but an ancient pre-LXC container). OpenVZ does not permit containers to load kernel modules, which you have to do in order to use the firewall features you are trying to use. Further, the 2.6.32 based kernel which they supply is too old to use many modern Linux features anyway. It was released in 2009!

To solve the problem, get a new VPS from another provider, which does not use OpenVZ or its commercial variant Virtuozzo.