当前位置: 代码网 > 服务器>服务器>Linux > Linux端口的开启方式

Linux端口的开启方式

2024年12月29日 Linux 我要评论
一、firewall方式(centos7.*)1. 查看防火墙状态firewall-cmd --state如果返回的是“not running”,那么需要先开启防火墙;2. 开

一、firewall方式(centos7.*)

1. 查看防火墙状态

firewall-cmd --state

如果返回的是“not running”,那么需要先开启防火墙;

2. 开启防火墙

systemctl start firewalld.service

再次查看防火墙状态,发现已开启!

3. 开启指定端口

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

显示success表示成功

  • –zone=public表示作用域为公共的
  • –add-port=443/tcp添加tcp协议的端口端口号为443
  • –permanent永久生效,如果没有此参数,则只能维持当前 服 务生命周期内,重新启动后失效;

4. 重启防火墙

systemctl restart firewalld.service

系统没有任何提示表示成功!

5. 重新加载防火墙

firewall-cmd --reload

显示success表示成功

6. 其他命令

#查看已开启的端口
firewall-cmd --list-ports
#关闭指定端口
firewall-cmd --zone=public --remove-port=8080/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload
#查看端口被哪一个进程占用
netstat -lnpt |grep 5672
# centos7默认没有 netstat 命令,需要安装 net-tools 工具:
# 安装 net-tools
yum install -y net-tools
# 临时关闭防火墙
systemctl stop firewalld.service
# 或者
systemctl stop firewalld
# 永久关闭防火墙(必须先临时关闭防火墙,再执行该命令,进行永久关闭)
systemctl disable firewalld.service
# 或者
systemctl disable firewalld

二、修改iptables方式(centos6.*)

centos6.* 的linux版本是自带iptables的,所以可以直接使用该方式,centos7 不自带iptables的,所以要使用该方式,需要手动安装iptables后,再使用该方式!

2.1 修改iptables文件

#修改iptables
[root@localhost sbin]# vi /etc/sysconfig/iptables

2.2 重启防火墙

[root@localhost sbin]# /etc/init.d/iptables restart

三、注意事项

当在linux中成功开启了某个端口,但是远程telnet还是无法ping通,是正常的!

因为3306端口没有被linux进程监听,换句话说,就是该端口上没有运行任何程序!!! 

如果这时,我将mysql在linux中启动,并配置完成,那么远程telnet该端口是可以成功的!!!

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

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

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com