一、firewall介绍

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

1、官方介绍

The dynamic firewall daemon firewalld provides a dynamically managed firewall with support for network “zones” to assign a level of trust to a network and its associated connections and interfaces. It has support for IPv4 and IPv6 firewall settings. It supports Ethernet bridges and has a separation of runtime and permanent configuration options. It also has an interface for services or applications to add firewall rules directly.

2、什么是区域Zone:

网络区域定义了网络连接的可信等级。这是一个 一对多的关系,这意味着一次连接可以仅仅是一个区域的一部分,而一个区域可以用于很多连接。

3、哪个区域可用?

由firewalld 提供的区域按照从不信任到信任的顺序排序。

4、区域的分类?

Firewalls can be used to separate networks into different zones based on the level of trust the user has decided to place on the devices and traffic within that network. NetworkManager informs firewalld to which zone an interface belongs. An interface’s assigned zone can be changed by NetworkManager or via the firewall-config tool which can open the relevant NetworkManager window for you.

The zone settings in /etc/firewalld/ are a range of preset settings which can be quickly applied to a network interface. They are listed here with a brief explanation:

dropblock 、public 、external 、dmz 、work 、homeinternal 、trusted

注:具体内容,请参见官方文档介绍!

二、firewall配置

The configuration for firewalld is stored in various XML files in /usr/lib/firewalld/ and /etc/firewalld/.

This allows a great deal of flexibility as the files can be edited, written to, backed up, used as templates for other installations and so on.

注意:以下firewalld 的操作只有重启之后才有效:service firewalld restart 重启

1、系统配置目录

/usr/lib/firewalld/services

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

2、用户配置目录


/etc/firewalld/

3、如何自定义添加端口

用户可以通过修改配置文件的方式添加端口,也可以通过命令的方式添加端口,注意,修改的内容会在/etc/firewalld/ 目录下的配置文件中还体现。

  • 3.1、命令的方式添加端口

firwall-cmd

--permanent

--add-port=9527/tcp

参数介绍:

1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、--permanent:表示设置为持久;
3、--add-port:标识添加的端口;

另外,firewall中有Zone的概念,可以将具体的端口制定到具体的zone配置文件中。

例如:添加8010端口

firewall-cmd

--zone=public

--permanent

--add-port=8010/tcp

--zone=public:指定的zone为public;

添加结果如下:

如果–zone=dmz 这样设置的话,会在dmz.xml文件中新增一条。

  • 3.2、修改配置文件的方式添加端口

    上述的一个配置文件可以很好的看出:

    1、添加需要的规则,开放通源ip为122.10.70.234,端口514,协议tcp;

    2、开放通源ip为123.60.255.14,端口10050-10051,协议tcp;

    3、开放通源ip为任意,端口9527,协议tcp;

    三、firewall常用命令

    1、重启、关闭、开启firewalld.service服务

    service firewalld restart 重启 service firewalld start 开启 service firewalld stop 关闭

    注意:以上对firewalld 的操作只有重启之后才有效

    2、查看firewall服务状态

    systemctl status firewall

    3、查看firewall的状态

    firewall-cmd --state

  • 4、查看防火墙规则

    firewall-cmd --list-all

  • 四、CentOS切换为iptables防火墙

    切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务。

    1、关闭firewall:

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

    2、安装iptables防火墙

    yum install iptables-services #安装

    3、编辑iptables防火墙配置

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

    下边是一个完整的配置文件:

    :wq! #保存退出

    service iptables start #开启

    systemctl enable iptables.service #设置防火墙开机启动

原文转自:

http://www.phpchina.com/portal.php?mod=view&aid=40252

