限制指定机器IP访问oracle数据库node

经过使用数据库服务器端的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……)sql

以后从新启动监听器便可数据库

须要注意的地方:

一、tcp.invited_nodes与tcp.excluded_nodes都存在,以tcp.invited_nodes为主

二、必定要许可或不要禁止服务器本机的IP地址,不然经过lsnrctl将不能启动或中止监听,由于该过程监听程序会经过本机的IP访问监听器,而该IP被禁止了,可是经过服务启动或关闭则不影响。

三、修改以后,必定要重起监听才能生效,而不须要从新启动数据库

四、任何平台均可以,可是只适用于TCP/IP协议

(2)第二种方法使用触发器实现

一、这个触发器实现了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)服务器