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 ...
随机推荐
- WPF去除窗体边框及白色边框
<Window x:Class="WpfAppFirst.Evaluation" xmlns="http://schemas.microsoft.com/winfx ...
- vuejs实现瀑布流布局(二)
瀑布流布局已然完成,那么剩下的就是另一个比较大的工程了——无限加载. 之前说了,这个活动项目是基于SUI-Mobile搭建的,所以可以直接使用sui内建组件“无限加载”来实现这个功能. 没有真实的数据 ...
- 阅读别人的程序(Java篇)
1.递归求数组最大值 2.转账(事务) 1.递归应用 public class DiGuiDemo3 { public static void main(String[] args) { int[] ...
- Java swing 代码例子
package com; import java.awt.Button; import java.awt.Container; import java.awt.event.ActionEvent; i ...
- django+uwsgi+nginx+sqlite3部署+screen
note:可通过该命令查找文件未知 sudo find / -name filename 一:项目(github) ssh root@server ip # 连接你的服务器 git ...
- Loadrunner:win10下Vuser 运行脚本通过,Controller执行用户并发报错
现象:win7安装LR可以正常使用,将win7升级到win10之后,运行场景之后报错:Error (-81024): LR_VUG: The 'QTWeb' type is not supported ...
- docker pull centos慢问题的解决方案
1.现象 如果直接docker pull centos 两个小时才down下来8M,很慢 2.解决 [root@localhost network-scripts]# cd /etc/docker [ ...
- react-native Animated, 旋转动画
Animated 仅封装了四个可以动画化的组件: View.Text.Image.ScrollView 可以使用 Animated.createAnimatedComponent()来封装你自己的组件 ...
- [转]使用Ubuntu Live CD修复Grub引导教程
这个教程的方法我用过了,能够解决了我的问题. 这篇文章主要介绍了使用Ubuntu Live CD修复Grub引导教程,本文以 Ubuntu Live CD 修复 Grub 引导为例,需要的朋友可以参考 ...
- VC 字符串转化和分割
原文:点击这里. 备忘:为了适用于Unicode环境,要养成使用_T()宏的习惯 1.格式化字符串 CString s;s.Format(_T("The num is %d."), ...