I’m actually still experiencing difficulties. It was working like you said and I’ve enabled ufw as a service to start on boot, but when I reboot it won’t start and the log file shows:
haste@Khadas:~$ sudo journalctl -b | grep ufw
Jul 02 12:47:06 Khadas systemd[1]: Starting ufw.service - Uncomplicated firewall...
Jul 02 12:47:07 Khadas ufw-init[479]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[479]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[479]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[485]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[485]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[485]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[489]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[489]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[489]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[492]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[492]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[492]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[493]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[493]: Error occurred at line: 12
Jul 02 12:47:07 Khadas ufw-init[493]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[494]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[494]: Error occurred at line: 12
Jul 02 12:47:07 Khadas ufw-init[494]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[506]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[506]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[506]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[510]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[510]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[510]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[513]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[513]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[513]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[515]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[515]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[515]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[534]: Problem running '/etc/ufw/before.rules'
Jul 02 12:47:07 Khadas ufw-init[534]: Problem running '/etc/ufw/after.rules'
Jul 02 12:47:07 Khadas ufw-init[534]: Problem running '/etc/ufw/user.rules'
Jul 02 12:47:07 Khadas systemd[1]: ufw.service: Main process exited, code=exited, status=1/FAILURE
Jul 02 12:47:07 Khadas systemd[1]: ufw.service: Failed with result 'exit-code'.
Jul 02 12:47:07 Khadas systemd[1]: Failed to start ufw.service - Uncomplicated firewall.
Jul 02 12:47:51 Khadas sudo[1533]: haste : TTY=pts/0 ; PWD=/home/haste ; USER=root ; COMMAND=/usr/sbin/ufw status
Jul 02 12:47:56 Khadas sudo[1544]: haste : TTY=pts/0 ; PWD=/home/haste ; USER=root ; COMMAND=/usr/bin/systemctl status ufw
Jul 02 12:48:18 Khadas sudo[1548]: haste : TTY=pts/0 ; PWD=/home/haste ; USER=root ; COMMAND=/usr/sbin/ufw status
When I try to manually enable ufw it won’t start:
haste@Khadas:~$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
haste@Khadas:~$ sudo systemctl status ufw
× ufw.service - Uncomplicated firewall
Loaded: loaded (/usr/lib/systemd/system/ufw.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Tue 2024-07-02 12:47:07 UTC; 5min ago
Docs: man:ufw(8)
Main PID: 456 (code=exited, status=1/FAILURE)
CPU: 125ms
Jul 02 12:47:07 Khadas ufw-init[513]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[515]: iptables-restore v1.8.10 (legacy): iptables-restore: unable to initialize table 'filter'
Jul 02 12:47:07 Khadas ufw-init[515]: Error occurred at line: 1
Jul 02 12:47:07 Khadas ufw-init[515]: Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Jul 02 12:47:07 Khadas ufw-init[534]: Problem running '/etc/ufw/before.rules'
Jul 02 12:47:07 Khadas ufw-init[534]: Problem running '/etc/ufw/after.rules'
Jul 02 12:47:07 Khadas ufw-init[534]: Problem running '/etc/ufw/user.rules'
Jul 02 12:47:07 Khadas systemd[1]: ufw.service: Main process exited, code=exited, status=1/FAILURE
Jul 02 12:47:07 Khadas systemd[1]: ufw.service: Failed with result 'exit-code'.
Jul 02 12:47:07 Khadas systemd[1]: Failed to start ufw.service - Uncomplicated firewall.
The modules are loaded as far as I can see:
haste@Khadas:~$ lsmod | grep ip_tables
lsmod | grep nf_tables
lsmod | grep nf_conntrack
lsmod | grep iptable_filter
lsmod | grep iptable_nat
lsmod | grep iptable_mangle
lsmod | grep iptable_raw
lsmod | grep xt_tcp
lsmod | grep xt_udp
lsmod | grep xt_LOG
lsmod | grep xt_limit
lsmod | grep xt_conntrack
lsmod | grep xt_addrtype
ip_tables 32768 12 iptable_filter,iptable_raw,iptable_nat,iptable_mangle
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
nf_tables 221184 0
nfnetlink 20480 1 nf_tables
nf_conntrack 147456 2 xt_conntrack,nf_nat
nf_defrag_ipv6 24576 1 nf_conntrack
nf_defrag_ipv4 16384 1 nf_conntrack
iptable_filter 16384 1
ip_tables 32768 12 iptable_filter,iptable_raw,iptable_nat,iptable_mangle
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
iptable_nat 16384 0
nf_nat 49152 1 iptable_nat
ip_tables 32768 12 iptable_filter,iptable_raw,iptable_nat,iptable_mangle
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
iptable_mangle 16384 0
ip_tables 32768 12 iptable_filter,iptable_raw,iptable_nat,iptable_mangle
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
iptable_raw 16384 0
ip_tables 32768 12 iptable_filter,iptable_raw,iptable_nat,iptable_mangle
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
xt_tcpudp 16384 14
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
xt_LOG 16384 4
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
xt_limit 20480 6
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
xt_conntrack 16384 8
nf_conntrack 147456 2 xt_conntrack,nf_nat
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle
xt_addrtype 16384 4
x_tables 49152 11 xt_conntrack,iptable_filter,xt_LOG,xt_tcpudp,xt_addrtype,ip6_tables,iptable_raw,ip_tables,iptable_nat,xt_limit,iptable_mangle