linux怎么关闭指定端口

如何关闭 linux 中的指定端口

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

使用 UFW

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

使用 iptables

查看当前规则:sudo iptables -L

添加拒绝规则:

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

使用 firewalld

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

示例

以下命令关闭端口 80:

sudo ufw deny 80sudo iptables -I INPUT -p tcp --dport 80 -j DROPsudo firewall-cmd --add-port=80/tcp --permanent

注意:

根据您的系统和防火墙软件,实际命令可能略有不同。始终记得在更改防火墙规则后重新加载规则(例如,sudo ufw reloadsudo iptables-restore sudo firewall-cmd --reload)。如果使用其他防火墙软件,请查阅其文档以了解具体关闭端口的步骤。

以上就是linux怎么关闭指定端口的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/88121.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年11月17日 21:16:06
下一篇 2025年11月17日 21:37:29

相关推荐

发表回复

登录后才能评论
关注微信