firewall zone_firewalld关闭端口

firewall zone_firewalld关闭端口自定义zone#添加/删除zonefirewall-cmd–new-zone=mysshzone–permanentfirewall-cmd–delete-zone=mysshzone–permanent#查询所有zone列表firewall-cmd–get-zonesblockdmzdropexternalhomeinternalmysshzonepublictrustedwork#显示生效的zonefirewall-cmd–get-a

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

目录

自定义zone

自定义ipset

案例一:centos8源地址访问限制

案例二:(留个小尾巴,后面会接续介绍firewalld预定义zone的作用)

开篇先讲一下写本文的由来:了解/etc/hosts.allow/etc/hosts.deny的同学肯定知道,这是用来做源地址访问控制的两个配置文件。实质上,是由TCP_Wrappers实现的安全访问控制;凡是包含有libwrap.so库文件的程序就会受TCP_Wrappers的安全控制。所以,这也是它的局限性。更甚,CentOS8已经舍弃了TCP_Wrappers(tcp_wrappers-libs包),即便我们手动进行安装,也不会生效;原因就是CentOS8自带的ssh等软件不再集成libwrap.so库。

那么,没有了TCP_Wrappers怎么做源地址访问控制呢?答案是通过系统自带防火墙,无论iptables还是firewalld都能做到(见案例一)。当然,一些软件本身也自带了访问控制功能(比如:ssh的Match指令)

注:TCP_Wrappers是一个工作在网络传输层的安全工具,它对有状态连接的特定服务进行安全检测并实现访问控制。

自定义zone

# 添加/删除zone
firewall-cmd --new-zone=mysshzone --permanent
firewall-cmd --delete-zone=mysshzone --permanent
# 查询所有zone列表
firewall-cmd --get-zones 
block dmz drop external home internal mysshzone public trusted work
# 显示生效的zone
firewall-cmd --get-active-zone
mysshzone
  sources: 192.168.186.103 192.168.10.182 ipset:4mysshzone
public
  interfaces: ens192
trusted
  sources: 192.168.10.124
## 查看zone信息
firewall-cmd --info-zone=mysshzone
### 上面命令效果同:
firewall-cmd --zone=mysshzone --list-all
# 查看所有zone的详细配置
firewall-cmd --list-all-zones
## zone添加/删除源地址
firewall-cmd --permanent --zone=mysshzone --add-source=192.168.186.103
firewall-cmd --permanent --zone=mysshzone --remove-source=192.168.186.103
## zone绑定/解绑ipset
firewall-cmd --permanent --zone=mysshzone --add-source=ipset:4mysshzone
firewall-cmd --permanent --zone=mysshzone --remove-source=ipset:4mysshzone

自定义ipset

## 查看ipset列表
firewall-cmd --permanent --get-ipsets
4mysshzone
## 查看ipset详细信息
firewall-cmd --permanent --info-ipset=4mysshzone
4mysshzone
  type: hash:ip
  options: 
  entries: 192.168.186.125
## 查看ipset配置文件存放路径
firewall-cmd --permanent --path-ipset=4mysshzone
/etc/firewalld/ipsets/4mysshzone.xml
### 查看ipset XML文件
cat /etc/firewalld/ipsets/4mysshzone.xml                                  
<?xml version="1.0" encoding="utf-8"?>
<ipset type="hash:ip">
  <entry>192.168.186.125</entry>
</ipset>
## 删除ipset
firewall-cmd --delete-ipset=4mysshzone --permanent
## 创建ipset
firewall-cmd --new-ipset=4mysshzone --type=hash:ip --permanent
## ipset添加/删除entry
firewall-cmd --permanent --ipset=4mysshzone --add-entry=192.168.186.125 
firewall-cmd --permanent --ipset=4mysshzone --remove-entry=192.168.186.125
firewall-cmd --permanent --ipset=4mysshzone --add-entry=192.168.186.1/24  #type: hash:ip可以加网段
## 获取所有ipset的entry
firewall-cmd --permanent --ipset=4mysshzone --get-entries
192.168.186.125
192.168.186.1/24
## 验证某IP是否在该ipset的entry中,并不会匹配网段范围
firewall-cmd --permanent --ipset=4mysshzone --query-entry=192.168.186.125
yes
### 不能匹配到192.168.186.1/24
firewall-cmd --permanent --ipset=4mysshzone --query-entry=192.168.186.12
no

