SSH隧道:local =>网关=> MySQL服务器 [英] SSH tunnel: local => gateway => MySQL server

查看:152
本文介绍了SSH隧道:local =>网关=> MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在实验室的远程服务器上访问MySQL数据库.只有登录到远程网络上的网关服务器后,该服务器才可以访问:

I need to access a MySQL database on a remote server at my lab. The server is only accessible once I log in to a gateway server on the remote network:

local server => gateway server => MySQL server.

我可以使用端口24222 SSH到网关.

I can ssh to the gateway using port 24222.

我正在使用PERL DBI 模块.这是我在实验室时用来连接的东西:

I am using the PERL DBI module. This is what I use to connect when I am at the lab:

my $host="1.2.3.4";
my $database="dbname";
my $user="user";
my $pw="pass";
my $table="table";    

我想我必须建立一条通过网关服务器到数据库服务器的隧道.我该怎么做呢?如果MySQL数据库位于网关上,则可以这样打开隧道:

I imagine I have to set up a tunnel through the gateway server to the database server. How do I go about doing that? If the MySQL database were on the gateway, I could open a tunnel like so:

$ ssh -f user@gateway -L 3307:127.0.0.1:3306 -N 

如何修改此设置以通过网关上的开放端口24222隧道到达1.2.3.4上的MySQL服务器?

How can I modify this to tunnel through the open port 24222 on the gateway through to the MySQL server on 1.2.3.4?

更新:

使用@anttir的答案,它可以按如下方式工作.

Using @anttir's answer I got it to work as follows.

  1. 设置隧道:

  1. Set up the tunnel:

$ ssh -fN -p 24222 user1@11.12.13.14 -L 3307:1.2.3.4:3306

  • 设置脚本变量:

  • Set up the script variables:

    my $host="127.0.0.1";
    my $port = 3307;
    

  • 推荐答案

    使用以下命令:

    $ ssh -f user@gateway -L 3307:1.2.3.4:3306 -N 
    

    这表明到客户端本地主机3307的所有连接都将通过SSH隧道转发到网关,然后连接到主机1.2.3.4到端口3306.

    This states that all connections to client localhost 3307 will be forwarded via the SSH tunnel to gateway and then connected to host 1.2.3.4 to port 3306.

    如果SSH位于端口24222上,则

    edit: If the SSH is on port 24222 then

    $ ssh -f user@gateway -p 24222 -L 3307:1.2.3.4:3306 -N 
    

    这篇关于SSH隧道:local =>网关=> MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