今天遇到一台服务器22端口正常,但是通过ssh连接的问题。排查了防火墙和端口问题,半天没有找出来原因,后来求助大神,终于明白了通过etc目录下hosts.deny和hosts.allow文件可以限制远程访问,使用方法如下:

修改/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
以上写法表示允许210和222两个ip段连接sshd服务(这必然需要hosts.deny这个文件配合使用),当然:allow完全可以省略的。
当然如果管理员集中在一个IP那么这样写是比较省事的
all:218.24.129.110//他表示接受110这个ip的所有请求!

/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
注意看:sshd:all:deny表示拒绝了所有sshd远程连接。:deny可以省略。
所以:当hosts.allow和 host.deny相冲突时,以hosts.allow设置为准。

注意修改完后:
service network restart
重启网络服务才能让刚才的更改生效

配置优先级:
linux 系统会先检查/etc/hosts.deny规则,再检查/etc/hosts.allow规则,如果有冲突 按/etc/hosts.allow规则处理

/etc/hosts.allow和/etc/hosts.deny详解的更多相关文章

  1. 【转】Apache的Order Allow,Deny 详解

    Apache的Order Allow,Deny 详解   Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等 ...

  2. 转-Apache的Order Allow,Deny 详解

    Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权. 所以,最常用的是:Or ...

  3. Apache的Order Allow,Deny 详解

    Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权. 所以,最常用的是: O ...

  4. Apache的Order Allow,Deny详解

    Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权. 所以,最常用的是: O ...

  5. 访问Storm ui界面,出现org.apache.storm.utils.NimbusLeaderNotFoundException: Could not find leader nimbus from seed hosts ["master"]. Did you specify a valid list of nimbus hosts for confi的问题解决(图文详解)

    不多说,直接上干货! 前期博客 apache-storm-0.9.6.tar.gz的集群搭建(3节点)(图文详解) apache-storm-1.0.2.tar.gz的集群搭建(3节点)(图文详解)( ...

  6. 访问Storm ui界面,出现org.apache.storm.utils.NimbusLeaderNotFoundException: Could not find leader nimbus from seed hosts ["master" "slave1"]. Did you specify a valid list of nimbus hosts for confi的问题解决(图文详解)

    不多说,直接上干货! 前期博客 apache-storm-1.0.2.tar.gz的集群搭建(3节点)(图文详解)(非HA和HA)  问题详情 org.apache.storm.utils.Nimbu ...

  7. Linux 限制IP——/etc/hosts.allow和/etc/hosts.deny文件【转】

    就像是 限制特定IP来访 想法 看起来通常的做法是利用hosts的拒绝设置,而它的设置是针对某一个具体的进程,具体的服务,在这里就是sshd了 看起来设置一个网段使用的是 x.x.x.0/24 后面加 ...

  8. linux环境下/etc/hosts文件详解

    linux环境下/etc/hosts文件详解 就没一个昵称能用关注 0.0632017.09.12 17:04:28字数 623阅读 27,096 介绍 hosts文件是linux系统中负责ip地址与 ...

  9. CentOS 6.3下Samba服务器的安装与配置方法(图文详解)

    这篇文章主要介绍了CentOS 6.3下Samba服务器的安装与配置方法(图文详解),需要的朋友可以参考下   一.简介  Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件, ...

随机推荐

  1. Python- sort()/sorted()

    Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列. sorted(iterable,key=None,revers ...

  2. 118th LeetCode Weekly Contest Powerful Integers

    Given two non-negative integers x and y, an integer is powerful if it is equal to x^i + y^j for some ...

  3. POJ - 1733 离散化 并查集

    题意:求问数列区间奇偶信息正确与否 和上一题一样(甚至弱化),加个离散就ok啦 #include<iostream> #include<algorithm> #include& ...

  4. HDU1286

    欧拉函数测试题 期末考试完了做下水题 更好的方法是phi[i]==i时就直接筛选,不改了 #include<bits/stdc++.h> using namespace std; cons ...

  5. vue filters过滤器的使用

    说的很详细 https://www.w3cplus.com/vue/how-to-create-filters-in-vuejs.html

  6. oracle 集群RAC搭建(四)--grid部署

    安装教程:

  7. python 爬虫系列09-异步斗图来一波

    斗图斗图,妈妈再也不怕我都不赢了 import requests from lxml import etree from urllib import request import os import ...

  8. STL:set用法总结

    一:介绍 set是STL的关联式容器,以红黑树(Red-Black Tree)作为底层数据结构.自动去重,保证每个元素唯一,并对数据进行排序. 命名空间为std,所属头文件为<set> 二 ...

  9. C++ Memory System Part2: 自定义new和delete

    在第一部分中,我们介绍了new / delete的具体用法和背后的实现细节,这次我们将构建我们自己的小型工具集,可以使用我们自定义的allocator类来创建任意类型的实例(或者实例数组),我们需要做 ...

  10. TerraBuilder创建地形之去除影像黑边,填充影像

    最近在Skyline项目中使用TerraBuilder创建地形,由于地形比较大,分块下载卫星影像,然后再TerraBuilder中合并,由于合并.图形等等问题,导致创建处理出来的地形中存在严重的缝隙和 ...