centos7 防火墙 开启端口 并测试
1、防火墙
CentOS升级到7之后,发现无法使用iptables控制Linuxs的端口,google之后发现Centos 7使用firewalld代替了原来的iptables。下面记录如何使用firewalld开放Linux端口:
查看防火墙状态
systemctl status firewalld
开启防火墙
systemctl start firewalld
关闭防火墙
systemctl stop firewalld
查看当前firewall状态
firewall-cmd --state
重启firewall
firewall-cmd --reload
禁止开机启动
systemctl disable firewalld.service
2、开启端口
查看已经开放的端口:
firewall-cmd --list-ports
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
开启断绝口后需要重启防火墙

3、测试端口
在开启的端口启动一个服务,如tomcat,我使用的是zookeeper。

在dos中输入
telnet 服务器ip 端口

回车后

表明端口开启成功
Centos 7 firewall 命令:
查看已经开放的端口:
firewall-cmd --list-ports
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload #重启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
CentOS 7 以下版本 iptables 命令
如要开放80,22,8080 端口,输入以下命令即可
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
然后保存:
/etc/rc.d/init.d/iptables save
查看打开的端口:
/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中的站点
1. 本机能ping通虚拟机2. 虚拟机也能ping通本机3.虚拟机能访问自己的web4.本机无法访问虚拟机的web
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
查看CentOS防火墙信息:/etc/init.d/iptables status关闭CentOS防火墙服务:/etc/init.d/iptables stop
centos7 防火墙 开启端口 并测试的更多相关文章
- centos7防火墙开放端口等命令
CentOS 7 开放防火墙端口 命令 最近公司新的server要求用CentOS7, 发现以前CentOS 6 系列中的 iptables 相关命令不能用了,查了下,发现Centos 7使用fire ...
- Centos7 防火墙开放端口,查看状态,查看开放端口
CentOS7 端口的开放关闭查看都是用防火墙来控制的,具体命令如下: 查看防火墙状态:(active (running) 即是开启状态) [root@WSS bin]# systemctl fire ...
- linux centos7 防火墙及端口开放相关命令
一.防火墙相关命令 1.查看防火墙状态 : systemctl status firewalld.service 注:active是绿的running表示防火墙开启 2.关闭防火墙 :systemct ...
- CentOS7下开启端口
开启端口: firewall-cmd --zone=public --add-port=80/tcp --permanent 含义: --zone #作用域 --add-port=80/tcp #添加 ...
- centos7 防火墙开启 (重点)
如果在自己服务器上想开启远端访问功能,需要开启防火墙 1.通过systemctl status firewalld查看firewalld状态,发现当前是dead状态,即防火墙未开启. 2.通过syst ...
- Linux Centos7配置防火墙开启端口
在使用centos7安装完mysql.tomcat.nginx后,都需要配置防火墙才能正常访问. 下面系统的学习一下防火墙的配置. centos7默认使用firewall,需要关闭,然后使用iptab ...
- Centos7防火墙开启3306端口
CentOS7的默认防火墙为firewall,且默认是不打开的. systemctl start firewalld # 启动friewall systemctl status firewalld # ...
- CentOS7防火墙开启与关闭以及开放6379,3306,80等端口
CentOS7用firewall防火墙替代了原来的iptables,所以我们应该使用firewall的一些命令.如下:1.关闭防火墙 systemctl stop firewalld.service ...
- centos7 防火墙与端口设置、linux端口范围
防火墙 启动防火墙: systemctl start firewalld 查看防火墙状态: systemctl status firewalld 关闭防火墙: systemctl stop firew ...
随机推荐
- SQL Server 查询性能优化——创建索引原则(一)
索引是什么?索引是提高查询性能的一个重要工具,索引就是把查询语句所需要的少量数据添加到索引分页中,这样访问数据时只要访问少数索引的分页就可以.但是索引对于提高查询性能也不是万能的,也不是建立越多的索引 ...
- 十年阿里java架构师的六大设计原则和项目经验
先看一幅图吧: 这幅图清晰地表达了六大设计原则,但仅限于它们叫什么名字而已,它们具体是什么意思呢?下面我将从原文.译文.理解.应用,这四个方面分别进行阐述. 1.单一职责原则(Single Res ...
- Maven依赖下载速度慢,不用怕,这么搞快了飞起
一.背景 众所周知,Maven对于依赖的管理让我们程序员感觉爽的不要不要的,但是由于这货是国外出的,所以在我们从中央仓库下载依赖的时候,速度如蜗牛一般,让人不能忍,并且这也是大多数程序员都会遇到的问题 ...
- 【Linux】【Tomcat】Tomcat的安装和配置等
安装环境 :Linux(Ubuntu 版) 安装软件 : apache-tomcat-9.0.0.M1.tar.gz(下载地址http://tomcat.apache.org/) 步骤一 Tomcat ...
- Android 自定义TabHost,TabWidget样式
界面比较简单,要想做得漂亮换几张图片就可以了. 第一步:先在布局(这里用了main.xml创建时自动生成的)里面放上TabHost ,只要将TabHost控件托至屏幕中就可: <?xml ver ...
- Linux实用命令整理
说明 点击标题可进入详细讲解的章节 0. 基本命令 linux 基本命令整理 1. 压缩 解压 tar -zcvf a.tar.gz a #把a压缩成a.tar.gz tar -zxvf a.tar. ...
- 39.纯 CSS 创作一个表达怀念童年心情的条纹彩虹心特效
原文地址:https://segmentfault.com/a/1190000015126240 HTML code: <div class="heart"> < ...
- MySQL把文件导入表中
1. Mysql 把本地文件导入表中 drop table if exists wufangzhai_caigou_group; create table wufangzhai_caigou_grou ...
- kettle实现简单的增量同步
下载 pdi-ce-7.0.0.0-25.zip 解压 安装jdk 1.7以上的版本 配置环境变量 下载并将mysql-connector-java-5.1.39.jar 拷贝到 \data-inte ...
- django之signal机制分析
django的signal在djangobb中的使用: from django.db.models.signals import post_save from django.dispatch impo ...