通过telnet连接到mysql服务器

时间:2014-03-04 07:56:42

标签: debian iptables

我在debian linux系统中运行mysql,该系统在Windows 7上运行vm。我已经修改了iptables以接受来自3306端口的任何地方的连接 - 但我无法从Windows进行远程登录。虽然我可以ping vm并确保它可以访问。

这是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。这就是我得到的:

$ 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系统在关闭连接之前等待一段时间。或者我可以做^]并关闭它。

1 个答案:

答案 0 :(得分:8)

问题 - 严格的安全权限

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

如果你跑:

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 guest虚拟机的静态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防火墙不是问题。