CentOS7配置iptables防火墙
CentOS 7中默认是firewalld防火墙,如果使用iptables需要先关闭firewalld防火墙(1.关闭防火墙,2.取消开机启动)。
#关闭firewalld
systemctl stop firewalld
#取消开机启动
systemctl disable firewalld
#查看状态
firewall-cmd --state
安装启用iptables
#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#安装iptables-services
yum -y install iptables-services
#注册iptables服务,相当于以前的chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service
设置iptables规则
查看iptables现有规则:iptables -L -n
添加开放80端口:iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT(好像这种方式重启以后就失效了)
编辑配置文件方式添加端口:
文件位置:/etc/sysconfig/iptables
执行vi /etc/sysconfig/iptables
添加一条规则开放80端口:-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
重启生效:service restart iptables
关闭iptables
systemctl stop iptables
其他规则:
#查看iptables现有规则
iptables -L -n
#先允许所有,不然有可能会杯具
iptables -P INPUT ACCEPT
#清空所有默认规则
iptables -F
#清空所有自定义规则
iptables -X
#所有计数器归0
iptables -Z
#允许来自于lo接口的数据包(本地访问)
iptables -A INPUT -i lo -j ACCEPT
#开放22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#开放21端口(FTP)
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#开放80端口(HTTP)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#开放443端口(HTTPS)
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
#允许ping
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
#允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#其他入站一律丢弃
iptables -P INPUT DROP
#所有出站一律绿灯
iptables -P OUTPUT ACCEPT
#所有转发一律丢弃
iptables -P FORWARD DROP
CentOS7配置iptables防火墙的更多相关文章
- CentOs7 使用iptables防火墙开启关闭端口
CentOs7 使用iptables防火墙开启关闭端口 # 0x01介绍 iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分iptables文件设置路径:命令:v ...
- CentOS下配置iptables防火墙 linux NAT(iptables)配置
CentOS下配置防火墙 配置nat转发服务CentOS下配置iptables防火墙 linux NAT(iptables)配置 CentOS下配置iptables 1,vim /etc/syscon ...
- CentOS7安装配置iptables防火墙
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761 CentOS7默认的防火墙不是iptables,而是firewall ...
- CentOS7使用iptables防火墙开放端口
背景:在CentOS上面安装了mysql.svn.tomcat等软件,发现访问不了,用telnet命令查看端口,发现都不通: telnet IP 端口 CentOS7 默认使用firewalld防火墙 ...
- CentOS7安装iptables防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- Ubuntu 14.04 配置iptables防火墙
Ubuntu默认安装是没有开启任何防火墙的,为了服务器的安全,建议大家安装启用防火墙设置,这里推荐使用iptables防火墙.如果mysql启本地使用,可以不用打开3306端口. # whereis ...
- CentOS之——CentOS7安装iptables防火墙
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761 CentOS7默认的防火墙不是iptables,而是firewall ...
- 2-10~2-11 配置iptables防火墙增强服务 selinux简单讲解
学习一个服务的过程: 1.此服务器的概述:名字,功能,特点,端口号 2.安装 3.配置文件的位置 4.服务启动关闭脚本,查看端口 5.此服务的使用方法 6.修改配置文件,实战举例 7.排错(从下到上, ...
- 使用Ansible安装部署nginx+php+mysql之配置iptables防火墙(0)
前提: 1.已配置好hosts文件且免密码登录 2.需要的yaml文件已上传到主控端 一.使用Ansible配置iptables 1.iptables.yaml文件 --- - hosts: clon ...
随机推荐
- nodejs 使用 js 模块
nodejs 使用 js 模块 Intro 最近需要用 nodejs 做一个爬虫,Google 有一个 Puppeteer 的项目,可以用它来做爬虫,有关 Puppeteer 的介绍网上也有很多,在这 ...
- [20190402]对比_mutex_wait_scheme不同模式cpu消耗.txt
[20190402]对比_mutex_wait_scheme不同模式cpu消耗.txt --//前几天做了sql语句在mutexes上的探究.今天对比不同_mutex_wait_scheme模式cpu ...
- 从0开始的Python学习008变量
局部变量 在我们定义函数的过程中,函数内外具有相同名称的变量是没有任何关系的.变量的名称对于函数来说是局部的,而它所在的代码块就是它的作用域. 使用局部变量 #局部变量 def func(x): pr ...
- javascript弹出模态窗体
function openwindow(url,name,iWidth,iHeight){ //获得窗口的垂直位置 var iTop = (window.screen.availHeight-30-i ...
- nysql报错1136
报错信息:> 1136 - Column count doesn't match value count at row 1 代码:insert into class(caption) value ...
- 并发框架Disruptor场景应用
今天用一个停车场问题来加深对Disruptor的理解.一个有关汽车进入停车场的问题.当汽车进入停车场时,系统首先会记录汽车信息.同时也会发送消息到其他系统处理相关业务,最后发送短信通知车主收费开始.看 ...
- 一 Struts2 开发流程
SSH与SSM简介SSM:Spring+SpringMVC+MybatisSSH:Struts2+Hibernate+SpringStruts2:是侧重于控制层的框架Hibernate:是一个ORM( ...
- Mac下MySql初始密码设置及mysql数据库操作
1. 首先 点击系统偏好设置 -> 点击MySQL, 在弹出的页面中,关闭服务.2. 进入终端命令输出: cd /usr/local/mysql/bin/ 命令,回车.3. 回车后,输入命令:s ...
- 使用github 的相关博客
基于hexo+github搭建一个独立博客 如何用Github的gh-pages分支展示自己的项目 使用git clone error: RPC failed Git的使用-- ...
- go笔记-pprof使用
go tool pprof http://localhost:6060/debug/pprof/profile go tool pprof http://localhost:6060/debug/pp ...