netfilter
iptables
firewalld
firewalld和iptables的区别
firewalld | iptables | |
配置文件 | /etc/firewalld/firewalld.conf或/usr/lib/firewalld/ | /etc//sysconfig/iptables |
对规则的修改 | 不需要全部刷新策略,不丢实现行连接 | 需要全部刷新策略,丢失连接 |
防火墙类型 | 动态防火墙 | 静态防火墙 |
四表
五链
iptables常用参数
服务器
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# iptables -I INPUT -i ens33 -p tcp --dport 80 -s 192.168.43.155/24 -j ACCEPT
//192.168.43.155客户机的IP地址
firewalld网络区域 | 网络区域描述 |
drop(丢弃) | 任何接收的网络数据包都被丢弃,没有任何回复。仅能有发送出去的网络连接 |
block(限制) | 任何接收的网络连接都被IPv4的icmp-host-prohibited信息和IPv6的icmp6-adm-prohibited信息所拒绝 |
public(公共) | 在公共区域内使用,不能相信网络内的其他计算机不会对您的计算机造成危害,只能接收经过选取的连接 |
exiernal(外部) | 特别是为路由器启用了伪装功能的外部网。您不能信任来自网络的其他计算,不能相信它们不会对您的计算机造成危害,只能接收经过选择的连接 |
dmz(非军事区) | 用于你的非军事区内的电脑,此区域内可公开访问,可以有限地进入您的内部网络,仅仅接收经过选择的连接 |
work(工作) |
用于工作区,您可以基本相信网络内的其他电脑不会危害您的电脑。仅仅接收经过选择的连接
|
home(家庭) |
用于家庭网络。您可以基本信任网络内的其他计算机不会危害您的计算机。仅仅接收经过选择的连接 |
internal(内部) | 用于内部网络。您可以基本上信任网络内的其他计算机不会威胁您的计算机。仅仅接受经过选择的连接 |
trusted(信任) | 可接受所有的网络连接 |
firewalld数据处理流程
运行时配置
永久配置
注:业务繁忙时,不能使用永久配置,不然会造成业务中断
firewall-config图形工具的工作流程
注:利用firewall-config命令在终端上进入图形化界面
命令行工具 firewall-cmd
firewalld的配置文件目录/etc/firewalld ,/usr/lib/firewalld
[root@localhost ~]# cd /etc/firewalld
[root@localhost firewalld]# ls
firewalld.conf helpers icmptypes ipsets lockdown-whitelist.xml services zones
[root@localhost firewalld]# cd /usr/lib/firewalld
[root@localhost firewalld]# ls
helpers icmptypes ipsets services xmlschema zones
[root@localhost firewalld]#
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# firewall-cmd --state
not running
[root@localhost ~]# systemctl restart firewalld
[root@localhost ~]# firewall-cmd --state
running
[root@localhost ~]#
//功能同比systemctl status firewalld
[root@localhost ~]# firewall-cmd --reload
success
//状态信息将会丢失,多用于处理防火墙出现问题
[root@localhost ~]# firewall-cmd --complete-reload
success
[root@localhost ~]#
//查看预定义的区域
[root@localhost ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
//查看预定义的服务
[root@localhost ~]# firewall-cmd --get-service
RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master high-availability http https imap imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kibana klogin kpasswd kshell ldap ldaps libvirt libvirt-tls managesieve mdns mosh mountd ms-wbt mssql mysql nfs nrpe ntp open ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server
//查看预定义的icmp类型
[root@localhost ~]# firewall-cmd --get-icmptypes
[root@localhost ~]# firewall-cmd --get-default-zone
public
[root@localhost ~]#
[root@a ~]# firewall-cmd --set-default-zone=internal
success
[root@a ~]# firewall-cmd --get-default-zone
internal
[root@a ~]#
[root@a ~]# firewall-cmd --get-active-zones
internal
interfaces: ens33
[root@a ~]#
//区域至少关联着一个接口(网卡)或者一个源地址/网段
注:get在linux中有下载和查看的含义
[root@a ~]# firewall-cmd --get-zone-of-interface=ens33
internal
[root@a ~]# firewall-cmd --zone=work --add-interface=ens33
The interface is under control of NetworkManager, setting zone to 'work'.
success
查看网络连接的默认区域,默认区域没有改变
[root@a ~]# firewall-cmd --get-default-zone
internal
[root@a ~]# firewall-cmd --zone=work --change-interface=ens33
The interface is under control of NetworkManager and already bound to 'work'
The interface is under control of NetworkManager, setting zone to 'work'.
success
[root@a ~]# firewall-cmd --get-active-zones
work
interfaces: ens33 ens37
[root@a ~]#
[root@a ~]# firewall-cmd --zone=work --remove-interface=ens33
The interface is under control of NetworkManager, setting zone to default.
success
//解除的接口会分配给默认区域
[root@a ~]# firewall-cmd --get-active-zones
work
interfaces: ens37
internal
interfaces: ens33
[root@a ~]#
[root@a ~]# firewall-cmd --zone=work --query-interface=ens33
no
[root@a ~]# firewall-cmd --zone=work --query-interface=ens37
yes
[root@a ~]#
[root@a ~]# firewall-cmd --list-all-zones
[root@a ~]# firewall-cmd --zone=internal --list-all
internal (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh mdns samba-client dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@a ~]#
[root@a ~]# firewall-cmd --list-all
internal (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh mdns samba-client dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@a ~]#
[root@a ~]# firewall-cmd --zone=internal --list-services
ssh mdns samba-client dhcpv6-client
[root@a ~]#
[root@a ~]# firewall-cmd --zone=public --list-services
ssh dhcpv6-client
[root@a ~]# firewall-cmd --zone=public --add-service=smtp
success
[root@a ~]# firewall-cmd --zone=public --list-services
ssh dhcpv6-client smtp
[root@a ~]#
[root@a ~]# firewall-cmd --zone=internal --list-services
ssh mdns samba-client dhcpv6-client
[root@a ~]# firewall-cmd --zone=internal --remove-service=ssh
success
[root@a ~]# firewall-cmd --zone=internal --list-services
mdns samba-client dhcpv6-client
[root@a ~]#
[root@a ~]# firewall-cmd --zone=internal --query-service=ssh
no
[root@a ~]#
[root@a ~]# firewall-cmd --zone=internal --list-ports
[root@a ~]# firewall-cmd --zone=internal --add-port=22/tcp --timeout=5m
success
//timeout表示时间持续为5分钟
[root@a ~]# firewall-cmd --zone=internal --list-ports
22/tcp
[root@a ~]#
[root@a ~]# firewall-cmd --zone=internal --list-ports
22/tcp
[root@a ~]# firewall-cmd --zone=internal --remove-port=22/tcp
success
[root@a ~]# firewall-cmd --zone=internal --list-ports
[root@a ~]#
[root@a ~]# firewall-cmd --zone=internal --list-ports
[root@a ~]# firewall-cmd --zone=internal --query-port=22/tcp
no
[root@a ~]#
[root@a ~]# firewall-cmd --zone=work --list-icmp-blocks
[root@a ~]# firewall-cmd --zone=work --add-icmp-block=echo-reply
success
[root@a ~]# firewall-cmd --zone=work --list-icmp-blocks
echo-reply
[root@a ~]#
[root@a ~]# firewall-cmd --zone=work --remove-icmp-block=echo-reply
success
[root@a ~]# firewall-cmd --zone=work --list-icmp-blocks
[root@a ~]#
[root@a ~]# firewall-cmd --zone=work --query-icmp-block=echo-request
no
[root@a ~]#