您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
Linux 防火墙设置简明指南
一 选择工具与适用场景
二 常用发行版快速上手
CentOS/RHEL/Alibaba Cloud Linux
sudo firewall-cmd --state(返回 running/not running)sudo systemctl start|enable firewalldsudo systemctl stop|disable firewalldsudo firewall-cmd --permanent --add-port=80/tcp && sudo firewall-cmd --reloadsudo firewall-cmd --permanent --add-service=http && sudo firewall-cmd --reloadsudo firewall-cmd --list-allsudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port port="22" protocol="tcp" accept' && sudo firewall-cmd --reloadUbuntu/Debian
sudo ufw status(返回 Status: active/inactive)sudo ufw enable|disablesudo ufw allow 80/tcpsudo ufw allow 3000:3100/tcpsudo ufw allow from 192.168.1.100 to any port 22sudo ufw status verbose使用 iptables 的通用做法(适用于所有发行版)
sudo iptables -L -n -vsudo iptables -F(操作前请先备份)sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPTsudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTsudo apt-get install iptables-persistent -y && sudo netfilter-persistent savesudo service iptables save(或 sudo iptables-save > /etc/iptables/rules.v4 并配置开机恢复)三 生产环境最佳实践
firewall-cmd --reload 使配置生效;重要变更前先备份,必要时用 firewall-cmd --runtime-to-permanent 固化运行时配置。sudo firewall-cmd --set-log-denied=all --permanent && sudo firewall-cmd --reload,并用 journalctl -u firewalld 查看。四 常见问题与排错
firewall-cmd --reload;用 firewall-cmd --list-all 核对生效规则与区域绑定。firewall-cmd: command not found,需先安装 firewalld 再启动服务。免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。