如何通过 ssh 隧道链(双隧道,公司网络中的服务器)连接到 Oracle Database 11g 服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3653788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I connect to Oracle Database 11g server through ssh tunnel chain (double tunnel, server in company network)?
提问by Michal Drozd
I have SSH access to 'public' server, which is also the gateway to company network. There is another server in the network, where localOracle Database server is running (There is no access from outside of this server, only localhost DB connections are accepted). And of course, I have another SSH access to this server.
我可以通过 SSH 访问“公共”服务器,这也是公司网络的网关。网络中有另一台服务器,其中运行本地Oracle 数据库服务器(无法从该服务器外部访问,仅接受 localhost DB 连接)。当然,我还有另一个 SSH 访问此服务器。
Is there any way to join to this Oracle Database 11g Server from outside of the network ? I am asking if there is something like ssh tunnel chain, and how i configure it. This can be usefull, for example, for TOAD for Oracle (ORACLE client).
有没有办法从网络外部加入这个 Oracle Database 11g 服务器?我在问是否有类似 ssh 隧道链的东西,以及我如何配置它。例如,这对于 TOAD for Oracle(ORACLE 客户端)很有用。
EDIT:Here is image
编辑:这是图像
Thanks
谢谢
回答by Erich Kitzmueller
Yes, it's possible. E.g. on Linux, run
是的,这是可能的。例如在 Linux 上,运行
ssh -N -Llocalport:dbserver:dbport yourname@connectionserver
where
在哪里
- localport is the port on your machine which will be forwarded (can be 1521 if there is no local instance of oracle running)
- dbserver is the name or IP of the database server
- dbport is the port of the database (usually 1521)
- yourname is the login on the connectionserver
- connectionserver is the machine where you have ssh access
- localport 是你机器上将被转发的端口(如果没有运行oracle的本地实例,可以是1521)
- dbserver 是数据库服务器的名称或 IP
- dbport 是数据库的端口(通常是 1521)
- 你的名字是连接服务器上的登录名
- connectionserver 是您可以访问 ssh 的机器
The same can be done on Windows using Plink (which comes with Putty):
同样可以在 Windows 上使用 Plink(Putty 附带)完成:
plink -N -L localport:dbserver:dbport yourname@connectionserver
Do this on both machines (your local machine and the server you have access to) to chain the ssh tunnels. Example:
在两台机器(您的本地机器和您有权访问的服务器)上执行此操作以链接 ssh 隧道。例子:
Connection server (assuming Linux):
连接服务器(假设为 Linux):
ssh -N -L1521:dbserver:1521 dblogin@dbserver
Your PC:
你的电脑:
plink -N -L 1521:connectionserver:1521 connlogin@connectionserver
The tnsnames.ora entry must look like you are running a local database, e.g.
tnsnames.ora 条目必须看起来像您正在运行本地数据库,例如
prodoverssh =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod)
)
)
回答by Michal Drozd
Thanks!
谢谢!
I called ssh -N -LXXXX:server:YYYY login@server
twice.
我打了ssh -N -LXXXX:server:YYYY login@server
两次电话。
First, I called
首先,我打电话
ssh -L 9998:127.0.0.1:9997 [email protected]
on my PC.
在我的电脑上。
Then, on this server (during the SSH session), I called
然后,在此服务器上(在 SSH 会话期间),我调用了
ssh -L 9997:localhost:1521 [email protected]
where 192.168.105.111 is server where ORACLE was running.
其中 192.168.105.111 是运行 ORACLE 的服务器。
So what I did is following redirection:
所以我所做的是遵循重定向:
1521 (COMPANY ORACLE SERVER)
-> 9997 (COMPANY GATEWAY SERVER)
-> 9998 (LOCAL PC)
So I got ORACLE access in my local PC at port 9998 !
所以我在本地 PC 的 9998 端口获得了 ORACLE 访问权限!
回答by loudstil
you can add as well the -f
option which run the ssh command in the background.
您还可以添加-f
在后台运行 ssh 命令的选项。