暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
3.访问控制-01.docx
22
19页
0次
2024-12-28
25墨值下载
防火墙
防⽕墙介绍
当今⼀提到防⽕墙,就会想到安全的概念。防⽕墙的作⽤就是阻挡防⽕墙外⾯的攻击。
防火墙分类:
1. 主机防⽕墙:针对单个主机进⾏防护(软件防⽕墙)
2. ⽹络防⽕墙:作为⽹络的分界点,防护内⽹之外的攻击(硬件防⽕墙)
Linux 本身是不具备防⽕墙功能的,但是 Linux 的内核管控着所有的⽹络流量。它的防⽕墙功
能是通过内核的 net_filter 模块提供的。只要内核有这个模块,那么就有防⽕墙功能。
windows⾥⾯也有防⽕墙,在 windows10⾥⾯是 windows definder 的⼀个组件。
iptables 防火墙
Linux 的防⽕墙功能是 net_filter 模块提供的,iptables 是⼀个客户端,客户端是⽤来接收⽤
户命令的,iptables 将⽤户的命令转换成对应的 net_filter⾥⾯的过滤规则。
1.查看 iptables 的表
iptables -L:能看 INPUTOUTPUT FORWARD 三个规则的链
[root@pghost ~]# systemctl stop firewalld --先关闭 firewalld
[root@pghost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
iptables -L -t nat:能看到 prerouting postrouting 的规则
[root@pghost ~]# iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
iptables -F # 清空所有的防⽕墙规则
iptables -X # 删除⽤户⾃定义的空链
iptables -Z # 清空计数
2.添加规则:
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 22 -j ACCEPT
-A 表示添加,INPUT 表示添加的位置
-s 表示源,192.168.1.0/24 表示数据包中源 ip 192.168.1.0/24⽹段将会被匹配
-p 表示协议,tcp 就表示协议是 tcp 将会被匹配
--dport 表示⽬的端⼝,22 就表示⽬的端⼝是 22 将会被匹配
-j 表示动作,ACCEPT 就表示接受(允许),REJECT 表示拒绝
iptables -A INPUT -s 192.168.2.0/24 -p tcp --dport 22 -j REJECT
--查看规则
[root@pghost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.1.0/24 anywhere tcp dpt:ssh
REJECT tcp -- 192.168.2.0/24 anywhere tcp dpt:ssh reject-with icmp-
port-unreachable
3.删除规则
iptables -D INPUT -s 192.168.2.0/24 -p tcp --dport 22 -j REJECT
[root@pghost sysconfig]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.1.0/24 anywhere tcp dpt:ssh
4.iptables 默认规则
vi /etc/sysconfig/iptables
iptables -P INPUT DROP # 配置默认的不让进
iptables -P FORWARD DROP # 默认的不允许转发
iptables -P OUTPUT ACCEPT # 默认的可以出去
5.针对 PostgreSQL 的配置
# 查看防火墙状态,防火墙处于开启状态并且只开放了 22 端口
iptables -L
# 仅允许本地子网访问 PostgreSQL 端口
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 5432 -j ACCEPT
# 查看地址限制,是否通过防火墙限制 5432 端口
iptables -L
rewalld 防火墙
firewalld 是⼀个服务,这个服务提供了防⽕墙配置的⼯具。只要开启了 firewalld 服务,那么
就可以通过 firewalld 服务提供的⼯具来配置防⽕墙。
默认在 rhel7centos7 以上的版本默认就安装了 firewalld 服务。且默认 firewalld 服务是开
启的.
firewalld 服务提供了⼀个更加简单的⽅式来配置防⽕墙,原理就是 firewalld 服务将你的防⽕
墙配置命令转换成 iptables 规则。
systemctl start firewalld
systemctl status firewalld
[root@pghost ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.1.0/24 0.0.0.0/0 tcp dpt:22
REJECT tcp -- 192.168.2.0/24 0.0.0.0/0 tcp dpt:22 reject-with icmp-port-
unreachable
firewalld 服务给我们提供了两种⼯具,⼀种是图形化的防⽕墙管理⼯具,⼀种是命令⾏的管
理⼯具。
命令⾏⼯具是 firewall-cmd
[root@pghost sysconfig]# firewall-cmd --add-service=http
success
[root@pghost sysconfig]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client http ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
firewalld 提供了 zone 的概念, zone 是区域的意思, firewalld 将我们的系统划分成了⼀个
个的 zone
zone 的边界取决于⽹卡,⼀个⽹卡只能属于⼀个 zone
firewalld zone⾥⾯有⽹卡,有规则(rule)。如果⼀个⽹卡属于 firewalld 的某个 zone
那么这个 zone⾥⾯的所有规则都会应⽤到该 zone 内的⽹卡。
of 19
25墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。