用ORACLE 监听白名单功能 限制特定IP访问数据库
发布时间:2018-09-06 00:00:00
限制指定机器IP访问oracle数据库 通过使用数据库服务器端的sqlnet.ora文件可以实现禁止指定IP主机访问数据库的功能,这对于提升数据库的安全性有很大的帮助,与此同时,这个技术为我们管理和约束数据库访问控制提供了有效的手段。 下面是实现这个目的的具体步骤仅供参考: 1.默认的服务器端sqlnet.ora文件的内容 # sqlnet.ora Network Configuration File: D:\Server\Oracle\Product\11.2.0\dbhome_1\network\admin\sqlnet.ora # Generated by Oracle configuration tools. # This file is actually generated by netca. But if customers choose to # install "Software Only", this file wont exist and without the native # authentication, they will not be able to connect to the database on NT. SQLNET.AUTHENTICATION_SERVICES= (NTS) NAMES.DIRECTORY_PATH= (TNSNAMES) 2.确认客户端的IP地址: C:\Documents and Settings\Administrator>ipconfig 3.在客户端分别使用tnsping命令和sqlplus命令来验证数据库的连通性: C:\Documents and Settings\Administrator>tnsping irmdb C:\Documents and Settings\Administrator>sqlplus /nolog 到这里说明在客户端两种方式都证明的数据库的可连通性。 4.限制客户端IP地址9.123.112.16对当前irmdb数据库的访问: 我们只需要在服务器端的sqlnet.ora文件中添加下面的内容即可。 # sqlnet.ora Network Configuration File: D:\Server\Oracle\Product\11.2.0\dbhome_1\network\admin\sqlnet.ora # Generated by Oracle configuration tools. # This file is actually generated by netca. But if customers choose to # install "Software Only", this file wont exist and without the native # authentication, they will not be able to connect to the database on NT. SQLNET.AUTHENTICATION_SERVICES= (NTS) NAMES.DIRECTORY_PATH= (TNSNAMES) tcp.validnode_checking=yes tcp.invited_nodes=(9.123.112.34) tcp.excluded_nodes=(9.123.112.16) 第一行的含义:开启IP限制功能; 第二行的含义:允许访问数据库的IP地址列表,多个IP地址使用逗号分开,此例中我们写入数据库服务器的IP地址; 第三行的含义:禁止访问数据库的IP地址列表,多个IP地址使用逗号分开,此处我们写入欲限制的IP地址9.123.112.16。 5.重新启服务器端listener后生效(这里也可以通过lsnrctl reload方式实现): C:\Documents and Settings\Administrator>lsnrctl stop 1)在9i中真正起作用的是sqlnet.ora文件,我们修改sqlnet.ora其实是最好最快的方法。 在soracle\product\10.2.0\db_1\network\ADMIN\qlnet.ora中增加如下部分 tcp.validnode_checking=yes #允许访问的IP tcp.invited_nodes=(ip1,ip2……) #禁止访问的IP tcp.excluded_nodes=(ip1,ip2……) 之后重新启动监听器即可 需要注意的地方: 1、tcp.invited_nodes与tcp.excluded_nodes都存在,以tcp.invited_nodes为主 2、一定要许可或不要禁止服务器本机的IP地址,否则通过lsnrctl将不能启动或停止监听,因为该过程监听程序会通过本机的IP访问监听器,而该IP被禁止了,但是通过服务启动或关闭则不影响。 3、修改之后,一定要重起监听才能生效,而不需要重新启动数据库 4、任何平台都可以,但是只适用于TCP/IP协议 (2)第二种方法使用触发器实现 1、这个触发器实现了192.168.137开始的IP不能访问test用户的功能 create or replace trigger chk_ip after logon on test.schema declare ipaddr VARCHAR2(30); begin select sys_context('userenv', 'ip_address') into ipaddr from dual; if ipaddr like ('192.168.137.%') then raise_application_error('-20001', 'you can not logon by test'); end if; end ; / 过对oracle9i参数文件的设置,可以控制访问计算机的ip地址。 在172.28.65.13这台机器上的配置文件$ORACLE_HOME/network/sqlnet.ora中增加: #开启对ip地址的检查 tcp.validnode_checking=yes #允许访问的ip tcp.invited_nodes=(172.28.65.13) #禁止访问的ip ip.excluded_nodes= (172.27.65.15) 重启监听! $ lsnrctl reload LSNRCTL for Solaris: Version 9.2.0.4.0 - Production on 14-DEC-2005 16:59:19 Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC0))) The command completed successfully. 在172.28.65.15这台机器上编辑$ORACLE_HOME/network/admin/tnsnames.ora文件: 此处可以添加新的服务(dsf): dsf = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(Host= 172.28.65.13)(Port = 1521)) (CONNECT_DATA = (SID = ORCL)) ) 在15上进行tnsping测试: $ tnsping dsf TNS Ping Utility for Solaris: Version 9.2.0.4.0 - Production on 14-DEC-2005 17:04:02 Copyright (c) 1997 Oracle Corporation. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(Host= 172.28.65.13)(Port = 1521)) (CONNECT_DATA = (SID = ORCL))) TNS-12537: TNS:connection closed 连接测试: SQL*Plus: Release 9.2.0.4.0 - Production on Wed Dec 14 17:04:24 2005 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. ERROR: ORA-12537: TNS:connection closed ------------------------------------------------------------------------------------------------------------------- TCP.VALIDNODE_CHECKING,这个参数必须设置,值也必须是YES,否则就是不启用 TCP.VALIDNODE_CHECKING=YES 白名单的设置参数,这个地址列表中必须包含本机的地址,不然监听可能要启动失败 TCP.INVITED_NODES=(10.10.2.100,10.10.2.101) 黑名单的设置参数: TCP.EXCLUDED_NODES=(10.10.1.100) |