温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用命令行界面配置服务器防火墙

发布时间:2025-08-20 19:10:28 来源:亿速云 阅读:89 作者:小樊 栏目:系统运维

不同操作系统使用命令行配置服务器防火墙的方法有所差异,以下是常见操作系统的配置方法:

Linux系统

  • 使用firewalld(CentOS 7及以上等系统)
    • 查看状态systemctl status firewalldfirewall-cmd --state
    • 开启/关闭systemctl start firewalldsystemctl stop firewalld
    • 添加端口规则firewall-cmd --permanent --add-port=端口/tcp(如firewall-cmd --permanent --add-port=80/tcp)。
    • 限制IP访问端口firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="IP地址" port protocol="tcp" port="端口" accept'
    • 重新加载规则firewall-cmd --reload
  • 使用iptables(较老系统或特定场景)
    • 查看规则iptables -L -n
    • 添加规则:如允许SSH,iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    • 保存规则service iptables save(CentOS 6等)或iptables-save > /etc/iptables/rules.v4(Ubuntu/Debian)。

Windows系统

  • 使用PowerShell
    • 查看规则Get-NetFirewallRule
    • 添加规则:如允许HTTP入站,New-NetFirewallRule -DisplayName "Allow_HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
    • 删除规则Remove-NetFirewallRule -DisplayName "规则名称"
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI