【问题标题】:Difference between SSH tunnelsSSH隧道之间的区别
【发布时间】:2014-11-25 19:13:51
【问题描述】:

我正在尝试配置一个 SSH 隧道,以绕过可以访问它的主机 (remote_host) 通过远程数据库 (remote_mysql_server) 的 mysql 调用,但我不知道两者之间有什么区别(注意冒号:本地端口前):

> ssh -f username@remote_host -L 3306:remote_mysql_server:3306 -N
> lsof -i :3306
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
ssh     16797 vagrant    4u  IPv6  31697      0t0  TCP localhost:mysql (LISTEN)
ssh     16797 vagrant    5u  IPv4  31698      0t0  TCP development:mysql (LISTEN)

> ssh -f username@remote_host -L :3306:remote_mysql_server:3306 -N
> lsof -i :3306
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
ssh     16805 vagrant    4u  IPv6  31697      0t0  TCP *:mysql (LISTEN)
ssh     16805 vagrant    5u  IPv4  31698      0t0  TCP *:mysql (LISTEN)

它们都为我工作以执行mysql -h 127.0.0.1 -u dbusername -pPasswordDB database

【问题讨论】:

    标签: mysql bash ssh


    【解决方案1】:

    -L选项的格式为:

    -L [bind_address:]port:host:hostport
    

    bind_address: 部分是可选的,如果缺少它,则隧道仅绑定到本地主机(可以使用 ssh 配置中的GatewayPorts 选项更改默认行为)。但是,如果您指定它,它会绑定到您指定的内容,或者如果您使用空的bind_address*,它会绑定到所有接口。

    【讨论】:

    • 据我了解,bind_address 参数是来自 3306 端口上的请求的地址。这解释了为什么对我来说,从 localhost 执行 mysql 指令对它们没有任何影响,但在第二种情况下,我能够使用来自其他机器的 -h development 连接到 MySQL。谢谢!
    猜你喜欢
    • 2018-08-20
    • 2013-05-20
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 2016-06-27
    • 2020-07-31
    相关资源
    最近更新 更多