firewalld的介绍与简单应用
CentOS7的默认防火墙是firewalld,在之前使用iptables时,关闭了firewalld服务,现在反过来关闭iptables服务,打开firewalld服务:
systemctl disable iptables
systemctl stop iptables
systemctl enable firewalld
systemctl start firewalld 打开firewalld服务之后,iptables相关的命令其实也可以继续使用的,但在CentOS7中不用那么操作,因为firewalld有自己的命令。
firewalld有两个基础概念,zone和service,每个zone里面有不同的iptables规则,默认一共有9个zone,CentOS7默认zone为public,查看系统所有zone,使用命令
firewall-cmd --get-zones //查看所有zone
firewall-cmd --get-default-zone //查看默认zone 9个zone的简单介绍: drop(丢弃):任何接受的网络数据包都被丢弃,没有任何回复。仅能有发送出去的网络连接。
block(限制):任何接受的网络连接被IPv4的 icmp-host-prohibited 信息和 IPv6 的icmp6-adm-prohibited 信息所拒绝。
public (公共) :在公共区域内使用,不能相信网络内的其他计算机不会对你的计算机造成危害,只能接收经过选取的连接。
external (外部):特别是为路由器启用了伪装功能的外部网。你不能信任来自网络的其他计算,不能相信它们不会对你的计算机造成危害,只能接收经过选择的连接。
dmz(非军事区):用于的非军事区内的电脑,此区域内可公开访问,可以有限地进入你的内部网络,仅仅接收经过选择的连接。
work(工作):用于工作区。你可以基本相信网络内的其他电脑不会危害你的电脑。仅仅接收经过选择的连接。
home(家庭):用于家庭网络。你可以基本信任网络内的其他计算机不会危害你的计算机。仅仅接收经过选择的连接。
internal(内部):用于内部网络。你可以基本上信任网络内的其他计算机不会威胁你的计算机。仅仅接收经过选择的连接。
trusted(信任):可接受所有的网络连接 几个关于zone的命令
# firewall-cmd --set-default-zone=work //设定默认zone
# firewall-cmd --get-zone-of-interface=ens33 //查看指定网卡
# firewall-cmd --zone=public --add-interface=lo //给指定网卡设置zone
# firewall-cmd --zone=dmz --change-interface=lo //针对网卡更改zone
# firewall-cmd --zone=dmz --remove-interface=lo //针对网卡删除zone
# firewall-cmd --get-zctive-zones //查看系统所有网卡所在的zone fired中的service service 就是zone下面的一个子单元,每个zone里都使用了不同的service,而service就是针对服务(端口)做的iptables规则。
firewall-cmd --get-services //查看当前系统所有service
这些service都是由一个个配置文件定义的,配置文件的模版子啊/usr/lib/firewalld/services/目录下,真正生效的配置文件则在/etc/firewalld/services/目录下(默认为空) 关于service的一些操作命令:
# firewall-cmd --get-services
//查看所有的servies
# firewall-cmd --list-services
//查看当前zone下有哪些service
# firewall-cmd --zone=public --add-service=http
//把http服务增加到public zone下面
# firewall-cmd --zone=public --remove-service=http
//把http服务移除
# ls /usr/lib/firewalld/zones/
//zone的配置文件模板
# firewall-cmd --zone=public --add-service=http --permanent
//更改配置文件,否则只是保存在内存中,之后会在/etc/firewalld/zones目录下面生成配置文件

实例:
需求:ftp服务自定义端口1121,需要在work zone下面放行ftp。
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/
vi /etc/firewalld/services/ftp.xml
修改ftp端口号 <?xml version="1.0" encoding="utf-8"?>
<service>
<short>FTP</short>
<description>FTP is a protocol used for remote file transfer. If you plan to make your FTP server publicly available, enable this option. You need the vsftpd package installed for this option to be useful.</description>
<port protocol="tcp" port=""/> ##修改端口为1121
<module name="nf_conntrack_ftp"/>
</service>
[root@zlinux ~]# cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
[root@zlinux ~]# vi /etc/firewalld/zones/work.xml //增加ftp相关配置 <?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Work</short>
<description>For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<service name="ftp"/> ##增加ftp
</zone>
[root@zlinux ~]# firewall-cmd --reload //重新加载
success
[root@zlinux ~]# firewall-cmd --zone=work --list-services //查看是否有ftp
ssh dhcpv6-client ftp
firewalld一些常用的语句

查看默认的zone,结果为trusted
firewall-cmd --get-default-zone
public
设置默认zone为trusted
firewall-cmd --set-default-zone=trusted
success
显示当前正在使用的zone消息
firewall-cmd --get-active-zones
trusted
interfaces: eno16777736
显示系统预定义的zone,默认是9个
firewall-cmd --get-zones
block dmz drop external home internal public trusted work
显示系统预定义的服务名称:
firewall-cmd --get-services
amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https
查询eno16接口和那个zone匹配,网卡与trusted匹配,则该网卡的流量执行eno16中定义的规则,默认允许访问所以的服务:
firewall-cmd --get-zone-of-interface=eno16777736
trusted
显示所以zone及其相对应的规则信息
firewall-cmd --list-all-zone
block
interfaces:
sources:
services:
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules: dmz
interfaces:
sources:
services: ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
.......
在public这个zone中添加允许访问ftp服务的规则
firewall-cmd --add-service=ftp --zone=public
success
从public这个zone中删除允许访问ftp服务的规则
firewall-cmd --remove-service=ftp --zone=public
success
在public这个zone中添加允许访问3306端口的规则
firewall-cmd --add-port=/tcp --zone=public
从public这个zone中删除允许访问3306端口的规则
firewall-cmd --remove-port=/tcp --zone=public
success
将eno16网卡和public绑定,以后从该接口进入的流量,匹配到public中的规则
firewall-cmd --add-interface=eno16 --zone=public
success
将eno16网卡与public解除绑定
firewall-cmd --remove-interface=eno16 --zone
trusted
将源ip地址1.1.1.1与public绑定,以后该主机访问本机时匹配public中的规则
firewall-cmd --add-source=1.1.1.1 --zone=public
success
在public这个zone中添加一条永久规则(允许访问3306端口),规则重启防火墙后依然生效
firewall-cmd --permanent --add-port=/tcp --zone=public
重新加载读取防火墙规则
firewall-cmd --reload
firewall指定端口和ip访问
、启动防火墙
systemctl start firewalld.service
、指定IP与端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="" accept"
、重新载入,使配置生效
systemctl restart firewalld.service
、查看配置结果
firewall-cmd --list-all
、删除规则
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="" accept"
.对指定的IP开放指定的端口段
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="-" accept"

