CentOS7中如何使用FirewallD
本篇内容主要讲解“CentOS7中如何使用FirewallD”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“CentOS7中如何使用FirewallD”吧!
FirewallD 使用服务(service) 和区域(zone)来代替 iptables 的规则(rule)和链(chain)。
默认情况下,有以下的区域(zone)可用:
要列出所有可用的区域,运行:
#firewall-cmd--get-zonesworkdropinternalexternaltrustedhomedmzpublicblock
列出默认的区域 :
#firewall-cmd--get-default-zonepublic
改变默认的区域 :
#firewall-cmd--set-default-zone=dmz#firewall-cmd--get-default-zonedmzFirewallD 服务
FirewallD 服务使用 XML 配置文件,记录了 firewalld 服务信息。
列出所有可用的服务:
#firewall-cmd--get-servicesamanda-clientamanda-k5-clientbaculabacula-clientcephceph-mondhcpdhcpv6dhcpv6-clientdnsdocker-registrydropbox-lansyncfreeipa-ldapfreeipa-ldapsfreeipa-replicationftphigh-availabilityhttphttpsimapimapsippipp-clientipseciscsi-targetkadminkerberoskpasswdldapldapslibvirtlibvirt-tlsmdnsmoshmountdms-wbtmysqlnfsntpopenvpnpmcdpmproxypmwebapipmwebapispop3pop3spostgresqlprivoxyproxy-dhcpptppulseaudiopuppetmasterradiusrpc-bindrsyncdsambasamba-clientsanesmtpsmtpssnmpsnmptrapsquidsshsynergysyslogsyslog-tlstelnettftptftp-clienttinctor-sockstransmission-clientvdsmvnc-serverwbem-httpsxmpp-boshxmpp-clientxmpp-localxmpp-server
XML 配置文件存储在 /usr/lib/firewalld/services/ 和 /etc/firewalld/services/ 目录下。
用 FirewallD 配置你的防火墙作为一个例子,假设你正在运行一个 web 服务器,SSH 服务端口为 7022 ,以及邮件服务,你可以利用 FirewallD 这样配置你的服务器:
首先设置默认区为 dmz。
#firewall-cmd--set-default-zone=dmz#firewall-cmd--get-default-zonedmz
为 dmz 区添加持久性的 HTTP 和 HTTPS 规则:
#firewall-cmd--zone=dmz--add-service=http--permanent#firewall-cmd--zone=dmz--add-service=https--permanent
开启端口 25 (SMTP) 和端口 465 (SMTPS) :
firewall-cmd--zone=dmz--add-service=smtp--permanentfirewall-cmd--zone=dmz--add-service=smtps--permanent
开启 IMAP、IMAPS、POP3 和 POP3S 端口:
firewall-cmd--zone=dmz--add-service=imap--permanentfirewall-cmd--zone=dmz--add-service=imaps--permanentfirewall-cmd--zone=dmz--add-service=pop3--permanentfirewall-cmd--zone=dmz--add-service=pop3s--permanent
因为将 SSH 端口改到了 7022,所以要移除 ssh 服务(端口 22),开启端口 7022:
firewall-cmd--remove-service=ssh--permanentfirewall-cmd--add-port=7022/tcp--permanent
要应用这些更改,我们需要重新加载防火墙:
firewall-cmd--reload
最后可以列出这些规则:
#firewall-cmd–list-alldmztarget:defaulticmp-block-inversion:nointerfaces:sources:services:httphttpsimapimapspop3pop3ssmtpsmtpsports:7022/tcpprotocols:masquerade:noforward-ports:sourceports:icmp-blocks:richrules:
到此,相信大家对“CentOS7中如何使用FirewallD”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。