centos配置iptables作为防火墙来替代默认的firewalld(代码片段)

666小奇 666小奇     2023-02-27     187

关键词:

文章目录

1.更新软件包

sudo yum update

出现如下信息代表已经更新到最新版,确保软件包更新到最新

已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No packages marked for update

2.安装iptables

运行 service iptables status 命令,确保系统未安装过iptables出现如下信息代表未安装过,可以进行下一步安装

yum install -y iptables

升级iptables

yum update iptables 

安装iptables-services

yum install iptables-services

禁用/停止自带的firewalld服务停止firewalld服务

systemctl stop firewalld

3.禁用firewalld服务

systemctl mask firewalld

4.编辑/etc/sysconfig/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

通过iptables -L可以查看端口放行信息

[root@QiCentos ~]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ftp
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
ACCEPT     icmp --  anywhere           anywhere             icmp echo-request
ACCEPT     all  --  anywhere          anywhere   state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

最后最后,保存上述规则(重要),默认保存在 /etc/sysconfig/iptables

service iptables save
[root@QiCentos ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  确定  ]

提醒一下,保存后需要确认保存成功在重启,否则会导致SSH无法连接!

参考文档:
CentOS7安装iptables防火墙

centos防火墙的配置方法详解iptables

CentOS6/7系统是基于linux中的,它的防火墙其实就是iptables了。下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助。iptables是与Linux内核集成的IP信息包过滤系统,其自带防火墙功能,我们在配置完服务... 查看详情

centos6下防火墙(iptables)的配置方法详解

CentOS6系统是基于linux中的,它的防火墙其实就是iptables了。下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助。iptables是与Linux内核集成的IP信息包过滤系统,其自带防火墙功能,我们在配置完服务... 查看详情

centos7关闭firewall安装iptables并配置

一、配置防火墙,开启80端口、3306端口CentOS7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service #停止firewallsystemctldisablefirewalld.service #禁止firewall开机启动 2、安装iptables... 查看详情

centos的防火墙(firewalld,iptables)和开启启动(代码片段)

Centos系统防火墙介绍  Centos7以前的系统默认使用iptables服务来管理防火墙,Centos7系统及以后使用firewalld服务替代了iptables服务,但是依然可以使用iptables来管理内核的netfilter。其实iptables服务和firewalld服务都不是真正的防火墙... 查看详情

centos7关闭firewall安装iptables并配置

 一、配置防火墙,开启80端口、3306端口CentOS7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service #停止firewallsystemctldisablefirewalld.service #禁止firewall开机启动 2、安装ipta 查看详情

centos7.0配置防火墙

之前用的iptables来管理的防火墙,后来发现centOS7.0中已经用firewalld取代iptables了,于是与时俱进,停用了iptables。systemctlstopiptables.service然后来启动firewalld吧systemctlstartfirewalld.service给我报了这个错Failedtostartfirewalld.service:Unitfirewa 查看详情

centos7关闭firewall安装iptables并配置(转)

http://www.cnblogs.com/valu/p/5649689.html 一、配置防火墙,开启80端口、3306端口CentOS7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service #停止firewallsystemctldisablefirewalld. 查看详情

centos下配置iptables防火墙linuxnat(iptables)配置

CentOS下配置防火墙配置nat转发服务CentOS下配置iptables防火墙linuxNAT(iptables)配置CentOS下配置iptables 1,vim/etc/sysconfig/network 这里可以更改主机名称。NETWORKING=yesNETWORKING_IPV6=noHOSTNAME=BGI-TJ.localdomain GATEWAY 查看详情

转载centos7关闭firewall防火墙指令以及更换安装iptables并配置

转载连接 http://ashui.net/archives/2015/943.html 一、配置防火墙,开启80端口、3306端口CentOS7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service#停止firewallsystemctldisablefirewalld 查看详情

centos7安装配置iptables防火墙

...下如果不想用centos7自带的FIREwall而用7之前版本的iptables当防火墙,这样自动加端口比较方便,可以如下方式配置:一、关闭Firewall防火墙执行以下操作:systemctlstopfirewalld.servicesystemctldisablefirewalld.service二、安装iptables防火墙yuminstall... 查看详情

centos系统配置iptables防火墙

阿里云CentOS系统配置iptables防火墙 虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT。OUTPUT和FORWORD都是ACCEPT的规则一、检查iptables服务状态首... 查看详情

防火墙(代码片段)

防火墙:保证数据的安全性是继数据可用性之后的最为重要的一项工作防火墙作为公网和内网之间的保护屏障防火墙种类:硬件防火墙:网关服务器软件防火墙:装在操作系统中的软件防火墙管理工具主要功能:依据策略对穿越... 查看详情

centos7安装配置iptables防火墙

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761CentOS7默认的防火墙不是iptables,而是firewalle.安装iptable iptable-service [plain] viewplain copy  #先检查是否安装了iptables&n 查看详情

centos7为啥要关闭firewall防火墙

CentOS7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下1、直接关闭防火墙systemctlstopfirewalld.service#停止firewallsystemctldisablefirewalld.service#禁止firewall开机启动2、设置iptablesserviceyum-yinstalliptables-services如果要修改防火墙... 查看详情

阿里云centos配置iptables防火墙

虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT。OUTPUT和FORWORD都是ACCEPT的规则一、检查iptables服务状态首先检查iptables服务的状态[[email protect... 查看详情

centos7版本firewalld防火墙的基本命令配置管理

centos7/redhat7已经默认使用firewalld作为防火墙,其使用的方式已经变化,基于iptables的防火墙默认不启用,但是仍可以继续使用注意:centos7/redhat7中有几种防火墙共存:firewalld、iptables、ebtablesd、默认使用的是firewalld作为防火墙,... 查看详情

centos切换为iptables防火墙并进行相关配置(代码片段)

CentOS切换为iptables防火墙切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务。1、关闭firewall:servicefirewalldstopsystemctldisablefirewalld.service#禁止firewall开机启动2、安装iptables防火墙yuminstalliptables-services#安装3、编辑iptab 查看详情

centos7.3下的一个iptables配置

centos7.3默认使用的防火墙应该是firewall,而不是iptables。而我们xxmj服务器使用的是iptables防火墙。所以,在配置防火墙之前,我们需要先关闭firewall,安装iptables。查看firewall的安装和启动状态[[email protected]~]#yumlistinstalledfirewall... 查看详情