当输入firewall-cmd --list-ports 查看端口信息时报错

Ubuntu报Command 'firewall-cmd' not found, but can be installed with:  apt install firewalld错误解决方案-LMLPHP

报错的原因可能是没有安装firewall,安装命令为: yum install firewalld

  • 安装完毕后下面介绍一下firewalld的常用用法:
    • 启动: systemctl start firewalld
    • 停止运行: systemctl stop firewalld
    • 查看状态: systemctl status firewalld
    • 禁止开机启动: systemctl disable firewalld
    • 查看端口信息:firewall-cmd --list-ports
    • 开端口命令:firewall-cmd --zone=public --add-port=80/tcp --permanent
    • 重启防火墙:systemctl restart firewalld.service

结果执行yum install firewalld 时又报了一个新的错误

Ubuntu报Command 'firewall-cmd' not found, but can be installed with:  apt install firewalld错误解决方案-LMLPHP

这时上网搜发现yum则属于Redhat、Centos包管理工具,所以Ubuntu应该使用sudo apt install firewalld才可以

Ubuntu报Command 'firewall-cmd' not found, but can be installed with:  apt install firewalld错误解决方案-LMLPHP

出现下图就算下载完毕了

Ubuntu报Command 'firewall-cmd' not found, but can be installed with:  apt install firewalld错误解决方案-LMLPHP

此时可以通过 systemctl status firewalld命令来查看防火墙状态

Ubuntu报Command 'firewall-cmd' not found, but can be installed with:  apt install firewalld错误解决方案-LMLPHP

比如,大家想要开启8080端口,只需要执行开端口命令即可,

firewall-cmd --zone=public --add-port=8080/tcp --permanent

Ubuntu报Command 'firewall-cmd' not found, but can be installed with:  apt install firewalld错误解决方案-LMLPHP

不过此时我们会发现,开启端口之后再查看端口时看不到的,我们需要重启防火前之后就可以查到了

Ubuntu报Command 'firewall-cmd' not found, but can be installed with:  apt install firewalld错误解决方案-LMLPHP

这样我们的防火墙配置就大功告成了!

07-25 16:51