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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 精灵图定位

    精灵图定位.searchem{position:absolute;top:8px;right:90px;width:20px;height:20px;background:url(…/images/sprite-search.png)no-repeat;}.searchem:hover{background-position:-30px0;/*精灵图第一个值是X轴的…

    2022年5月7日
    83
  • goland 2021.11.4激活_最新在线免费激活

    (goland 2021.11.4激活)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html4M7HSKPBXS-eyJsaWNlbnNlSW…

    2022年3月29日
    42
  • 最全源码网站_短视频源码php

    最全源码网站_短视频源码php1.ASP.NET源码:http://i.aspx1.com/showforum-4.aspx2.源码之家:http://www.codejia.com/3.源码网:http://www.codepub.com/4.虾客源码:http://www.xkxz.com/5.源码开发网:http://www.codedn.com/6.洪越源代码:http://www.softhy.net/7…

    2025年10月30日
    4
  • vue文件中引入js_vue中require引入js

    vue文件中引入js_vue中require引入js由于一些演示,需要对编码名称等可快速进行修改,需要页面方便配置。由于build后的vue项目基本已经看不出原样,因此需要创建一个文件,并在打包的时候不会进行编译。vue-cli2.0的作法是在static文件下创建js。vue-cli3.0的写法则是直接在public文件夹下创建js、具体操作如下:1、在public文件夹下创建config.js文件,里面文件的语法是es5,不允许使用浏览器…

    2022年10月8日
    3
  • intellij idea激活码_通用破解码

    intellij idea激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    66
  • 微信开放平台开发第三方授权登陆(一):开发前期准备

    微信开放平台开发第三方授权登陆(一):开发前期准备据微信开放平台“开发资源”中网站应用微信登陆功能开发指南描述:进行授权登陆接入前,需要先注册一个开发者账号,并拥有一个已经审核通过的网站应用,并获取AppID和APPSecret,然后申请微信登陆并通过审核后,可以接入流程进行开发。据开发者资质认证处介绍:开发者资质认证通过后,微信开放平台帐号下的应用,将获得微信登录、智能接口、第三方平台开发等高级能力。所以在微信第三方授权登陆获取用户信息…

    2022年5月11日
    58

发表回复

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

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