Centos 7 开放3360端口命令,Centos 6 开放3360端口命令

编程入门 行业动态 更新时间:2024-10-10 06:19:21

Centos 7 开放3360端口命令:

查看端口的开放情况:sudo firewall-cmd --list-all

接下来通过以下命令开放http 3306端口:

  1. sudo firewall-cmd --add-service=http --permanent
  2. sudo firewall-cmd --add-port=3306/tcp --permanent
  3. 命令末尾的--permanent表示用久有效,不加这句的话重启后刚才开放的端口就又失效了。

然后重启防火墙:

sudo firewall-cmd --reload

再次查看端口的开放情况:sudo firewall-cmd --list-all

就会发现 services: 里出现了 http 服务,ports:里也出现了 3306 端口:

查看已经开放的端口:

firewall-cmd --list-ports

开启端口

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

命令含义:

–zone #作用域

–add-port=3306/tcp #添加端口,格式为:端口/通讯协议

–permanent #永久生效,没有此参数重启后失效

重启防火墙

firewall-cmd --reload #重启firewall systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动

firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

同理Centos 7 开放80、6379、11211端口命令只需更改成对应的端口即可

 

CentOS 6 版本 开放3306端口命令(iptables)

如要开放80,22,8080 端口,输入以下命令即可

vi /etc/sysconfig/iptables 加入:
 

-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3306 -j DROP

然后保存:

/etc/rc.d/init.d/iptables save 或者 service iptables save 或 service iptables restart

查看打开的端口:

/etc/init.d/iptables status

关闭防火墙 

1) 永久性生效,重启后不会复原

开启: chkconfig iptables on

关闭: chkconfig iptables off

2) 即时生效,重启后复原

开启: service iptables start

关闭: service iptables stop

查看防火墙状态: service iptables status

 

下面说下CentOS7和6的默认防火墙的区别

CentOS 7默认使用的是firewall作为防火墙,使用iptables必须重新设置一下

1、直接关闭防火墙

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

2、设置 iptables service

yum -y install iptables-services

如果要修改防火墙配置,如增加防火墙端口3306

vi /etc/sysconfig/iptables 

增加规则

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

保存退出后

systemctl restart iptables.service #重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

最后重启系统使设置生效即可。

systemctl start iptables.service #打开防火墙

systemctl stop iptables.service #关闭防火墙

 

CentOS防火墙的关闭,关闭其服务即可: 

查看CentOS防火墙信息:/etc/init.d/iptables status 

关闭CentOS防火墙服务:/etc/init.d/iptables stop 

更多推荐

Centos 7 开放3360端口命令,Centos 6 开放3360端口命令

本文发布于:2023-06-14 03:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1435182.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   命令   Centos

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!