Linux 中如何开启端口的 ?


作者:运维派

Linux 端口的开启

  • Linux 端口的开启

  • 一、firewall 方式 (centOS7.*)

  • 二、修改 iptables 方式 (centOS6.*)

一、firewall 方式 (centOS7.*)

  1. 查看防火墙状态

firewall-cmd --state
Linux 中如何开启端口的 ?

Linux 中如何开启端口的 ?
如果返回的是 “not running”,那么需要先开启防火墙;

  1. 开启防火墙

systemctl start firewalld.service


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

  1. 开启指定端口

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

显示 success 表示成功
–zone=public 表示作用域为公共的
–add-port=443/tcp 添加 tcp 协议的端口端口号为 443
–permanent 永久生效,如果没有此参数,则只能维持当前 服 务生命周期内,重新启动后失效;微信搜索公众号:架构师指南,回复:架构师 领取资料 。

  1. 重启防火墙

systemctl restart firewalld.service

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

  1. 重新加载防火墙

firewall-cmd --reload

显示 success 表示成功

  1. 其他命令

#查看已开启的端口
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

Linux 中如何开启端口的 ?

2.2 重启防火墙

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

Linux 中如何开启端口的 ?

三、注意事项

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

Linux 中如何开启端口的 ?


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


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

--完--

读到这里说明你喜欢本公众号的文章,欢迎 置顶(标星)本公众号 Linux技术迷,这样就可以第一时间获取推送了~

本公众号 Linux技术迷,后台回复:Linux,领取2T学习资料 !
1. Linux 中 find 命令的 35 个实际例子
2. 运维必备的《网络端口大全》,看这一份就够了
3. Linux 学习指南 (收藏篇)
4. 2万字系统总结,带你实现Linux命令自由
Linux 中如何开启端口的 ?
Linux 中如何开启端口的 ?

本篇文章来源于微信公众号:程序IT圈

原创文章,作者:software,如若转载,请注明出处:https://www.sldh123.com/7377.html

(0)
上一篇 2月 5, 2023 4:25 上午
下一篇 2月 5, 2023 4:26 上午

相关推荐

发表回复

您的电子邮箱地址不会被公开。