centOS7 mini配置linux服务器(三) 配置防火墙以及IPtables切换的更多相关文章

  1. Linux服务器时间同步配置

    Linux服务器时间同步配置   以CentOS7 做时间服务器,其他服务器(Centos 6.RHEL7)同步该服务器时间 RHEL 7.CentOS 7 默认的网络时间协议 为Chrony 本教程 ...

  2. 在Linux服务器上配置phpMyAdmin

    使用php和mysql开发网站的话,phpmyadmin是一个非常友好的mysql管理工具,并且免费开源,国内很多虚拟主机都自带这样的管理工具,配置很简单,接下来在linux服务器上配置phpmyad ...

  3. [亲测]ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问

    前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...

  4. 本地Linux服务器上配置Git

    当我们需要拉取远程服务器代码到本地服务器时,我们首先要确定已经配置了正确的Git账号,可以从~/.gitconfig文件(为隐藏文件,需要使用ls -a查看),以及~/.ssh下的id_rsa.pub ...

  5. [亲测]七步学会ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问

    前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...

  6. linux服务器上配置多个svn仓库

    linux服务器上配置多个svn仓库 1.在指定目录建立仓库保存总目录,本文示例目录设定为:/usr/local/svn/svnrepos # mkdir -p /usr/local/svn/svnr ...

  7. linux服务器网络配置

    一.配置linux服务器的网络 手动修改配置网卡文件 先检查网卡是否正常 lspci |grep Ether 与网卡相关的TCP/IP网络配置文件位置 /etc/sysconfig/network-s ...

  8. 【转】Linux 服务器安全配置

    第一部分:RedHat Linux篇1.概述 Linux服务器版本:RedHat Linux AS 2.1 对于开放式的操作系统---Linux,系统的安全设定包括系统服务最小化.限制远程存取.隐藏重 ...

  9. RedHat Linux服务器安全配置细节

    1.概述 Linux服务器版本:RedHat Linux AS 2.1 对于开放式的操作系统---Linux,系统的安全设定包括系统服务最小化.限制远程存取.隐藏重要资料.修补安全漏洞.采用安全工具以 ...

  10. Linux服务器安全配置

    众所周知,网络安全是一个非常重要的课题,而服务器是网络安全中最关键的环节.Linux被认为是一个比较安全的Internet服务器,作为一种开放源代码操作系统,一旦Linux系统中发现有安全漏洞,Int ...

随机推荐

  1. linux apache 打模块示例

    主要是为了以后能举一反三 Apache配置方案 首先,安装apache的一个第三方模块“mod_rpaf”, 官方网站: http://stderr.net/apache/rpaf/ wget htt ...

  2. angular指令中,require和transclude同时设置为true时的作用

    最近在学习angularJS指令的时候,对指令对象中require属性和transclude属性同时设置为true比较疑惑,于是自己动手测试一下具体差异 index.html: <simple& ...

  3. python py_innodb_page_info.py -v /usr/local/var/mysql/ibdata1

    mylib.py #encoding=utf-8 import os import include from include import * TABLESPACE_NAME='D:\\mysql_d ...

  4. js控制href内容的连接内容的变化

    html: <a data-toggle="modal" href="#myModal_devices" id="check_devices&q ...

  5. MySQL XtraBackup自动恢复脚本

      #!/bin/sh ################## #author:rrhelei@126.com# ################## #xtrabackup2.1.8 # 使用方法: ...

  6. php之 有点复杂的 流程管理

    1.流程管理的用法是什么样的? 2.怎么发起想要的流程? 3.审批的人要是怎么审批通过? 4.流程审核是不是要挨个走过? 一.还是要有数据库的内容的 肯定会有表的,首先就是用户表了,然后就是流程表,用 ...

  7. Microsoft IoT Starter Kit 开发初体验-反馈控制与数据存储

    在上一篇文章<Microsoft IoT Starter Kit 开发初体验>中,讲述了微软中国发布的Microsoft IoT Starter Kit所包含的硬件介绍.开发环境搭建.硬件 ...

  8. 分析 OVS 如何实现 vlan 隔离 - 每天5分钟玩转 OpenStack(140)

    上一节我们完成了 OVS vlan 环境的搭建,当前拓扑结构如下: cirros-vm1 位于控制节点,属于 vlan100. cirros-vm2 位于计算节点,属于 vlan100. cirros ...

  9. asp.net客户端IP跟踪

    /// <summary> /// 获取客户端IP地址(无视代理) /// </summary> /// <returns>若失败则返回回送地址</retur ...

  10. [转载] ping和telnet的区别

    转载自:http://www.cnblogs.com/Jtianlin/p/4045021.html windown7下打开telnet功能: 控制面板 --- > 程序(小图标下直接到[程序和 ...