`
purpen
  • 浏览: 785367 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Linux hosts.allow与hosts.deny文件设置

阅读更多

redhat as4常用应用之hosts.allow和hosts.deny

一、概述

这两个文件是tcpd服务器的配置文件,tcpd服务器可以控制外部IP对本机服务的访问。这两个配置文件的格式如下:

#服务进程名:主机列表:当规则匹配时可选的命令操作
server_name:hosts-list[:command]
/etc/hosts.allow控制可以访问本机的IP地址,/etc/hosts.deny控制禁止访问本机的IP。如果两个文件的配置有冲突,以/etc/hosts.deny为准。

/etc/hosts.allow和/etc/hosts.deny两个文件是控制远程访问设置的,通过他可以允许或者拒绝某个ip或者ip段的客户访问linux的某项服务。
比如SSH服务,我们通常只对管理员开放,那我们就可以禁用不必要的IP,而只开放管理员可能使用到的IP段。

二、配置

1、修改/etc/hosts.allow文件
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
sshd:210.13.218.*:allow
sshd:222.77.15.*:allow

all:218.24.129.110 #表示接受110这个ip的所有请求!

in.telnetd:140.116.44.0/255.255.255.0
in.telnetd:140.116.79.0/255.255.255.0
in.telnetd:140.116.141.99
in.telnetd:LOCAL
smbd:192.168.0.0/255.255.255.0 #允许192.168.0.网段的IP访问smbd服务

#sendmail:192.168.1.0/255.255.255.0
#pop3d:192.168.1.0/255.255.255.0
#swat:192.168.1.0/255.255.255.0
pptpd:all EXCEPT 192.168.0.0/255.255.255.0
httpd:all
vsftpd:all

以上写法表示允许210和222两个ip段连接sshd服务(这必然需要hosts.deny这个文件配合使用),当然:allow完全可以省略的。

ALL要害字匹配所有情况,EXCEPT匹配除了某些项之外的情况,PARANOID匹配你想控制的IP地址和它的域名不匹配时(域名伪装)的情况。

2、修改/etc/hosts.deny文件

#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
sshd:all:deny

in.telnet:ALL

ALL:ALL EXCEPT 192.168.0.1/255.255.255.0,192.168.1.21,\
202.10.5.0/255.255.255.0

注意看:sshd:all:deny表示拒绝了所有sshd远程连接。:deny可以省略。

3、启动服务
注意修改完后:
#service xinetd restart
才能让刚才的更改生效。

=======================================================

hosts.allow与hosts.deny
两个文件均在/etc/目录下
优先级为先检查hosts.deny,再检查hosts.allow,
后者设定可越过前者限制,

例如:
1.限制所有的ssh,
除非从218.64.87.0——127上来。
hosts.deny:
in.sshd:ALL
hosts.allow:
in.sshd:218.64.87.0/255.255.255.128

2.封掉218.64.87.0——127的telnet
hosts.deny
in.sshd:218.64.87.0/255.255.255.128

3.限制所有人的TCP连接,除非从218.64.87.0——127访问
hosts.deny
ALL:ALL
hosts.allow
ALL:218.64.87.0/255.255.255.128

4.限制218.64.87.0——127对所有服务的访问
hosts.deny
ALL:218.64.87.0/255.255.255.128

其中冒号前面是TCP daemon的服务进程名称,通常系统
进程在/etc/inetd.conf中指定,比如in.ftpd,in.telnetd,in.sshd

其中IP地址范围的写法有若干中,主要的三种是:
1.网络地址——子网掩码方式:
218.64.87.0/255.255.255.0
2.网络地址方式(我自己这样叫,呵呵)
218.64.(即以218.64打头的IP地址)
3.缩略子网掩码方式,既数一数二进制子网掩码前面有多少个“1”比如:
218.64.87.0/255.255.255.0《====》218.64.87.0/24

 

分享到:
评论

相关推荐

    操作系统安全:配置etchosts.allow及etchosts.deny.docx

    /etc/hosts.allow和/etc/hosts.deny两个文件是控制远程访问设置的,通过他可以允许或者拒绝某个ip或者ip段的客户访问linux的某项服务。 比如SSH服务,我们通常只对管理员开放,那我们就可以禁用不必要的IP,而只开放...

    操作系统安全:详解etc hosts.deny .docx

    /etc/hosts.allow和/etc/hosts.deny两个文件是控制远程访问设置的,通过他可以允许或者拒绝某个ip或者ip段的客户访问linux的某项服务。 比如SSH服务,我们通常只对管理员开放,那我们就可以禁用不必要的IP,而只开放...

    openssh 8.4版本的RPM包,支持hosts.allow的版本 openssh-server-8.4p1-1.el7.centos.x86_64.rpm

    openssh-server-8.4p1-1.el7.centos.x86_64.rpm源生的openssh的版本不支持tcpwraper

    linux详细目录架构

    /etc/hosts.allow 设置允许使用inetd的机器使用 /etc/hosts.deny 设置不允许使用inetd的机器使用 /etc/hosts.equiv 设置远端机不用密码 /etc/inetd.conf 设定系统网络守护进程inetd的配置 /etc/gateways ...

    linux常用命令

    /etc/hosts.allow 设置允许使用inetd的机器使用 /etc/hosts.deny 设置不允许使用inetd的机器使用 /etc/hosts.equiv 设置远端机不用密码 /etc/inetd.conf 设定系统网络守护进程inetd的配置 /etc/gateways 设定...

    TCPwrapper访问控制工具

    TCPwrapper访问控制工具 ...TCPwrappers会先查找/etc/hosts.allow,再查找/etc/hosts.deny,如果两个配置中有冲突,先匹配中的优先,也就是/etc/hosts.allow中的配置优先,如果两个配置都没命中,默认放

    openssh-8.4p1-1.el7.centos.x86_64.rpm

    openssh-8.4p1-1.el7.centos.x86_64.rpm以来的openssh包,源生的版本不支持hosts.allow,hosts.deny.

    Linux网络服务器配置基础(下)

    * /etc/hosts.allow 文件但是对于telnet、ftp等服务,如果将其一同关闭,那么对于管理员需要远程管理时,将非常不方便.Linux提供另外一种更为灵活和有效的方法来实现对服务请求用户的限制,从而可以在保证安全性的基础上...

    操作系统安全审计.doc

    1. RedHat Linux操作系统 RedHat Linux操作... " "查看hosts.allow和hosts.deny文件内容。 " "测试记录: " "已配置的日志: " " " " " " " "日志功能是否有效实施,日志记录的日期和内容是否与配置相符合: " " " "

    sshd 限制登陆的几种方法总结

    在 /etc/hosts.deny 写: sshd: ALL  2. 用 iptables 也行: iptables -I INPUT -p tcp --dport 22 -j DROP iptables -I INPUT -p tcp --dport 22 -s 1.2.3.4 -j ACCEPT 3. 禁止某个用户通过ssh登录 在/etc/ssh...

    超级服务器和telnet

    linux基本网络服务管理: 1、什么是守护进程(daemon) 2、超级服务器xinetd 3、xinetd举例:使用xinetd管理telnet 4、tcpd及其配置文件/etc/hosts.allow和/etc/hosts.deny

    sshban:控制您的 SSH 登录

    然后使用您的 /etc/hosts.deny 和 /etc/hosts.allow 来控制您的 SSHD。 在 /etc/hosts.deny 添加以下行 sshd: ALL 在 /etc/hosts.allow 添加以下行 sshd: ALL: aclexec /usr/local/bin/sshban.sh

    信息系统安全基线.docx

    配置/etc/hosts.allow, /etc/hosts.deny 安装TCP Wrapper,提高对系统访问控制 用户账号与口令 通过配置操作系统用户账号与口令安全策略,提高系统账号与口令安全性,详见表2。 表2 AIX系统用户账户与口令基线技术...

    Linux SSH 安全策略 限制 IP 登录方法

    vim /etc/hosts.deny 输入(表示除了上面允许的,其他的ip 都拒绝登陆ssh) sshd:ALL 最后sshd重启 service sshd restart  方法二: 比如说你只允许114.80.100.159这个IP进入,其它都禁止:   vim /etc/ssh/...

    限制ip访问Oracle数据库的方法步骤

    通过/etc/hosts.deny和/etc/hosts.allow 通过iptables 二、正式实验 本次实验环境是Centos6.10 + Oracle 11.2.0.4单实例,数据库服务器ip地址为192.168.31.71 1. 通过sqlnet.ora a. 关闭数据库服务器上的防火墙,...

    pro_apache_third_edition..pdf

    Contents About the Author...............................................................................................xix About the Technical Reviewer and Contributing Author.................xxi ...

    RED HAT LINUX 6大全

    10.1 Linux与新闻组 186 10.1.1 新闻供给点如何工作 187 10.1.2 推/拉新闻 187 10.1.3 下载新闻组的可选方法 187 10.2 INN硬件与软件要求 188 10.3 INN介绍 188 10.3.1 安装INN 188 10.3.2 INN启动文件 189 10.3.3 ...

    Centos中TCPWrappers访问控制实现

    一、TCP Wrappers概述 TCP Wrappers将TCP服务程序“包裹”起来,代为监听TCP服务程序的端口,增加了一个...对应的两个策略文件为/etc/hosts.allow和/etc/hosts.deny,分别用来设置允许和拒绝的策略。 1、策略的配置

    linux目录架构

    /etc/hosts 设定用户自已的IP与名字的对应表 /etc/hosts.allow 设置允许使用inetd的机器使用 /etc/hosts.deny 设置不允许使用inetd的机器使用 /etc/hosts.equiv 设置远端机不用密码 /etc/...

Global site tag (gtag.js) - Google Analytics