## 查看所有ipset类型
firewall-cmd --get-ipset-types
hash:ip hash:ip,mark hash:ip,port hash:ip,port,ip hash:ip,port,net hash:mac hash:net hash:net,iface hash:net,net hash:net,port hash:net,port,net

案例一:centos8源地址访问限制

# 安全加固
firewall-cmd --new-zone=mysshzone --permanent
firewall-cmd --delete-zone=mysshzone --permanent
## 语法: --add-source=source[/mask]|MAC|ipset:ipset
firewall-cmd --permanent --zone=mysshzone --add-source=192.168.186.103
firewall-cmd --permanent --zone=mysshzone --add-port=22/tcp
firewall-cmd --reload

案例二:(留个小尾巴,后面会接续介绍firewalld预定义zone的作用)

# 避免管理客户端被关在防火墙之外,设置白名单
firewall-cmd --permanent --zone=trusted --add-source=192.168.10.124
firewall-cmd --reload
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/185261.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Yii2 Call to a member function validateCsrfToken() on string

    Yii2 Call to a member function validateCsrfToken() on string

    2022年2月18日
    37
  • 邮箱发送验证码和短信发送验证码的学习笔记

    邮箱发送验证码和短信发送验证码的学习笔记邮箱发送验证码和短信发送验证码

    2022年10月12日
    0
  • springboot集成了哪些框架_redis java客户端

    springboot集成了哪些框架_redis java客户端Springboot集成Redis添加Redis依赖<depency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!–连接池–>

    2022年9月22日
    0
  • 常用的分布式事务解决方案有哪些_分布式事务redis解决方案

    常用的分布式事务解决方案有哪些_分布式事务redis解决方案首页 博客 专栏·视频 下载 论坛 问答 代码 直播 能力认证 高校会员中心收藏动态消息创作中心常用的分布式事务解决方案凌澜星空2018-03-1114:44:5575315收藏466分类专栏:架构高性能网站微服务项目实战文章标签:微服务分布式架构事务一致性版权众所周知,数据库能实现本地事务,也就是在同一个数据库中,你可以允许一组操作要么全都正确执行,要么全都不执行。这里特别强调了本地事务,也就是目前的…

    2022年10月26日
    0
  • rtsp html播放_浏览器视频播放rtsp

    rtsp html播放_浏览器视频播放rtsp从摄像机获取的RTSP视频流直接在浏览器中播放,这里采用vlc插件进行播放,设置步骤如下1、下载32位的vlc播放器,安装时选择安装插件,安装路径不要有空格,注意64位播放器安装上也不能正常播放(我测试不能正常播放)2、注册VLC插件(否则视频无法正常显示):使用cmd运行:regsvr32D:\VideoLAN32\VLC\axvlc.dll其中D:\VideoLAN32\VLC为VLC安…

    2022年10月9日
    0
  • 分布式锁-这一篇全了解(Redis实现分布式锁完美方案)[通俗易懂]

    前言在某些场景中,多个进程必须以互斥的方式独占共享资源,这时用分布式锁是最直接有效的。随着技术快速发展,数据规模增大,分布式系统越来越普及,一个应用往往会部署在多台机器上(多节点),在有些场景中,为了保证数据不重复,要求在同一时刻,同一任务只在一个节点上运行,即保证某一方法同一时刻只能被一个线程执行。在单机环境中,应用是在同一进程下的,只需要保证单进程多线程环境中的线程安全性,通过JAV…

    2022年4月12日
    36

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号