自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

3種方式限制IP訪問Oracle數(shù)據(jù)庫

數(shù)據(jù)庫 Oracle
分享3種限制某個ip或某個ip段訪問Oracle數(shù)據(jù)庫的方式,希望對大家有幫助。

 

 

[[340416]]

 

01概述

本文將給大家介紹如何限制某個ip或某個ip段才能訪問Oracle數(shù)據(jù)庫

  1. 通過sqlnet.ora
  2. 通過/etc/hosts.deny和/etc/hosts.allow
  3. 通過iptables

 

02正式實驗

本次實驗環(huán)境是Centos6.10 + Oracle 11.2.0.4單實例,數(shù)據(jù)庫服務(wù)器ip地址為192.168.31.71

1. 通過sqlnet.ora

a. 關(guān)閉數(shù)據(jù)庫服務(wù)器上的防火墻,修改sqlnet.ora文件該文件放在$ORACLE_HOME/network/admin下,如果沒有就在該目錄下創(chuàng)建一個即可添加以下兩行

 

  1. tcp.validnode_checking = yes  
  2. tcp.invited_nodes = (192.168.31.71, 192.168.31.77) 

 

這里需要注意的是必須把本機(jī)ip地址加進(jìn)來(不能寫成localhost和127.0.0.1),否則監(jiān)聽啟動會報錯。

b. 重啟監(jiān)聽,讓sqlnet.ora的修改生效

 

  1. lsnrctl stop  
  2. lsnrctl start 

 

設(shè)置之后就只有這兩個ip地址192.168.31.71, 192.168.31.77能訪問數(shù)據(jù)庫,其它ip地址訪問會報ORA-12547: TNS:lost contact錯誤

tcp.invited_nodes的意思是開通白名單,不在白名單中的一律拒絕訪問,它也可以寫成(192.168.31.*, 192.168.31.0/24)等方式,表明這個網(wǎng)段都能訪問。

另外還有個參數(shù)tcp.excluded_nodes,表示黑名單,這里不做介紹,有興趣的可以自己去做做實驗。

2. 通過/etc/hosts.deny和/etc/hosts.allow

sqlnet.ora屬于數(shù)據(jù)庫層面的限制,但如果一個ip能夠使用root或者oracle,ssh到這臺數(shù)據(jù)庫服務(wù)器的話,那么它依然能夠訪問數(shù)據(jù)庫。為了避免這種情況,這時就需要通過/etc/hosts.allow和/etc/hosts.deny去限制某個ip或者ip段才能ssh訪問數(shù)據(jù)庫服務(wù)器先刪除前面實驗添加的sqlnet.ora,然后重啟監(jiān)聽

 

  1. lsnrctl stop
  2. lsnrctl start 

a. 修改/etc/hosts.deny

在文件尾部添加一行

 

  1. all:all:deny 

第一個all表示禁掉所有使用tcp_wrappers庫的服務(wù),舉例來說就是ssh,telnet等服務(wù)。

第二個all表示所有網(wǎng)段。

b. 修改/etc/hosts.allow

在前面一步中我禁掉所有的網(wǎng)段,所以在這一步中要開通指定的網(wǎng)段。

修改/etc/hosts.allow,在文件尾部添加

 

  1. all:192.168.31.71:allow 
  2. all:192.168.31.47:allow 

格式與hosts.deny一樣,第一行表示把本機(jī)放開,第二行表示給.47開通白名單

下面用我另外一臺機(jī)器(即不在allow中的)ssh或telnet連接71這個機(jī)器,就會出現(xiàn)如下報錯

 

  1. [oracle@oracle19c1 ~]$ ssh 192.168.31.71 
  2. ssh_exchange_identification: readConnection reset by peer 
  3.  
  4. [oracle@oracle19c1 ~]$ telnet 192.168.31.71 22 
  5. Trying 192.168.31.71... 
  6. Connected to 192.168.31.71. 
  7. Escape character is '^]'
  8. Connection closed by foreign host. 

