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 ...
随机推荐
- Hibernate 的HQL和sql有什么区别
转自:https://blog.csdn.net/haozhugogo/article/details/54575802sql 面向数据库表查询 hql 面向对象查询 hql : from 后面跟的 ...
- WPF TabControl SelectionChanged 重复执行的问题
很邪门的问题,我曾经都感觉是微软的bug了. 问题是这样的:在我的tabcontrol下的tabitem中有一个combobox控件,由于一些原因,需要执行tabcontrol的SelectionCh ...
- IIS 中的虚拟目录 和软连接
在WIndows 中 可以这样设置 mklink /D C:\bb C:\cc 这样 bb 就指向 CC了 bb 在IIS中的目录其实就是虚拟目录 .这样大的文件就不用存放在IIS中了,可以放在其他 ...
- 使用CTE生成辅助表(数字或时间)等
数字辅助表: , ;WITH Digital_Rangs(Digital) AS ( SELECT @start_digital UNION ALL FROM [Digital_Rangs] WHER ...
- Solr 6.7学习笔记(08)-- Facet
在搜索中,我们搜索时,通常会自动返回一些相关的搜索.比如,你搜索了一本书,会自动返回作者信息加上他的其它书籍的数量.这种功能在Solr中称之为Facet.不太好翻译.下面对于参数的说明,我以搜索“手机 ...
- 阿里云(centos)下svn 服务器搭建
安装说明 系统环境:阿里云centos安装方式:yum install subversion 检查已安装版本 #检查是否安装了低版本的SVN[root@localhost /]# rpm -qa su ...
- 使用tcpdump抓取EOS帐户创建与交易数据
基本环境配置 EOS 版本:1.0.1(2018-06-04更新) 节点nodeos http监听端口:127.0.0.1:8888 本地钱包keosd http监听端口:127.0.0.1:89 ...
- Codeforces 126B(kmp)
要点 头尾的最长相同只要一个kmp即可得,于是处理中间部分 扫一遍记录一下前缀的每个位置是否存在一个中间串跟它相同,见代码 如果当前没有,接着用Next数组去一找即可 #include <cst ...
- Linux中/etc/passwd 和 /etc/shadows 详解
linux操作系统上的用户如果需要登录主机,当其输入用户名和密码之后: 首先在/etc/passwd文件中查找是否有你的账号,如果没有无法登录,如果有的话将该用户的UID和GID读出来,此外将此用户的 ...
- NET Everywhere
NET Everywhere 8月份已经发布了.NET Core 2.0, 大会Keynote 一开始花了大量的篇幅回顾.NET Core 2.0的发布,社区的参与度已经非常高.大会的主题是.NET ...