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. IOS Quarzt2D 手动的释放

    - (void)drawRect:(CGRect)rect { // 1.获取上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.绘制 ...

  2. hdu-3790 最短路径问题---dijkstra两重权值

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3790 题目大意: 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到 ...

  3. JQuery从服务器端取得数据绑定到dropdownlist(select)中

    http://blog.csdn.net/gaofang2009/article/details/5840783 http://www.cnblogs.com/Mac_Hui/archive/2010 ...

  4. swpan&expect交互脚本

    #!/usr/bin/expectset timeout 30set user USERNAMEset pass PASSWORDspawn sudo pg_dump npi -U admin -p ...

  5. Linux 系统性能

    Linux:PS命令详解与使用   要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程,ps命令就是最基本进程查看命令.使用该命令可以确定有哪些进程正在运行和运行的状态.进程 ...

  6. JZOJ 3383. 【NOIP2013模拟】太鼓达人

    3383. [NOIP2013模拟]太鼓达人 (Standard IO) Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limits ...

  7. ubuntu 压缩 解压 命令大全

    ubuntu下文件压缩/解压缩命令总结 http://blog.csdn.net/luo86106/article/details/6946255 .gz 解压1:gunzip FileName.gz ...

  8. Gender Equality in the Workplace【职场上的性别平等】

    Gender Equality in the Workplace A new batch of young women - members of the so-called Millennial ge ...

  9. UML类图关系模式(C++代码说明)

    在UML类图中的关系模式主要有以下几种: 泛化(Generalization),  实现(Realization), 关联(Association), 聚合(Aggregation), 依赖(Depe ...

  10. DFS:POJ1088-滑雪(记忆化搜索)

    题目: 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 97666 Accepted: 37055 Description ...