Linux centos修改防火墙为iptables
防火墙配置
CentOS 7默认使用的是firewall作为防火墙,这里改为iptables防火墙。
firewall操作:
# service firewalld status; #查看防火墙状态
(disabled 表明 已经禁止开启启动 enable 表示开机自启,inactive 表示防火墙关闭状态 activated(running)表示为开启状态)
# service firewalld start; 或者 #systemctl start firewalld.service;#开启防火墙
# service firewalld stop; 或者 #systemctl stop firewalld.service;#关闭防火墙
# service firewalld restart; 或者 #systemctl restart firewalld.service; #重启防火墙
# systemctl disable firewalld.service#禁止防火墙开启自启
# systemctl enable firewalld#设置防火墙开机启动
#yum remove firewalld#卸载firewall
禁用/停止自带的firewalld服务
systemctl stop firewalld #停止firewalld服务
systemctl mask firewalld #禁用firewalld服务
安装iptables防火墙及操作:
service iptables status #先检查是否安装了iptables
yum install -y iptables #安装iptables
yum update iptables #升级iptables
yum install iptables-services #安装iptables-services
设置现有规则
iptables -L -n #查看iptables现有规则
iptables -P INPUT ACCEPT #先允许所有,不然有可能会杯具
iptables -F #清空所有默认规则
iptables -X #清空所有自定义规则
iptables -Z #所有计数器归0
iptables -A INPUT -i lo -j ACCEPT #允许来自于lo接口的数据包(本地访问)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT #开放22端口
iptables -A INPUT -p tcp --dport 21 -j ACCEPT #开放21端口(FTP)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT #开放80端口(HTTP)
iptables -A INPUT -p tcp --dport 443 -j ACCEPT #开放443端口(HTTPS)
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT #允许ping
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT #允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
iptables -P INPUT DROP #其他入站一律丢弃
iptables -P OUTPUT ACCEPT #所有出站一律绿灯
iptables -P FORWARD DROP #所有转发一律丢弃
其他规则设定
iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT #如果要添加内网ip信任(接受其所有TCP请求)
iptables -P INPUT DROP #过滤所有非以上规则的请求
iptables -I INPUT -s ***.***.***.*** -j DROP #要封停一个IP,使用下面这条命令:
iptables -D INPUT -s ***.***.***.*** -j DROP #要解封一个IP,使用下面这条命令:
保存规则设定
service iptables save #保存上述规则
开启iptables服务
systemctl enable iptables.service #注册iptables服务 相当于以前的chkconfig iptables on
systemctl start iptables.service #开启服务
systemctl status iptables.service #查看状态
解决vsftpd在iptables开启后,无法使用被动模式的问题
1.首先在/etc/sysconfig/iptables-config中修改或者添加以下内容
2.重新设置iptables设置
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
以下为完整设置脚本
#!/bin/sh iptables -P INPUT ACCEPT iptables -F iptables -X iptables -Z iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables -A INPUT -p tcp --dport 21 -j ACCEPT iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp --dport 443 -j ACCEPT iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD DROP service iptables save systemctl restart iptables.service
Linux centos修改防火墙为iptables的更多相关文章
- Linux CentOS修改网卡IP/网关设置
1. 修改对应网卡IP的配置文件 修改以下内容 2. 修改对应网卡的网关的配置文件 vi /etc/sysconfig/network 修改以下内容 3. CentOS 修改DNS 修改以下内容 4. ...
- Linux Centos 开启防火墙 FirewallD is not running
转载自:http://www.z4zr.com/page/1006.html CentOS7用firewall命令“替代”了iptables.在这里我们需要区分“iptables服务”和“iptabl ...
- linux中的防火墙netfilter iptables
目录 一.Linux防火墙基础 1.1 ptables的表.链结构 1.2 数据包控制的匹配流程 二.编写防火墙规则 1.iptables的安装 2.1 基本语法.控制类型 一般在生产环境中设置网络型 ...
- Linux CentOS 7 防火墙/端口设置
CentOS升级到7之后用firewall代替了iptables来设置Linux端口, 下面是具体的设置方法: []:选填 <>:必填 [<zone>]:作用域(block.d ...
- Linux CentOS中防火墙的关闭及开启端口
注:CentOS7之前用来管理防火墙的工具是iptable,7之后使用的是Firewall 样例:在CentOS7上安装tomcat后,在linux本机上可以访问tomcat主页,http://ip: ...
- Linux CentOS 7 防火墙与端口设置操作
CentOS升级到7之后用firewall代替了iptables来设置Linux端口, 下面是具体的设置方法: []:选填 <>:必填 [<zone>]:作用域(block.d ...
- Linux CentOS 7 防火墙/端口设置【转发】
CentOS升级到7之后用firewall代替了iptables来设置Linux端口, 下面是具体的设置方法: []:选填 <>:必填 [<zone>]:作用域(block.d ...
- Linux系统修改防火墙配置
防火墙配置文件位置 /etc/sysconfig/iptables 需要开放端口,请在里面添加一条内容即可: 1 -A RH-Firewall-1-INPUT -m state --state NEW ...
- Linux CentOS 修改内核引导顺序
CentOS 7.0 系统更改内核启动顺序 可以 uname -a查下当前的 由于 CentOS 7 使用 grub2 作为引导程序,所以和 CentOS 6 有所不同,并不是修改 /etc/grub ...
随机推荐
- SpringBoot(七) Working with data: SQL
一.JdbcTemplate 二.Spring-data-jpa 实体类 继承JpaRepository<T,ID> 的接口,来访问数据库 30.3 JPA and Spring Data ...
- 分析Ethernet标准和Ieee802.3标准规定的MAC层帧结构
分析所用软件下载:Wireshark-win32-1.10.2.exe 阅读导览 1. 学习Wireshark的安装与使用 2. 熟悉Wireshark的操作界面与功能 3. 设计应用以获取以太网链路 ...
- 数组元素的移动(删除) C#实现
下面有四个问题: 把数组元素前后部分交换 MoveFirstPartOfArrayToTheEnd(int[] array, int index) 比如 {1,2,3,4,5,6,7} 3 => ...
- HwUI,CMS管理系统模板,漂亮,简单,兼容好
HwUI兼容目前所有浏览器,IE6+,Opera,Firefox,Chorme,Safari,由于IE6基本已废弃,所以也没有测试IE6的兼容,但做了部分IE6兼容调整.HwUI操作简单,路由导航不需 ...
- Maven项目下启动后Eclipse报错:org.springframework.web.context.ContextLoaderListener
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...
- 基于jQuery的软键盘
基于jQuery的软键盘 前些天写了一个基于基于jQuery的数字键盘,今天给大家带来一个基于jQuery的全字母键盘插件(支持全字母大小写切换,数字输入,退格清除,关闭功能,可调整大小和键盘位置 ...
- nginx的MainLine version、Stable version、Legacy versions
Nginx的版本说明Mainline version:在线版本,正处于开发状态Stable version :稳定版本(一般下载使用)Legacy version :遗留版本,遗留的老的版本 Linu ...
- HTML5和IOS、Android之间的交互
HTML5向IOS.Android传参: html给native传参需要注意三点: 1.判断终端设备,一般我们都是双系统开发,android和ios语言又不一样:我们需要用不同的方法给他们传递参数: ...
- json与list,map,String之间的互转
package tools; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import j ...
- Python 中单双引号
TODO, 在python中, 其实单双引号还是有分别的, 具体是什么?