IP黑白名单

防攻击可以增加IP白名单/etc/hosts.allow和黑名单/etc/hosts.deny

/etc/hosts.allow  IP白名单

/etc/hosts.deny   IP黑名单

   /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:21.13.21.*:allow

    sshd:21.71.15.*:allow

      #*表示所有的,allow可以省略。

    all:21.21.11.11   all表示接受这个ip的所有请求,ssh:只是开放了ssh连接

     smbd:192.168.0.0/255.255.255.0 #允许192.168.0.网段的IP访问smbd服务

/etc/hosts.deny此文件是拒绝服务列表,文件配置同上

修改配置以后重启生效:

service sshd  restart
service  xinetd  restart

 

注意:

1./etc/hosts.allow(允许)和/etc/hosts.deny(禁止)这两个文件是tcpd服务器的配置文件,tcpd服务器可以控制外部IP对本机服务的访问

2.一个IP请求连入,linux 系统会先检查/etc/hosts.deny规则,再检查/etc/hosts.allow规则,如果有冲突 按/etc/hosts.allow规则处理

3.实验发现对/etc/hosts.allow和/etc/hosts.deny的配置不用重启就立即生效,但不管重启不重启当前已有会话都不会受影响;也就是说对之前已经连入的,即便IP已配置为禁止登录会话仍不会强制断开。不过不知是否所有linux都一样

4.有些教程写成in.sshd和in.telnetd,这里独立启的不用加in,托管于xinetd的需要加in.

5.通过这种方法可以控制部分非授权访问,但不是一劳永逸的方法!我们在看服务日志的时候或许会看到很多扫描记录,不是还是直接针对root用户的,这时控制你的访问列表就非常有作用了!

猜你喜欢

转载自www.cnblogs.com/byfboke/p/9155518.html