連數(shù)據(jù)庫卻不受影響,因為數(shù)據(jù)庫服務(wù)不歸hosts.deny和hosts.allow管

 

  1. [oracle@oracle19c1 ~]$ sqlplus sys/xxxxx@192.168.31.71:1521/orcltest as sysdba 
  2.  
  3. SQL*Plus: Release 19.0.0.0.0 - Production on Sun Aug 16 23:12:49 2020 
  4. Version 19.3.0.0.0 
  5.  
  6. Copyright (c) 1982, 2019, Oracle.  All rights reserved. 
  7.  
  8. Connected to
  9. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 
  10. With the Partitioning, OLAP, Data Mining and Real Application Testing options 

其中ip地址也可以換成以下的寫法

通配符的形式 192.168.31.*表示192.168.31這個網(wǎng)段

網(wǎng)段/掩碼 192.168.31.0/255.255.255.0也表示192.168.31這個網(wǎng)段

3. 通過iptables

sqlnet.ora能夠限制數(shù)據(jù)庫的訪問,/etc/hosts.deny和/etc/hosts.allow能夠限制ssh的訪問,那有沒有辦法既能限制數(shù)據(jù)庫的訪問,也能限制ssh的訪問呢,答案就是linux自帶的防火墻功能了。為了實驗,將前面做的修改全部清除。

使用root執(zhí)行以下命令

 

  1. service iptables start  # 打開防火墻服務(wù)iptables -I INPUT -s 192.168.31.0/24 -p tcp --dport 1521 -j ACCEPT  # 允許192.168.31網(wǎng)段的ip訪問本機(jī)1521端口iptables -I INPUT ! -s 192.168.31.0/24 -p tcp --dport 22 -j DROP  # 拒絕非192.168.31網(wǎng)段的ip訪問本機(jī)22端口service iptables save  # 規(guī)則保存到配置文件/etc/sysconfig/iptables中 

這樣就同時限制了其它ip對服務(wù)器的ssh和數(shù)據(jù)庫訪問一些擴(kuò)展知識:

  1. iptables -L -n --line-numbers  # 查看當(dāng)前系統(tǒng)中的iptablesiptables -D INPUT 2  # 刪除input鏈中編號為2的規(guī)則,編號數(shù)字可以通過上一個命令得到 

 

03總結(jié)

  1. 如果只是限制其它ip對數(shù)據(jù)庫的訪問,使用sqlnet.ora
  2. 如果要限制其它ip對數(shù)據(jù)庫所在服務(wù)器上的ssh連接,使用/etc/hosts.deny和/etc/hosts.allow
  3. 前面兩個配合起來,基本上就能保證你的數(shù)據(jù)庫安全了。但是如果你對linux的iptables很熟悉,那么直接使用iptables去限制。
  4. 使用/etc/hosts.deny和iptables時一定要保證自己的操作機(jī)能連到服務(wù)器,不然很容易就把自己鎖死在外面了。 

 

責(zé)任編輯:龐桂玉 來源: ITPUB
相關(guān)推薦

2010-04-15 15:52:12

Oracle數(shù)據(jù)庫

2010-04-07 18:26:43

Oracle數(shù)據(jù)庫

2011-03-14 13:33:32

Oracle數(shù)據(jù)庫啟動

2010-04-06 10:52:06

Oracle數(shù)據(jù)庫

2011-03-21 12:51:16

Oracle數(shù)據(jù)庫表連接

2010-10-26 13:33:08

Oracle自動備份

2010-04-28 16:23:18

Oracle數(shù)據(jù)庫

2010-04-19 16:08:31

Oracle數(shù)據(jù)庫

2010-10-26 14:06:43

oracle連接遠(yuǎn)程數(shù)

2010-04-29 11:53:42

Oracle數(shù)據(jù)庫

2010-04-14 15:45:49

Oracle 數(shù)據(jù)庫

2011-04-13 14:07:17

OracleSybase數(shù)據(jù)庫

2011-08-30 17:48:48

Oracle數(shù)據(jù)庫日期to_char方式to_date方式

2011-04-13 14:38:17

2010-11-15 10:30:04

Oracle數(shù)據(jù)庫啟動

2010-10-26 16:07:45

連接oracle數(shù)據(jù)庫

2010-04-06 11:02:30

Oracle 數(shù)據(jù)庫

2009-08-26 16:56:49

Oracle訪問Syb

2010-04-22 17:36:51

Oracle數(shù)據(jù)庫

2011-03-17 15:16:38

點贊
收藏

51CTO技術(shù)棧公眾號