一、背景简介 在linux上多用iptables来限制ssh和telnet,编缉hosts.allow和hosts.deny感觉比较麻烦比较少用。 aix没有iptables且和linux有诸多不同,多种因素导致默认hosts.allow和hosts.deny在aix也是没用。 确实没人说过aix不能用hosts.allow和hosts.deny限制ssh,只是自己习惯性认为。 aix上能用hosts.allow,又追究起以前想过的问题:hosts.allow能支持哪些服务? (据说其实aix有类似iptables的东西的,只是我不会用大部份人应该也都不会用) 二、hosts.allow和hosts.deny支持哪些服务 2.1 hosts.allow和hosts.deny支持哪些服务 也就是说:hosts.allow和hosts.deny支持且只支持使用了libwrap库的服务。
文件没有添加相应的规则,于是查询hosts.allow文件,对比之前的正确测试环境,发现目前在建的这套环境里面没有配置相关的hosts.allow网段,重新配置之后,问题解决。 这里,看到了hosts.allow和hosts.deny这两个文件,于是研究了一下这两个文件的差别。 2hosts.allow和hosts.deny hosts.allow和hosts.deny是linux系统/etc/目录中的两个文件,hosts.allow和hosts.deny规则的执行者为TCP 简单看下hosts.allow中的内容,大致如下: # # hosts.allow This file describes the names of the hosts which are # allowed 上面的规则都需要根据两个文件进行规则匹配,根据规则的灵活性,我们也可以只用一个文件,通常是 hosts.allow 来包含 所有规则,在那些需要拒绝的ip后面跟上deny选项即可。
1、登录主机,如果是普通账户先切换至root账号 su root 2、编缉/etc/hosts.allow文件 vi /etc/hosts.allow 允许内容 书写格式(改成自自需要的IP或IP段) 以ssh允许192.168.220.1和telnet允许192.168.220网段为例,具体在/etc/hosts.allow加入内容如下: ? 说明: 1.一个IP请求连入,linux的检查策略是先看/etc/hosts.allow中是否允许,如果允许直接放行;如果没有,则再看/etc/hosts.deny中是否禁止,如果禁止那么就禁止连入。 2.实验发现对/etc/hosts.allow和/etc/hosts.deny的配置不用重启就立即生效,但不管重启不重启当前已有会话都不会受影响;也就是说对之前已经连入的,即便IP已配置为禁止登录会话仍不会强制断开
如果当iptables、hosts.allow和hosts.deny三者都设置时或设置出现冲突时,遵循的优先级是hosts.allow > hosts.deny >iptables 下面来看一下几个限制本地服务器登陆的设置 : 1)iptables和hosts.allow设置一致,hosts.deny不设置。 如果出现冲突,以hosts.allow设置为主。 [root@localhost ~]# cat /etc/sysconfig/iptables ..... 设置里,那么它是允许登陆本地服务器的; 也就是说hosts.allow里设置的ip都可以登陆本地服务器,hosts.allow里没有设置而iptables里设置的ip不能登陆本地服务器; 所以,只要hosts.allow 、hosts.deny三者都设置时,遵循的hosts.allow!
防攻击可以增加IP白名单/etc/hosts.allow和黑名单/etc/hosts.deny 配置文件格式参考: 修改/etc/hosts.allow文件 # # hosts.allow This 所以:当hosts.allow和 host.deny相冲突时,以hosts.allow设置为准。 /etc/hosts.allow(允许)和/etc/hosts.deny(禁止)这两个文件是tcpd服务器的配置文件 tcpd服务器可以控制外部IP对本机服务的访问 linux 系统会先检查/etc /hosts.deny规则,再检查/etc/hosts.allow规则,如果有冲突 按/etc/hosts.allow规则处理 比如: 1.禁止所有ip访问linux 的ssh功能 可以在/etc/ 禁止某一个ip(192.168.11.112)访问ssh功能 可以在/etc/hosts.deny添加一行sshd:192.168.11.112 3.如果在/etc/hosts.deny和/etc/hosts.allow
zhangsan、aliyun 帐户通过 SSH 登录系统 限制 IP SSH 登录 ---- 除了可以禁止某个用户登录,我们还可以针对固定的IP进行禁止登录,linux 服务器通过设置 /etc/hosts.allow 和 /etc/hosts.deny这个两个文件, hosts.allow许可大于hosts.deny可以限制或者允许某个或者某段IP地址远程 SSH 登录服务器.方法比较简单,具体如下: 1. vim /etc/hosts.allow, 添加 sshd:192.168.0.1:allow #允许 192.168.0.1 这个 IP 地址 ssh 登录 sshd:192.168.0.1/24:allow #允许 192.168.0.1/24 这段 IP 地址的用户登录 2.vim /etc/hosts.allow,添加 sshd:ALL # 允许全部的 ssh 登录 ? hosts.allow 和hosts.deny 两个文件同时设置规则的时候,hosts.allow 文件中的规则优先级高,按照此方法设置后服务器只允许 192.168.0.1 这个 IP 地址的 ssh
配置文件:/etc/hosts.allow,/etc/hosts.deny 但是并非所有服务都能接受tcp_wrapper的控制,事实上,tcp_wrapper与其说是一个服务,不如说是一个库更合适。 三、使用tcp_wrapper控制 a).只需将受控制程序名写入配置文件即可实现控制: 允许访问:/etc/hosts.allow 拒绝访问:/etc/hosts.deny b).控制原理 程序链接的库文件 ,会自动在用户访问服务时,基于tcpd检测 /etc/hosts.allow、/etc/hosts.deny两个配置文件,并判断某一主机是否能够访问服务。 c).匹配机制 1.先检查/etc/hosts.allow,如果被允许,则直接放行; 2.如果/etc/hosts.allow没有匹配项,则检查/etc/hosts.deny;如果有匹配项则禁止访问; EXCEPT 172.16.251.105 f).事例 如果我们要定义仅放行某一网段,则定义/etc/hosts.allow放行网段,在/etc/hosts.deny定义拒绝所有主机。
系统账户 # 拒绝 aliyun 帐户通过 SSH 登录系统限制 IP SSH 登录除了可以禁止某个用户登录,我们还可以针对固定的IP进行禁止登录,linux 服务器通过设置 /etc/hosts.allow 和 /etc/hosts.deny 这个两个文件,hosts.allow许可大于hosts.deny可以限制或者允许某个或者某段IP地址远程 SSH 登录服务器.方法比较简单,具体如下:vim /etc /hosts.allow, 添加sshd:192.168.0.1:allow #允许 192.168.0.1 这个 IP 地址 ssh 登录sshd:192.168.0.1/24:allow #允许 192.168.0.1/24 这段 IP 地址的用户登录vim /etc/hosts.allow,添加sshd:ALL # 允许全部的 ssh 登录 hosts.allow 和hosts.deny 两个文件同时设置规则的时候,hosts.allow 文件中的规则优先级高,按照此方法设置后服务器只允许 192.168.0.1 这个 IP 地址的 ssh 登录,其它的 IP 都会拒绝
linux设置允许和禁止访问的IP host.allow 和 host.deny 对于能过xinetd程序启动的网络服务,比如ftp telnet,我们就可以修改/etc/hosts.allow和/etc 比如我们在 /etc/hosts.allow中加入 all:218.24.129. 这样就会允许来自218.24.129.*域的所有的客户来访问。 当hosts.allow和 host.deny相冲突时,以hosts.allow设置优化。 不是任何服务程序都能使用TCP_wrappers的,例如使用命令ldd /usr/sbin/sshd,如果输出中有libwrap,则说明可以使用TCP_wrappers, 即该服务可以使用/etc/hosts.allow
四、实验原理TCP Wrappers是通过/etc/hosts.allow和/etc/hosts.deny这两个配置文件来实现一个类似防火墙的机制。 当有请求从远程到达本机的时候首先检查/etc/hosts.allow如有匹配的,就默认允许访问,跳过 /etc/hosts.deny这个文件没有匹配的,就去匹配/etc/hosts.deny 文件,如果有匹配的 在服务端(登录账号:root,密码:123456)命令行中输入命令:vi /etc/hosts.allow,打开配置文件hosts.allow,如下图所示:4、打开后进入编辑模式,编辑打开的hosts.allow 在服务端命令行中输入命令:vi /etc/hosts.allow,打开配置文件hosts.allow,修改hosts.allow文件,在末尾添加如下命令:“in.telnetd:192.168.”修改完成后保存 输入命令:vi /etc/hosts.allow,打开hosts.allow文件,进入编辑模式,在末尾添加保存一条命令:in.telnetd: 192.168.EXCEPT192.168.100.101
------ 方法2 ---------# # 配置文件 /etc/hosts 可以有效阻挡暴力破解攻击 sed -i "1 a sshd:183.230.102.102:allow" /etc/hosts.allow # 多个IP就插入多行 # hosts.deny 是拒绝IP hosts.allow和hosts.deny 两个文件同时设置规则的时候,hosts.allow文件中的规则优先级高
编辑/etc/hosts.allow配置文件 vi /etc/hosts.allow sshd:ALL:allow #表示允许所有ip连接 sshd:192.168.3.2:allow #仅允许此IP连接 *:allow #允许.3网段的所有IP连接 再配合/etc/hosts.deny配置文件 vi /etc/hosts.deny sshd:ALL:deny 以上配置表示除了hosts.allow中配置的地址可以连接
这部分设置共涉计到两个文件:hosts.allow和 hosts.deny。 将那些明确允许的请求添加到/etc/hosts.allow中。 如对除了在hosts.allow列表中明确允许使用sshd的用户外,所有其他用户都禁 止使用sshd服务,则添加如下内容到hosts.deny文件中: sshd:All 注意:系统对上述两个文件的判断顺序是先检查 hosts.allow文件再查看hosts.deny文件,因此一个用户在hosts.allow允许使用 网络资源,而同时在hosts.deny中禁止使用该网络资源,在这种情况下系统优先选择使用hosts.allow
TCP包装器依赖于两个文件才能工作:/etc/hosts.allow和/etc/hosts.deny。如果这些文件尚不存在,请创建它们: touch /etc/hosts. {allow,deny} 编辑hosts.allow和hosts.deny 您可以使用任何您喜欢的文本编辑器编辑hosts.allow和hosts.deny。 # # The rules in this file can also be set up in # /etc/hosts.allow with a 'deny' option 允许例外 在规则的hosts.allow文件中有比规定更高的优先级hosts.deny的文件。这允许我们使用hosts.allow文件为我们的拒绝规则创建例外。 在首选文本编辑器中打开hosts.allow。 在您的hosts.allow文件中,您可以添加例外。找到您要允许的IP,即您自己的IP地址或其他服务器的IP地址。 选择允许IP地址访问的服务。
一、概述 本文将给大家介绍如何限制某个ip或某个ip段才能访问Oracle数据库 通过sqlnet.ora 通过/etc/hosts.deny和/etc/hosts.allow 通过iptables 为了避免这种情况,这时就需要通过/etc/hosts.allow和/etc/hosts.deny去限制某个ip或者ip段才能ssh访问数据库服务器 先删除前面实验添加的sqlnet.ora,然后重启监听 修改/etc/hosts.allow 在前面一步中我禁掉所有的网段,所以在这一步中要开通指定的网段。 修改/etc/hosts.allow,在文件尾部添加 all:192.168.31.71:allow all:192.168.31.47:allow 格式与hosts.deny一样,第一行表示把本机放开 连数据库却不受影响,因为数据库服务不归hosts.deny和hosts.allow管 [oracle@oracle19c1 ~]$ sqlplus sys/xxxxx@192.168.31.71:1521
一、CentOS上的SSH设置 1.1 终端窗口下,以root身份登录,修改hosts.allow,允许用户远程连接 vi /etc/hosts.allow 按 i 键切换到 insert模式,在最后一行加一句 sshd:ALL 然后按ESC返回命令模式,然后再按:进行末行模式,最后输入x 保存退出(注:如果保存时,提示文件只读,可以尝试 chmod +w hosts.allow 赋于写权限),可以用 tail /etc/hosts.allow 查看验证下文件内容是否正确 1.2 重启sshd /etc/rc.d/init.d/sshd restart 重启完成后,应该就允许远程连接了 二、mac 机上 ssh
在使用TCP Wrappers保护网络服务时应该考虑以下几个要点: A.因为hosts.allow中的规则会首先被应用,所以比hosts.deny中指定的规则有优先权.因此,如果访问一项服务在 hosts.allow中设置为允许,那么在hosts.deny中同一项服务的拒绝访问设置则被忽略. D.TCP会绕的服务并不缓存主机访问文件中的规则,因此对hosts.allow或hosts.deny的配置改变都无需重新启动网络服务便会马上起作用. 2.格式化访问规则 /etc/hosts.allow cracker.example.com hosts.allow文件内的另一个例子中,来自192.168.0.x网络的所有客户都可以使用除FTP之外的所有服务 ALL EXCEPT ALLOW/DENY: 可以在/etc/hosts.deny或/etc/hosts.allow 中被当做一个选项来使用。
在Linux云服务器中分别通过配置/etc/hosts.allow和/etc/hosts.deny这两个文件,拒绝或者允许指定的IP及IP地址段通过SSH远程登录云服务器 编辑/etc/hosts.allow 191.168.2.1/24这个IP地址段通过SSH登录 编辑/etc/hosts.deny文件,添加类似如下的内容,拒绝所有IP地址通过SSH登录 sshd:ALL # 拒绝全部的SSH登录 同时设置上述两个文件时,hosts.allow
config (图片可放大查看) 接下来进行正题 三、CentOS Stream 9通过配置sshd_config中AllowUsers实现SSH访问控制 1、CentOS Stream 9默认无/etc/hosts.allow 在CentOS Stream 9系统中 ll /etc/hosts.allow ldd /usr/sbin/sshd 可以发现无libwrap.so.0库文件 (图片可放大查看) 系统中没有/etc /hosts.allow 和/etc/hosts.deny 文件 对比CentOS7系统 具体参考如下两篇文章 利用tcp_wrapper实现SSH登录的IP访问控制 细谈企业网络安全中堡垒机绕过问题 这样就可以实现SSH访问控制 当注释掉AllowUsers这一行,重启sshd服务,就可以正常登录 (图片可放大查看) (图片可放大查看) Tips: CentOS Linux 8以后就不再支持/etc/hosts.allow
i eth0 -p UDP -s 140.0.0.0/8 --dport 111 -j ACCEPT 3、为了防止可能的 Dos 攻击,需要合理设定 NFSD 的 COPY 数目. 4、修改/etc/hosts.allow 和/etc /hosts.deny 达到限制 CLIENT 的目的 /etc/hosts.allow portmap: 192.168.0.0/255.255.255.0 : allow NFS 端口 NFS 默认使用的是 111 端口,但同时你也可以使用 port 参数来改变这个端口,这样就可以在一定程度上增强安全性. 6、使用 Kerberos V5 作为登陆验证系统 修改/etc/hosts.allow 和/etc/hosts.deny 达到限制 CLIENT 的目的 /etc/hosts.allow portmap: 192.168.0.0/255.255.255.0 : allow portmap