解决ufw和netfilter同时存在ufw无法激活的问题
开机后,发现ufw一直处于inactive,查看 ufw状态, 本机也安装了docker,经过网上搜索和本地确认是netfilter-persistent
这服务导致的。
$ sudo service --status-all |grep netfilter
[ + ] netfilter-persistent
$ sudo ufw status
Status: inactive
确认ufw eanble 配置开启
# /etc/ufw/ufw.conf
#
# Set to yes to start on boot. If setting this remotely, be sure to add a rule
# to allow your remote connection before starting ufw. Eg: 'ufw allow 22/tcp'
ENABLED=yes
# Please use the 'ufw' command to set the loglevel. Eg: 'ufw logging medium'.
# See 'man ufw' for details.
LOGLEVEL=low
编辑ufw.service配置文件
在/lib/systemd/system/ufw.service
文件中增加 After=netfilter-persistent.service
字段:
[Unit]
Description=Uncomplicated firewall
Documentation=man:ufw(8)
DefaultDependencies=no
Before=network.target
After=netfilter-persistent.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/lib/ufw/ufw-init start quiet
ExecStop=/lib/ufw/ufw-init stop
[Install]
WantedBy=multi-user.target
重启
$ sudo reboot