一、概述

这两个文件是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:denyin.telnet:ALLALL: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

Linux hosts.allow与hosts.deny文件设置相关推荐

  1. linux hosts的allow和deny

    linux hosts的allow和deny /etc/hosts.allow和/etc/hosts.deny两个文件是控制远程访问设置的,通过他可以允许或者拒绝某个ip或者ip段的客户访问linux ...

  2. 【转】Linux操作系统下/etc/hosts文件配置方法

    原文链接 http://my.oschina.net/liting/blog/387544 1.关于/etc/host,主机名和IP配置文件 Hosts - The static table look ...

  3. 通过配置hosts.allow和hosts.deny文件允许或禁止ssh或telnet操作

    1.登录主机,如果是普通账户先切换至root账号 su root 2.编缉/etc/hosts.allow文件 vi /etc/hosts.allow 允许内容 书写格式(改成自自需要的IP或IP段) ...

  4. Linux操作系统下/etc/hosts文件

    1. 关于/etc/host,主机名和IP配置文件 Hosts - The static table lookup for host name(主机名查询静态表) Linux 的/etc/hosts是 ...

  5. Linux hostname主机名配置文件与文件 /etc/hosts解说

    Linux hostname经过长时间的发展,这里我发表一下个人理解,下面就这就来讲术Linux hostname.今天又开始写网络文档了,先写一篇小一点的练练手,本来计划了一篇比较大的网络基础文档, ...

  6. Linux操作系统下/etc/hosts文件配置方法(域名映射)

    文章目录 hosts文件 hosts格式配置 hosts文件 hosts -- the static table lookup for host name(主机名查询静态表). hosts文件是Lin ...

  7. linux文件目录:/etc/hosts文件详解

    这里的/etc/hosts作用同Windows下的hosts文件,Windows中host文件的目录一般为:C:\Windows\System32\drivers\etc\hosts. 一.概念 ho ...

  8. 【TCP wrappers】关于/etc/hosts.allow /etc/hosts.deny

    一.关于/etc/hosts.allow  /etc/hosts.deny 遇到一台服务器22端口正常,可是用SSH连接却有问题. 报错:ssh_exchange_identification: re ...

  9. hosts.allow和hosts.deny

    对于能过xinetd程序启动的网络服务,比如ftp telnet,我们就可以修改/etc/hosts.allow和/etc/hosts.deny的配制,来许可或者拒绝哪些IP.主机.用户可以访问 比如 ...

最新文章

  1. Hihocoder 1370 快乐数字
  2. pycharm中如何正确配置pyqt5
  3. 软件设计师 - 常用公式
  4. 大四课程设计之基于RFID技术的考勤管理系统(三)数据库设计
  5. android中常见的错误及解决办法
  6. php 明天凌晨,用php判断时间戳来输出刚刚,分钟前,小时前昨天和时间
  7. 单例模式 代码以及祥解
  8. ffmpeg 编译成功,Mark一下
  9. android 获取屏幕像素为 1920x1016的原因
  10. Ruby module里的self
  11. Category为什么会覆盖原来类中的方法?
  12. 折腾凤凰系统 (by quqi99)
  13. UT(XCAP) 参数说明
  14. 【MIKE21】mesh导入文件
  15. 无线网络优化(家用无线网)
  16. 新手建站之【网站备案】③
  17. LaTex常用技巧7:常用网站(公式和表格编辑器)
  18. 超级账本执行董事:区块链将削弱谷歌、亚马逊和Facebook的市场力量
  19. 服务器数据存储在哪个位置,数据存储在云服务器什么地方
  20. Python安装包时遇到There was a problem confirming the ssl certificate…的解决办法

热门文章

  1. IasS,CasS,PasS,SasS的区别
  2. linux下top指令参数详解及用法
  3. 生物统计学(biostatistics)学习笔记(一)
  4. PWM互补脉冲配置,互补输出异常
  5. 【高级篇 / System】(7.0) ❀ 07. HA 下配置核心交换机 (下) ❀ FortiGate 防火墙
  6. NameNode故障处理方法
  7. 浮点数的表示及范围 IEEE754
  8. Mysql技术-innodb引擎-笔记
  9. 程序员的工资高,到底程序员的工资有多高?你不了解的程序员!
  10. 数据库事务(Transaction)与锁(Locking)详解图析