【问题标题】:Connecting to mysql server over telnet通过 telnet 连接到 mysql 服务器
【发布时间】:2014-04-05 15:21:44
【问题描述】:

我在 debian linux 系统中运行 mysql,该系统在 Windows 7 上的 vm 上运行。我已修改 iptables 以接受来自任何地方通过端口 3306 的连接 - 但我无法从 Windows 对它进行 telnet。虽然我可以 ping 虚拟机并确保它可以访问。

这是 iptables 的详细信息:

# sudo iptables -L
CHAIN INPUT (policy ACCEPT)
target        prot opt source        destination
ACCEPT        tcp  --  anywhere      anywhere         tcp dpt:mysql

CHAIN FORWARD (policy ACCEPT)
target        prot opt source        destination

CHAIN OUTPUT (policy ACCEPT)
target        prot opt source        destination
#

这是我添加规则的内容:

-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

我可以成功 ping 到 debian vm,但是当我尝试从 windows 主机进行 telnet 时,我得到:

Could not open connection to the host, on port 3306: Connect failed

我还尝试在 debian 中进行远程登录。这是我得到的:

$ telnet localhost 3306
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
6
5.1.73-1*?MH]~"* wG;2(oz9JJrConnection closed by foreign host.
$

debian 系统会等待一段时间,然后自行关闭连接。或者我可以做一个 ^] 并关闭它。

【问题讨论】:

  • 您的虚拟机是否使用主机网络?如果没有桥接,它可能会给您带来问题?您的 Windows 防火墙是如何配置的?
  • 对不起,只是重新阅读,您可以 ping...
  • 你能从 Debian 内部 telnet 到它吗?
  • @AndrewMcDonnell 谢谢。我已经用结果更新了问题。
  • @AndrewMcDonnell 正如我上面提到的,telnet 连接会自动关闭。

标签: debian iptables


【解决方案1】:

问题 - 严格的安全权限

如果您正在运行默认的 Debian wheezy 安装,开箱即用的文件 /etc/mysql/my.cnf 配置为使 mysql 仅绑定到 127.0.0.1 - 这可以解释为什么您可以从框内远程登录但不是来自外部。

如果你运行:

sudo netstat -lntp

你看到了

tcp         0    0   127.0.0.1:3306      0.0.0.0.*     LISTEN     1234/mysqld

并没有其他mysqld条目,确实是这样。

一个解决方案

编辑文件 /etc/mysql/my.cnf 并更改以下行:

 bind-address   = 127.0.0.1

 bind-address   = 0.0.0.0

或者,改为以下行,其中 192.168.1.2 是您的 Debian VM 来宾的静态 IP 地址:

 bind-address   = 192.168.1.2

如果您使用 ipv6 或其他配置,上述内容会有所不同。

另请参阅:http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_bind-address

注意

返回的零负载长度 TCP 数据包(粗略地说)是 RST、ACK 数据包,它们告诉您的 Windows 机器在该接口上的该端口上没有任何东西在侦听。这确实证明您的 Windows 防火墙不是问题。

【讨论】:

  • 感谢您的详细解答。我的 telnet 是成功的。虽然我想要做的是将 Windows 上的 NodeJS 服务器连接到 debian 上的 mysql 服务器。我想这应该不再是问题了吧?
  • 我猜,我对 NodeJS 还不太了解!
猜你喜欢
  • 2018-12-25
  • 2017-10-09
  • 2017-04-05
  • 2019-03-07
  • 2010-09-24
  • 2018-01-09
  • 1970-01-01
  • 1970-01-01
  • 2017-09-26
相关资源
最近更新 更多