Centos安装iptables防火墙
一、安装说明:
1、因为centos7.0及以上版本就默认安装了firewall防火墙,但有时候根据项目实际所需,服务器上还是需要安装iptables,以下就是具体的安装步骤;
2、因阿里云在服务器外面还有相应的防火墙,所以除了在iptables中开放相应端口,还需要在阿里云后台-安全组规则-也开放相关端口;
二、如何安装:
安装iptable iptable-service
先检查是否安装了iptables
service iptables status
安装iptables
yum install -y iptables
升级iptables
yum update iptables
安装iptables-services
yum install iptables-services
iptables-services 和 iptables 是不一样的
安装了 services才有/etc/sysconfig/iptables
禁用/停止自带的firewalld服务
停止firewalld服务
systemctl stop firewalld
禁用firewalld服务
systemctl mask firewalld
设置现有规则
查看iptables现有规则
iptables -L -n
先允许所有,不然有可能会产生”杯具“,即可能导致服务器的部分服务不可用,例如web、ftp等
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
其他规则设定
如果要添加内网ip信任(接受其所有TCP请求)
iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
过滤所有非以上规则的请求
iptables -P INPUT DROP
要封停一个IP,使用下面这条命令:
iptables -I INPUT -s ... -j DROP
要解封一个IP,使用下面这条命令:
iptables -D INPUT -s ... -j DROP
保存规则设定
保存上述规则
service iptables save
开启iptables服务
注册iptables服务
相当于以前的chkconfig iptables on
systemctl enable iptables.service
开启服务
systemctl start iptables.service
查看状态
systemctl status iptables.service
解决vsftpd在iptables开启后,无法使用被动模式的问题
1.首先在/etc/sysconfig/iptables-config中修改或者添加以下内容
添加以下内容,注意顺序不能调换
IPTABLES_MODULES=”ip_conntrack_ftp”
IPTABLES_MODULES=”ip_nat_ftp”
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
Centos安装iptables防火墙的更多相关文章
- CentOS系统配置 iptables防火墙
阿里云CentOS系统配置iptables防火墙 虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FO ...
- Centos7下安装iptables防火墙
说明:centos7默认使用的firewalld防火墙,由于习惯使用iptables做防火墙,所以在安装好centos7系统后,会将默认的firewall关闭,并另安装iptables进行防火墙规则设 ...
- CentOS启用iptables防火墙
centos 7默认的防火墙使用firewall,系统服务管理方式也变更了,可以通过systemctl命令控制. 可以参考这个链接 但是习惯用iptables,可以按下面的操作改下 1.关闭firew ...
- 利用CentOS系统IPtables防火墙添加网站IP白名单
参考博文: 利用CentOS系统IPtables防火墙添加360网站卫士节点IP白名单 centos6.5添加白名单如下: 在防火墙 配置文件中加入白名单 ip -A INPUT -s 183.13 ...
- centos 7 安装iptables防火墙
firewalle: 开启6379端口和16379端口 [root@localhost ~]# firewall-cmd --zone=public --add-port=6379/tcp --per ...
- CentOS之——CentOS7安装iptables防火墙
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761 CentOS7默认的防火墙不是iptables,而是firewall ...
- CentOS7安装iptables防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- entOS7安装iptables防火墙,试验未通过
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- Linux 安装 iptables防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
随机推荐
- 使用XMLConfiguration解析xml,PropertiesConfiguration解析properties等相应信息
org.apache.commons.configuration.XMLConfiguration; Apache Common-Configuration工具可以从Properties文件,XML文 ...
- Elasticsearch集成ik分词器
1.插件地址https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.0/elasticsearch-anal ...
- 卸载 Ubuntu gnome 自带的 Videos, Browser, Document Viewer等
卸载命令 # uninstall Browser sudo apt-get remove --purge webbrowser-app # uninstall Videos sudo apt-get ...
- Robot FrameWork基础学习(二)
在Robot Framework中,测试套件(Test Suite)主要是存放测试案例,而资源文件(Resource)就是用来存放用户关键字. 内部资源:Resource 外部资源: External ...
- 后缀数组dc3算法模版(待补)
模版: ; #define F(x) ((x)/3+((x)%3==1?0:tb)) #define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2) int wa[maxn ...
- HDU - 1535 Invitation Cards 前向星SPFA
Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...
- [51nod] 1091 线段的重叠 贪心
X轴上有N条线段,每条线段包括1个起点和终点.线段的重叠是这样来算的,[10 20]和[12 25]的重叠部分为[12 20]. 给出N条线段的起点和终点,从中选出2条线段,这两条线段的重叠部分是最长 ...
- opencv多版本安装
使用命令查看当前的opencv版本: pkg-config --modversion opencv 自带的是opencv-2.4.9 安装opencv3.1 安装opencv的依赖项 sudo apt ...
- webpack 打包和手动创建一个vue的项目
首先我们为啥要用webpack,为啥不用其他的打包的工具. 先听我捋捋, Webpack有人也称之为 模块打包机 ,由此也可以看出Webpack更侧重于模块打包,当然我们可以把开发中的所有资源(图片. ...
- Delphi调用C# 编写dll动态库
Delphi调用C# 编写dll动态库 编写C#dll的方法都一样,首先在vs2005中创建一个“类库”项目WZPayDll, using System.Runtime.InteropServices ...