admin管理员组文章数量:1642346
Centos 7 开放3360端口命令:
查看端口的开放情况:sudo firewall-cmd --list-all
接下来通过以下命令开放http 3306端口:
- sudo firewall-cmd --add-service=http --permanent
- sudo firewall-cmd --add-port=3306/tcp --permanent
- 命令末尾的--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端口命令 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729335994a1196988.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论