简体   繁体   English

验证端口是否打开

[英]Verifying ports are open

I'm trying to create a connection to a MySQL database hosted on a raspberrypi through a java program running on my computer. 我正在尝试通过计算机上运行的Java程序创建与raspberrypi上托管的MySQL数据库的连接。 So far when I run my program I receive a communications link failure. 到目前为止,当我运行程序时,我收到通信链接故障。

As part of my trouble shooting I am trying to test if port 3306 is open or not. 作为解决问题的一部分,我试图测试端口3306是否打开。

I have used websites like this - http://www.mynetworktest.com/ports.php However I don't understand how port 80 can be closed if I can surf the web and I'm unsure if the rest of information presented is reliable. 我曾经使用过这样的网站-http: //www.mynetworktest.com/ports.php但是我不明白如果我可以上网浏览如何关闭80端口,并且我不确定所提供的其余信息是否可靠。

What is the best way of testing if a port is open and if also if port 80 genuinely is closed how come I can surf the web? 测试端口是否打开以及端口80是否真正关闭的最佳测试方法是什么?

Two things (you're probably more interested in the second point): 两件事(您可能对第二点更感兴趣):

  1. The port's you're quoting are incoming port numbers. 您引用的端口是传入端口号。 Your device will not use port 80 to "browse the web" (connect to a web server). 您的设备将不会使用端口80“浏览Web”(连接到Web服务器)。 It will select a port at random (for all intents and purposes) for its outgoing connection, and its the web server your requesting files from that uses port 80. To that end, assuming you don't have any over aggressive firewall rules on your computer, you simply need to make sure that the incoming ports you require are open in the PI's firewall (3306 by default for MySQL, but feel free to double check my.cnf if you want to satisfy yourself of the fact) 它将为它的传出连接随机地(出于所有意图和目的)选择一个端口,并在Web服务器上使用80端口从该端口请求文件。为此,假设您对防火墙没有任何过度攻击性的防火墙规则在计算机上,您只需要确保在PI的防火墙中打开了所需的传入端口(MySQL默认为3306,但是如果您想满足自己的话,请随时仔细检查my.cnf)。

  2. What is probably the problem for you is that most mysql default configurations come with the default setting of having MySQL bind to the 127.0.0.1 ip. 您可能遇到的问题是,大多数mysql默认配置都带有将MySQL绑定到127.0.0.1 ip的默认设置。 Which means only devices connecting via the local loopback interface can connect (which means only those clients running on the same device). 这意味着只有通过本地环回接口连接的设备才能连接(这意味着只有在同一设备上运行的那些客户端)。 Edit your my.cnf and delete the bind_address line, or set to: 编辑my.cnf并删除bind_address行,或设置为:

    bind_address=0.0.0.0 bind_address = 0.0.0.0

Then restart the mysql service 然后重启mysql服务

What your doing is telling MySQL to bind to any network interface (0.0.0.0) rather than the local loopback interface. 您要做的是告诉MySQL绑定到任何网络接口(0.0.0.0),而不是本地环回接口。 You could also set it to your locally assigned ip address which would only allow those on your local network to connect, but for the sake of ease (and not having to worry about DHCP) i'd just set it to 0.0.0.0 for now. 您也可以将其设置为本地分配的IP地址,该IP地址仅允许本地网络上的IP地址进行连接,但是为了简便起见(不必担心DHCP),我现在将其设置为0.0.0.0 。

Sorry I am not sure what you mean. 对不起,我不确定你的意思。 Are there 2 separate computers 1) raspberrpi 2) "my computer"? 是否有2台单独的计算机1)raspberrpi 2)“我的电脑”? If so, how is "my computer" connected to "raspberrypi"? 如果是这样,“我的电脑”如何连接到“ raspberrypi”? Are they connected to each other, or are they both connected independently to the internet? 它们是相互连接的,还是两者都独立连接到互联网的?

Typically, you create direct connection between the 2 machines (EG an ethernet cable). 通常,您在两台机器之间创建直接连接(例如,一条以太网电缆)。 You then make sure both machines have a "route" set to the other machine. 然后,请确保两台计算机都将“路由”设置为另一台计算机。 Your mysql connection string (setting) would include either the ip address or host name of your raspberry computer. 您的mysql连接字符串(设置)将包括您的树莓派计算机的IP地址或主机名。

You are correct, mysql is running on port 3306 by default (not port 80). 您是正确的,默认情况下mysql在端口3306上运行(而不是端口80)。

What operating systems are you running? 您正在运行什么操作系统?

Sorry, more question than answer. 抱歉,问题多于答案。

Hope that helps :) 希望有帮助:)

you can use 您可以使用

nc -l 3306

if it fails with "port is already open" , you can make sure the port is already open :-) 如果失败并显示“端口已打开” ,则可以确保端口已打开:-)
also you can telnet to that port from other computer. 您也可以从其他计算机远程登录到该端口。

telnet 192.168.1.92 3306

to determine if the port is accessible from other computer or not. 确定是否可以从其他计算机访问该端口。
you should do this to change mysql config as well: 您也应该这样做以更改mysql配置:
here is the link: how to Configure mysql 这是链接: 如何配置mysql
you should change the line 你应该换线

[mysqld]
bind-address = 127.0.0.1

and set it to 0.0.0.0 并将其设置为0.0.0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM