我正在Windows 7上的vm上运行的debian linux系统中运行mysql。我修改了iptables以通过端口3306接受来自任何地方的连接-但我无法从Windows对其进行telnet。虽然我可以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系统需要等待一段时间才能自行关闭连接。或者我可以做一个^]并关闭它。

最佳答案

问题-严格的安全权限

如果您正在运行默认的Debian Wheezy安装,请直接配置文件/etc/mysql/my.cnf,使mysql仅绑定到127.0.0.1-这将解释为什么您可以从包装盒内进行telnet,而不能从包装盒内进行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防火墙不是问题。

07-26 09:29
查看更多