firewalld的防火墙的更多相关文章

  1. CentOS 使用firewalld打开防火墙与端口

    CentOS 使用firewalld打开防火墙与端口 LinuxCentOS 基本使用 启动 : systemctl start firewalld 关闭 : systemctl stop firew ...

  2. centos7 && centos6.5部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发

    centos7 && centos6.5 部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发 一.准备工作: 1: 检查kvm ...

  3. firewalld管理防火墙常用命令

    1.查看防火墙的状态 [root@localhost HMK]# firewall-cmd --state 查看防火墙的运行状态 not running [root@localhost HMK]# s ...

  4. Centos7管理selinux及使用firewalld管理防火墙

    CentOS 7.0默认使用的是firewall作为防火墙 1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status ...

  5. Linux学习笔记之CentOS 7系统使用firewalld管理防火墙端口

    0x00 firewalld的基本使用 # 启动: systemctl start firewalld # 查看状态: systemctl status firewalld # 停止: systemc ...

  6. CentOS7使用firewalld管理防火墙与端口

    firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status fir ...

  7. centos8用firewalld搭建防火墙

    一,firewalld的systemd管理命令 启动:systemctl start firewalld 关闭:systemctl stop firewalld 查看状态:systemctl stat ...

  8. 第二十三章 Firewalld的防火墙

    一.防火墙基本概述 在CentOS7系统中集成了多款防火墙管理工具,默认启用的是firewalld(动态防火墙管理器)防火墙管理工具,Firewalld支持CLI(命令行)以及GUI(图形)的两种管理 ...

  9. CentOS7使用firewalld管理防火墙

    firewalld的基本使用 #启动 systemctl start firewalld #关闭 systemctl stop firewalld #查看状态 systemctl status fir ...

随机推荐

  1. JS中的Global对象

    Global对象可以说是ECMAScript中最特别的一个对象了.因为不管你从什么角度上看,这个对象都是不存在的.ECMAScript中的Global对象在某种意义上是作为一个终极的“兜底儿对象”来定 ...

  2. 可以使用可用的服务和参数调用在“eWorld.WCFImplement.ServiceImplement.ImageArchiveService”类型上使用“Autofac.Core.Activators.Reflection.DefaultConstructorFinder”找到的构造函数: 无法解析参数'eWorld.WCFBLL.ImageArchive.IDocumentOperation

    可以使用可用的服务和参数调用在“eWorld.WCFImplement.ServiceImplement.ImageArchiveService”类型上使用“Autofac.Core.Activato ...

  3. spark 之knn算法

    好长时间忙的没写博客了.看到有人问spark的knn,想着做推荐入门总用的knn算法,顺便写篇博客. 作者:R星月  http://www.cnblogs.com/rxingyue/p/6182526 ...

  4. 【洛谷1337】[JSOI2004] 吊打XXX(模拟退火经典题)

    点此看题面 大致题意: 一个平面上有\(n\)个点,每个点有1个权值,现在要选择平面上的一个点,使这\(n\)个点的权值乘上到达选定点的距离之和最小. 模拟退火 我们可以用模拟退火来做这道题. 先将\ ...

  5. 【BZOJ1433】[ZJOI2009] 假期的宿舍(二分图匹配入门)

    点此看题面 大致题意:有\(n\)个学生,其中一部分是在校学生,一部分不是,而在校学生中一部分回家,一部分不回家,并且我们用一个01矩阵表示学生之间相互认识关系.已知每个学生只能睡自己认识的人的床(当 ...

  6. 2dsphere索引

    概念:球面地理位置索引 创建方式: db.collection.ensureIndex({w:'2dsphere'}) wdspere中,位置的表示方式不再是简单的经度,纬度,数组,而是变成一种复杂的 ...

  7. mac 远程桌面提示: 证书或相关链无效

    左上角 RDC -->首选项-->安全性-->即使验证失败,也始终链接

  8. 《剑指offer》【调整数组顺序使奇数位于偶数前面】(python版)

    题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分 思路: 我认真看了一下,题目应该是要求在原地调整,所以这里不能再 ...

  9. kindeditor 上传图片失败问题总结

    1.近段时间一直在处理kindeditor上传图片失败的问题,前期一直以为是前端的问题,利用谷歌控制台,打断点,修改方法,一直都找不到解决方案,直到查看服务器配置,才发现: WEB 1号服务器 /da ...

  10. 数据结构期末复习( はち)--VOA图关键路径求法

    题目如下图: 注:将123456当成abcdef. 事件最早发生事件求法:找从原点到该事件的最长路径(从前往后推) 对a:Ve=0 对b:Ve=max{ 2 , 15+4 }=19 对c:Ve=15 ...