zoukankan      html  css  js  c++  java
  • 服务器设置 白名单

    Linux服务器防火墙白名单设置

    登上服务器,编辑防火墙配置文件

      vi /etc/sysconfig/iptables

      把需要访问本台服务器的其他服务器ip地址,以及本台服务器需要开放的端口号添加上

      如下:

    # Firewall configuration written by system-config-firewall
    # Manual customization of this file is not recommended.
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    #这里开始增加白名单服务器ip(请删除当前服务器的ip地址)
    -N whitelist
    -A whitelist -s 192.168.111.xxx -j ACCEPT
    -A whitelist -s 192.168.111.xxx -j ACCEPT
    -A whitelist -s 192.168.111.xxx -j ACCEPT
    -A whitelist -s 192.168.111.xxx -j ACCEPT
    -A whitelist -s 192.168.111.xxx -j ACCEPT
    #这里结束白名单服务器ip
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 13020 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 1000:8000 -j ACCEPT  //开放1000到8000之间的所有端口
    //上面这些 ACCEPT 端口号,公网内网都可以访问
    
    //下面这些 whitelist 端口号,仅限服务器之间通过内网访问
    #这里添加为白名单ip开放的端口
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j whitelist
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 13009 -j whitelist
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 10080 -j whitelist
    #这结束为白名单ip开放的端口
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    
    COMMIT

    编辑完之后,别忘了重启防火墙

      service iptables restart

    黑名单、白名单配置/etc/hosts.allow和/etc/hosts.deny

    修改/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完全可以省略的。www.111cn.net
    当然如果管理员集中在一个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设置为准。
    注意修改完后:www.111Cn.net
    service xinetd restart
    才能让刚才的更改生效。
    /etc/hosts.allow(允许)和/etc/hosts.deny(禁止)这两个文件是tcpd服务器的配置文件
    tcpd服务器可以控制外部IP对本机服务的访问
    linux 系统会先检查/etc/hosts.deny规则,再检查/etc/hosts.allow规则,如果有冲突 按/etc/hosts.allow规则处理

    比如:
    1.禁止所有ip访问linux 的ssh功能
    可以在/etc/hosts.deny添加一行 sshd:all:deny

    2.禁止某一个ip(192.168.11.112)访问ssh功能
    可以在/etc/hosts.deny添加一行sshd:192.168.11.112

    3.如果在/etc/hosts.deny和/etc/hosts.allow同时 有sshd:192.168.11.112 规则,则192.168.11.112可以访问主机的ssh服务
    总结:通过这种方法可以控制部分非授权访问,但不是一劳永逸的方法!我们在看服务日志的时候或许会看到很多扫描记录,不是还是直接针对root用户的,这时控制你的访问列表就非常有作用了!

    ORACLE数据库黑/白名单(配置文件、命令开关)

    编辑sqlnet.ora文件

    #开启ip限制功能
    tcp.validnode_checking=yes
    #允许访问数据库的IP地址列表,多个IP地址使用逗号分开
    tcp.invited_nodes=(10.120.84.59,10.120.84.54,10.120.84.58)
    #禁止访问数据库的IP地址列表,多个IP地址使用逗号分开
    tcp.excluded_nodes=(192.168.1.111)

    注:

    1、 需要重启监听器生效。
    2、 这个方式只是适合TCP协议,适用于9i以上版本。在9i之前的版本使用文件protocol.ora。
    3、第二行和第三行任写一行即可,如果tcp.invited_nodes与tcp.excluded_nodes都存在,以tcp.invited_nodes为主。
    4、不要禁止服务器本机的IP地址,否则通过lsnrctl将不能启动或停止监听,因为该过程监听程序会通过本机的IP访问监听器。

    可以通过修改sqlnet.ora文件来限制某些IP地址的访问,修改完成后,可能需重启监听生效。(可以lsnrctl reload)
    如果$ORACLE_HOME/network/admin/目录下没有sqlnet.ora文件,可以从samples目录下拷贝个sqlnet.ora或者直接vi
    ###########二选一##############
    #允许访问的IP
    TCP.INVITED_NODES=(192.168.1.103,ip2,ip3,..,..本地IP..)若使用白名单,必须本地IP,否则监听会起不来
    #不允许访问的IP
    TCP.EXCLUDED_NODES=(192.168.1.102)
    #检测上述参数的设置
    TCP.VALIDNODE_CHECKING=yes (这个参数是必须的)

    #允许访问的ip tcp.invited_nodes =(ip1,ip2,……) #不允许访问的ip tcp.excluded_nodes=(ip1,ip2,……)
    TCP.INVITED_NODES:设置允许访问数据库的IP地址列表,当这个参数和TCP.EXCLUDED_NODES设置的地址相同的时候将覆盖TCP.EXCLUDED_NODES设置。

    当不允许访问的客户端连入时,会出现下列错误
    sys/oracle@approd.test as sysdba
    ERROR:
    ORA-12537: TNS:connection closed


    Warning: You are no longer connected to ORACLE.


    需要注意的问题:
    1、 需要设置参数为YES,这样才能激活。
    2、 建议设置允许访问的IP,因为IP地址有可能被随意修改,就不能起到自己的目的。
    3、 TCP当参数TCP.INVITED_NODES和TCP.EXCLUDED_NODES设置的地址相同的时候将覆盖TCP.EXCLUDED_NODES设置。
    4、 需要重启监听器才能生效。
    5、 这个方式只是适合TCP协议。
    6、 这个配置适用于9i以上版本。在9i之前的版本使用文件protocol.ora。
    7、 在服务器上直接连接数据库不受影响。
    8、 这种限制方式事通过监听器来限制的。
     9、 这个限制只是针对IP检测,对于用户名检测事不支持的。
    10、使用触发器(通过监听器的限制,通常属于轻量级的,比在数据库内部通过触发器进行限制效率要高)

     

    参考文章

  • 相关阅读:
    揺する、揺らす、揺さぶる区別
    test
    W5N1のW2D2
    微软企业库6的使用方法
    Delphi XE6 原生解析json
    delphi URL 编码的转换
    Go语言配置与开发环境配置
    Win7 IIS下启用ASP.NET
    Windows2003远程桌面单会话登录
    IIS7应用程序池集成和经典的区别
  • 原文地址:https://www.cnblogs.com/klb561/p/10924308.html
Copyright © 2011-2022 走看看