linux怎么关闭指定端口

如何关闭 linux 中的指定端口

在 Linux 系统中,我们可以通过防火墙规则来关闭指定端口。常用的防火墙有 UFW、iptables 和 firewalld。

使用 UFW

  1. 安装 UFW:sudo apt install ufw
  2. 拒绝端口:sudo ufw deny PORT(替换 PORT 为要关闭的端口号)

使用 iptables

  1. 查看当前规则:sudo iptables -L
  2. 添加拒绝规则:

    • sudo iptables -I INPUT -p tcp --dport PORT -j DROP(TCP 端口)
    • sudo iptables -I INPUT -p udp --dport PORT -j DROP(UDP 端口)

使用 firewalld

  1. 查看当前规则:sudo firewall-cmd --list-all
  2. 添加拒绝规则:sudo firewall-cmd --add-port=PORT/protocol --permanent(替换 PORT 和 protocol 为要关闭的端口号和协议)

示例

以下命令关闭端口 80:

sudo ufw deny 80
sudo iptables -I INPUT -p tcp --dport 80 -j DROP
sudo firewall-cmd --add-port=80/tcp --permanent
1、本站目前拥有近 1000+ 精品收费资源,现在加入VIP会员即可全部下载。
2、本资源部分来源其他付费资源平台或互联网收集,如有侵权请联系及时处理。
SEA模板网 » linux怎么关闭指定端口

发表评论

加入本站VIP会员订阅计划,海量资源免费查看

目前为止共有 3654 位优秀的VIP会员加入! 立刻加入VIP会员