--==========================
-- 配置sqlnet.ora 限制IP訪問Oracle
--==========================
與防火牆類似的功能,Oracle 提供限制與允許特定的IP或主機名稱通過Oracle Net來訪問資料庫。這個功能由sqlnet.ora設定檔來實現。該檔案通常$ORACLE_HOME/network/admin/ 目錄下,與tnsnames.ora以及listener.ora位於同一路徑。用法也比較簡單。通過監聽器的限制,實現輕量級訪問限制,比在資料庫內部通過觸發器進行限制效率要高。
1. 實現方式
通過在sqlnet.ora檔案中增加下列記錄來實現
tcp.validnode_checking = yes
tcp.invited_nodes = (hostname1, hostname2,ip1,ip2)
tcp.excluded_nodes = (10.103.11.17,hostname1,hostname2)
當使用invited_nodes時,則所有沒有包含在invited_nodes值中的IP或主機將無法通過Oracel Net串連到資料庫。而如果使用
excluded_nodes時,除了excluded_nodes值中列出的IP和主機不可訪問之外,其餘的節點都可以訪問資料庫。通常情況下,更傾向於使
用excluded_nodes參數。
2. 注意事項
使用excluded_nodes與invited_nodes的一些特性
不支援萬用字元的使用(如hostname不能寫為svhs0*,IP地址不能寫為10.103.11.*)
excluded_nodes與invited_nodes為互斥方式,要麼使用前者,要麼使用後者
如果tcp.invited_nodes與tcp.excluded_nodes都存在,則tcp.invited_nodes優先
要將本地地址,或者Cluster群集其他節點的地址都加入到允許清單,否則監聽器可能無法啟動
修改之後,一定要重起監聽或reload才會生效,而不需要重新啟動資料庫
僅提供對TCP/IP協議的支援
3. 實戰演習
-->使用tnsping demo92,串連正常
C:\>tnsping demo92
TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 25-JUN-2011 18:55:39
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
d:\app\Robinson\Oracle_client\product\11.2.0\client_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.103.11.20
9)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = demo92)))
OK (0 msec)
-->查看設定檔
[oracle@test admin]$ more sqlnet.ora
# SQLNET.ORA Network Configuration File: /oracle/92/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
NAMES.DIRECTORY_PATH= (ONAMES, TNSNAMES, HOSTNAME)
#Added by Robinson
tcp.validnode_checking = yes
tcp.excluded_nodes = (10.103.11.17)
-->重新reload
[oracle@test admin]$ lsnrctl reload listener_demo92
LSNRCTL for Linux: Version 9.2.0.8.0 - Production on 26-JUN-2011 10:03:11
Copyright (c) 1991, 2006, Oracle Corporation. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
The command completed successfully
-->再次tnsping時,收到TNS-12547錯誤
C:\>tnsping demo92
TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 25-JUN-2011 19:01:21
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
d:\app\Robinson\Oracle_client\product\11.2.0\client_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.103.11.20
9)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = demo92)))
TNS-12547: TNS:lost contact
-->下面的示範中如果excluded_nodes與invited_nodes都存在,則invited_nodes優先,不再示範
[oracle@test admin]$ more sqlnet.ora
# SQLNET.ORA Network Configuration File: /oracle/92/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
NAMES.DIRECTORY_PATH= (ONAMES, TNSNAMES, HOSTNAME)
#Added by Robinson
tcp.validnode_checking = yes
tcp.excluded_nodes = (10.103.11.17)
tcp.invited_nodes = (10.103.11.17)