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)
上一篇 2022年10月6日 下午4:36
下一篇 2022年10月6日 下午4:36


相关推荐

  • Java内存管理-掌握自定义类加载器的实现(七)

    勿在流沙筑高台,出来混迟早要还的。做一个积极的人编码、改bug、提升自己我有一个乐园,面向编程,春暖花开!上一篇分析了ClassLoader的类加载相关的核心源码,也简单介绍了ClassLoader的设计思想,读源码相对来说是比较枯燥的,还是这个是必须要走的过程,学习源码中的一些思想,一些精髓,看一下大神级人物是怎么写出那么牛逼的代码。我们能够从中学到一点点东西,那也是一种进步和成长了…

    2022年2月28日
    33
  • 跳转指令JNZ(jmp not equal)

    跳转指令JNZ(jmp not equal)TITLEA06MOVE EXE Repetitivemo MODELSMALL STACk64 DATAHEADNG1D InterTech HEAdNG2DB9DU CODEA1

    2026年3月17日
    2
  • vue使用axios解决跨域_vue前端解决跨域的方法

    vue使用axios解决跨域_vue前端解决跨域的方法工具版本:【vue-V】:2.9.6ide工具:VSCode/Idea前提:我们前端vue工程需要单独部署一、本地使用命令运行跨域问题。外网访问的地址:https://www.runoob.com/try/ajax/json_demo.json本地springboot接口访问的地址:http://192.168.3.12:8081/register/getSmsCode/1234567891、axios访问的代码: created(){ const_this=this

    2025年10月28日
    5
  • 搓牙机调试位置讲解_hadoopjps进程不全

    搓牙机调试位置讲解_hadoopjps进程不全1、strace-p[进程号]strace-p1002297strace:Process1002297attachedfutex(0x7fcbb95f3f84,FUTEX_WAIT_PRIVATE,1,NULL可以看到死在了futex(0x7fcbb95f3f84,FUTEX_WAIT_PRIVATE,1,NULL

    2025年11月16日
    4
  • mongo DB的一般操作

    mongo DB的一般操作

    2021年11月26日
    44
  • Windows下面的Netstat命令详解

    Windows下面的Netstat命令详解  netstat[-a][-e][-n][-o][-pProtocol][-r][-s][Interval] 参数解释:-a 显示所有活动的TCP连接以及计算机侦听的TCP和UDP端口。 -e 显示以太网统计信息,如发送和接收的字节数、数据包数。该参数可以与-s结合使用。 -n 显示活动的TCP连接,不过,只以数字…

    2022年5月30日
    41

发表回复

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

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