限制指定機器IP訪問oracle資料庫

來源:互聯網
上載者:User

標籤: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
串連測試:
$ sqlplus wacos/[email protected]
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)

本文出自 “11300506” 部落格,請務必保留此出處http://11310506.blog.51cto.com/11300506/1971313

限制指定機器IP訪問oracle資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.