防火墙策略

所谓防火墙指的是一个有软件和硬件设备组合而成、在内部网和外部网之间、专用网与公共网之间的界面上构造的保护屏障。
防火墙是一种保护计算机网络安全的技术性措施,它通过在网络边界上建立相应的网络通信监控系统来隔离内部和外部网络,以阻挡来自外部的网络入侵。

这里写图片描述

一、防火墙的区域划分

网络区域名称 默认配置
block 拒绝所有的网络连接
dmz(非军事区) 仅接受ssh服务连接
drop 任何接受的网络数据包都被丢弃,没有任何回复
external 出去的ipv4网络连接通过此区域伪装和转发,仅接受ssh服务
home 用于家庭网络,仅接受ssh,mdns.ipp-client.samba-client或dhcpv6-client服务连接
internal 用于内部网络,仅接受ssh,mdns.ipp-client.samba-client,dhcpv6-client服务连接
public 在公共区域内使用,仅接受ssh或dhcpv6-client服务连接,为firewalld的默认区域
trusted 可接受所有连接
work 用于工作区。仅接受ssh,ipp-client或dhcpv6-client服务连接
安装防火墙服务及GUI配置工具
[root@foundation79 Desktop]# yum install firewalld firewall-config -y

二、防火墙的相关命令

1.firewalld的系统服务命令
命令 功能
systemctl start firewalld 启动
systemctl stop firewalld.service 关闭一个服务
systemctl restart firewalld.service 重启一个服务
systemctl status firewalld.service 显示一个服务的状态
systemctl enable firewalld.service 在开机时启用一个服务
systemctl disable firewalld.service 在开机时禁用一个服务
systemctl is-enabled firewalld.service 查看服务是否开机启动
systemctl list-unit-files grep enabled
systemctl –failed 查看启动失败的服务列表
2.防火墙相关命令
命令 实现功能
firewall-cmd –version 查看版本
firewall-cmd –state 显示状态
firewall-cmd –zone=public –list-ports 查看所有打开的端口
firewall-cmd –reload 更新防火墙规则
firewall-cmd –get-active-zones 查看区域信息
firewall-cmd –get-zone-of-interface=eth0 查看指定接口所属区域
firewall-cmd –panic-on 拒绝所有包
firewall-cmd –panic-off 取消拒绝状态
firewall-cmd –query-panic 查看是否拒绝

实验:
查看防火墙信息:
[root@server ~]# firewall-cmd --state    #查看火墙状态
running
[root@server ~]# firewall-cmd --get-active-zones #查看区域信息
ROL
  sources: 172.25.0.252/32
public
  interfaces: eth0
[root@server ~]# firewall-cmd --get-default-zone #默认分配的域
public
[root@server ~]# firewall-cmd --zone=public --list-all
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 

三、更改防火墙配置:

1.端口配置
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent    #添加
success
[root@localhost ~]# firewall-cmd --reload    #重新载入
success
[root@localhost ~]# firewall-cmd --zone=public --query-port=80/tcp                  #查看
yes
[root@localhost ~]# firewall-cmd --zone=public --remove-port=80/tcp --permanent       #删除
success
[root@localhost ~]# firewall-cmd --reload 
success
[root@localhost ~]# firewall-cmd --zone=public --query-port=80/tcpno
2.更改域
[root@localhost ~]# firewall-cmd --set-default-zone=trusted                      #设置防火墙默认域trusted
success
[root@localhost html]# vim index.html     #更改http默认发布文件
    <h1 style=color:RED>FIREWALLD</h1>
[root@localhost html]# systemctl start httpd   #开启apache

在浏览器中键入IP地址
这里写图片描述

[root@localhost html]# firewall-cmd --set-default-zone=public          #更改默认域为public后只接受ssh或dhcpv6-client服务连接
success

这里写图片描述

3.更改特定主机的所属域
[root@localhost html]# firewall-cmd --add-source=172.25.254.79 --zone=trusted 
success        
[root@localhost html]# firewall-cmd --list-all --zone=trusted 
trusted
  interfaces: 
  sources: 172.25.254.79
  services: 
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
4.更改网卡的域

列出所有网卡:

[root@localhost ~]# firewall-cmd --list-interfaces 
eth1

查看eth1的域:

[root@localhost ~]# firewall-cmd --get-zone-of-interface=eth1
public

更改eth1域信息:

[root@localhost html]# firewall-cmd --change-interface=eth1 --zone=trusted 
success
[root@localhost html]# firewall-cmd --get-zone-of-interface=eth1        
trusted          #更改成功
5.临时添加服务

可添加的服务:

[root@localhost firewalld]# firewall-cmd --add-service=
amanda-client        kpasswd              pop3s
bacula               ldap                 postgresql
bacula-client        ldaps                proxy-dhcp
dhcp                 libvirt              radius
dhcpv6               libvirt-tls          rpc-bind
dhcpv6-client        mdns                 samba
dns                  mountd               samba-client
ftp                  ms-wbt               smtp
high-availability    mysql                ssh
http                 nfs                  telnet
https                ntp                  tftp
imaps                openvpn              tftp-client
ipp                  pmcd                 transmission-client
ipp-client           pmproxy              vnc-server
ipsec                pmwebapi             wbem-https
kerberos             pmwebapis    

临时添加ftp服务

[root@localhost firewalld]# firewall-cmd --add-service=ftp
success
[root@localhost firewalld]# firewall-cmd --list-all
public (default, active)
  interfaces: eth0 eth1
  sources: 
  services: dhcpv6-client ftp ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 

注:iscsi的服务是iscsi-target

Firewall规则文件
[root@localhost ~]# cd /etc/firewalld/
[root@localhost firewalld]# ls
firewalld.conf      icmptypes               services
firewalld.conf.old  lockdown-whitelist.xml  zones
[root@localhost firewalld]# cd zones/
[root@localhost zones]# vim public.xml

这里写图片描述


四、图形管理

[root@foundation79 Desktop]# firewall-config
You have new mail in /var/spool/mail/root

这里写图片描述

传送门:
iptables详解

猜你喜欢

转载自blog.csdn.net/qq_36747237/article/details/80616970