首页 > 系统相关 >Linux平台实现简单的IP白名单策略

Linux平台实现简单的IP白名单策略

时间:2023-02-21 22:34:17浏览次数:25  
标签:deny name IP xxx etc hosts Linux 白名单

/etc/hosts.allow/etc/hosts.deny的判定机制

  1. 读取/etc/hosts.allow文件,从上到下读取:
    • 如果守护程序-客户端对与文件中的第一行匹配,则授予访问权限;
    • 如果该行不匹配,则读取下一行并执行相同的检查;
    • 如果读取了所有行,但没有匹配,则从顶部开始读取/etc/hosts.deny文件;
  2. 从上到下读取/etc/hosts.deny文件:
    • 如果在hosts.deny文件中找到守护程序-客户端对匹配,则拒绝访问;
    • 如果在两个文件中都找不到守护程序-客户端对的规则,或者如果两个文件都不存在,则授予对服务的访问权限。

白名单的配置策略

根据判定机制,配置策略可以是:在hosts.allow中配置IP白名单(逗号隔开),在hosts.deny中配置禁用所有IP(ALL):

# /etc/hosts.allow: list of hosts that are allowed to access the system.
#                   See the manual pages hosts_access(5) and hosts_options(5).
#
# Example:    ALL: LOCAL @some_netgroup
#             ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
#
# If you're going to protect the portmapper use the name "rpcbind" for the
# daemon name. See rpcbind(8) and rpc.mountd(8) for further information.

ALL: IP地址白名单(xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx)
# /etc/hosts.deny: list of hosts that are _not_ allowed to access the system.
#                  See the manual pages hosts_access(5) and hosts_options(5).
#
# Example:    ALL: some.host.name, .some.domain
#             ALL EXCEPT in.fingerd: other.host.name, .other.domain
#
# If you're going to protect the portmapper use the name "rpcbind" for the
# daemon name. See rpcbind(8) and rpc.mountd(8) for further information.
#
# The PARANOID wildcard matches any host whose name does not match its
# address.
#
# You may wish to enable this to ensure any programs that don't
# validate looked up hostnames still leave understandable logs. In past
# versions of Debian this has been the default.
# ALL: PARANOID

ALL: ALL

或者使用EXCEPT命令仅配置hosts.deny

ALL: ALL EXCEPT IP地址白名单(xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx)

标签:deny,name,IP,xxx,etc,hosts,Linux,白名单
From: https://www.cnblogs.com/LexLuc/p/17142747.html

相关文章

  • Linux学习-DAY11
    7.2LVM逻辑卷管理器LVM是Linux系统用于对硬盘分区进行管理的一种机制,理论性较强,其创建初衷是为了解决硬盘设备在创建分区后不易修改分区大小的缺陷。尽管对传统的硬盘分区进......
  • Rocky Linux安装
    1.下载VirtualBox并安装https://www.virtualbox.org/wiki/Downloads2.下载RockyLinux选择Rocky-9.1-x86_64-dvd.iso镜像官网https://rockylinux.org/download......
  • 'CScript' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    当adroidstdio打开虚拟机时回报错误为标题时,是我们系统中的path路径缺少,仅需要使用如下方法。系统环境变量被修改了。恢复办法如下:我的电脑--属性--高级--环境变量--系统......
  • linux基本功系列之sudo命令实战
    #前言......
  • kube-vip使用
    exportVIP=""exportINTERFACE=""#KVVERSION=$(curl-sLhttps://api.github.com/repos/kube-vip/kube-vip/releases|jq-r".[0].name")exportKVVERSION=v0.5.6......
  • Best Buy 百思买DROP SHIP EDI业务测试场景
    百思买集团BestBuy是全球最大家用电器和电子产品零售集团,在大型家电专业店+连锁经营的基础上同时实施成本领先的战略。引入EDI技术成为其进一步优化其供应链管理体系,实现......
  • 深入理解JavaScript对象
    前言在JavaScript中,对象是一种非常常见的数据类型,几乎每个程序员都会在日常工作中频繁地使用对象。在本篇文章中,我们将深入了解JavaScript对象的一些基本概念和一些高......
  • 虚拟机固定ip配置
    #!/bin/bashaddr="10.1.1.81"gateway="10.1.1.2"dns="10.1.1.2"HOST_IF="$(iproute|grepdefault|head-n1|cut-d''-f5)"#网卡配置nmcliconnectionmodify......
  • Web安全入门与靶场实战(43)- 查看Linux版本
    脏牛漏洞是在Linux内核中存在的一个漏洞,具体原理是get_user_page内核函数在处理Copy-on-Write(简称COW)的过程中,可能产生竞态条件造成COW过程被破坏。这里我们不需要去理解......
  • Linux下的高性能轻量级Web服务器(二)
    2.使用I/O复用技术和线程池网络中有很多用户会尝试去connect()这个WebServer上正在listen的这个port,而监听到的这些连接会排队等待被accept()。由于用户连接请求是随机到......