centos7中防火墙的使用

#*#firewall防火墙详解和配置以及iptables防火墙(建议开启此防火墙,适应配置)

1,官方文档介绍:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html#sec-Introduction_to_firewalld1

2,CentOS 7中防火墙是一个非常的强大的功能,是在CentOS 6.5中在iptables防火墙中进行的升级。

3,firewall配置

  1,系统配置目录(目录中存放定义好的网络服务和端口参数,系统参数,不能修改)

/usr/lib/firewalld/services

  2,用户配置目录

/etc/firewalld/

  3,查询状态,开放端口,启用

查询服务状态
systemctl status firewalld

查看firewall状态
firewall-cmd --state

查询哪些端口开放firewall-cmd --list-port

查询端口是否开放(eg:80)
firewall-cmd --query-port=80/tcp
开放端口(eg:80)firewall-cmd --zone=public --add-port=80/tcp --permanent

移除端口(eg:8080)firewall-cmd --permanent --remove-port=8080/tcp
重启防火墙(修改配置后要重启防火墙)systemctl start firewalld.service #firewall启动systemctl enable firewalld.service #firewall开机启动systemctl restart firewalld.service // firewall-cmd --reload

关闭firewall:

 systemctl stop firewalld.service #停止firewall

 systemctl disable firewalld.service #禁止firewall开机启动


参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;2,--zone #作用域,Zone的概念,可以将具体的端口制定到具体的zone配置文件中  补:如果–zone=dmz 这样设置的话,会在dmz.xml文件中新增一条3,--add-port=80/tcp #添加端口,格式为:端口/通讯协议4,--permanent :表示设置为持久,永久生效,没有此参数重启后失效

  4,通过配置文件添加端口

cd /etc/firewalld/zones
vim public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas.</description>
  <rule family="ipv4">
    <source address="122.10.70.234"/>
    <port protocol="udp" port="514"/>
    <accept/>
  </rule>
  <rule family="ipv4">
    <source address="123.60.255.14"/>
    <port protocol="tcp" port="10050-10051"/>
    <accept/>
  </rule>
 <rule family="ipv4">
    <source address="192.249.87.114"/> 放通指定ip,指定端口、协议
    <port protocol="tcp" port="80"/>
    <accept/>
  </rule>
<rule family="ipv4"> 放通任意ip访问服务器的9527端口
    <port protocol="tcp" port="9527"/>
    <accept/>
  </rule>
</zone>

------------------------------------------------------------------------------------------------------------------------

4,iptables配置

 1,关闭firewall

systemctl stop firewalld.service或者service firewalld stop
systemctl disable firewalld.service #禁止firewall开机启动

 2,安装iptables

yum install iptables-services #安装

 3,编辑配置

vi /etc/sysconfig/iptables #编辑防火墙配置文件

Firewall configuration written by system-config-firewallManual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT#必须开启,否则nginx无法打开-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-A INPUT -m state --state NEW -m udp -p udp --dport 8080 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT

 4,查看,启用

iptables -L#查看规则是否生效systemctl start iptables.service或者service iptables start #开启
systemctl enable iptables.service #设置防火墙开机启动

Game Over !

原文地址:https://www.cnblogs.com/Miracle1/p/11987312.html

时间: 2024-08-03 18:07:43

centos7中防火墙的使用的相关文章

CentOS7中防火墙的一些常用配置

# 启动 systemctl start firewalld # 查看状态 systemctl status firewalld # 停止关闭 systemctl disable firewalld systemctl stop firewalld # 把一个源地址加入白名单,以便允许来自这个源地址的所有连接 # 这个在集群中使用常见 # 设置后利用firewall-cmd --reload更新防火墙规则 firewall-cmd --add-rich-rule 'rule family="ip

CentOS7 中防火墙配置

systemctl  stop firewalld.service  #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 开启端口 firewall-cmd --zone=public --add-port=3306/tcp permanent    开启端口3306 firewall-cmd --reload 重启防火墙 常用命令介绍: firewall-cmd --state ##查看防火墙状态,是否running

CentOS7中firewall防火墙详解和配置,.xml服务配置详解

修改防火墙配置文件之前,需要对之前防火墙做好备份 重启防火墙后,需要确认防火墙状态和防火墙规则是否加载,若重启失败或规则加载失败,则所有请求都会被防火墙 1. firewall-cmd --state         #查看firewall的状态 firewall-cmd --list-all  #查看防火墙规则(只显示/etc/firewalld/zones/public.xml中防火墙策略) firewall-cmd --list-all-zones  #查看所有的防火墙策略(即显示/etc

CentOS中防火墙相关的命令(CentOS7中演示)

CentOS中防火墙程序主要是firewall和iptables,CentOS7中firewall服务已经默认安装好了,而iptables服务需要自己用yum  install  iptabes-services来安装.        说明:以下演示均在CentOS7中进行,其他版本也大同小异 1.firewall相关的操作 查看防火墙状态 firewall-cmd    --state 关闭防火墙 systemctl  stop   firewalld.service 开启防火墙 system

centos 7 中防火墙的关闭问题

新安装的centos 7 发现有些程序端口是关闭的,想到了防火墙和selinux selinx 好关闭 /etc/sysconfig/selinux 中 追加 SELINUX=disabled 防火墙以为也是很好弄,按照以前的老规矩,service iptables stop 或者 chkconfig --level 35 iptables off 重启后 运行 systemctl list-unit-files | grep ip  发现还有个ip6tables 没关  chkconfig -

centos7 firewall 防火墙

CentOS7.0中默认使用firewall代替了iptables service.虽然继续保留了iptables命令,但已经仅是名称相同而已.除非手动删除firewall,再安装iptables,否则不能继续使用以前的iptables配置方法. 检查防火墙状态# firewall-cmd --staterunning# systemctl stop firewalld# firewall-cmd –statenot running 列出全部启用的区域的特性firewall-cmd --list

在虚拟机centOS7中安装Redis,主机不能访问的解决方案

1.我使用了桥接的方式. 2.导致我连接不上的原因是,centos7的防火墙拦截了请求. 首先,网上提出了2种可能,一种是在redis.conf文件中配置了bind,绑定到了127.0.0.1.第二种就是我遇到的. 我们假设你的redis放在了/~/redis文件夹下 cd redis && vim redis.conf 然后搜索 bind /bind 按n寻找是否有 bind 127.0.0.1 如果发现没有问题,那第二种: 打开终端,切换到root su iptables –I INP

开发人员学Linux(3):CentOS7中安装JDK8和Tomcat8

题外话:直到今天开始写本系列的第三篇时本人才想好为这个系列取一个名字,本系列不是为Linux运维人员准备的,而是主要为开发人员准备的,包括但不限于:希望了解Linux的开发人员:需要在Linux上部署一些组件的开发人员,如Memcached/Nginx/Redis等:需要使用一些在Linux上部署运行效果可能会更好的效果的系统,如Jetkins.SVN.JavaMelody等.希望了解一些当前较热的技术,想在虚拟机里搭建个环境把玩一番的,如.Net Core/Hadoop等.因此在本系列文章中不

CentOS6和CentOS7中简单web站点的配置步骤

一.CentOS6中简单的web站点的配置实例:1.安装httpd:~]# yum install -y httpd httpd-manual httpd-tools //安装httpd应用程序所需要的必要文档文件2.确保SElinux和iptables防火墙不会干扰httpd服务的提供:SElinux配置:~]# getenforce //查看SELinux状态Enforcing~]# setenforce 0 //设置SELinux为防火墙:~]# iptables -vnL //查看主机是