可以连接但不能卷曲

时间:2019-07-22 12:16:19

标签: curl ping

我正在测试从本地计算机连接到远程服务器。使用ping可以成功连接,但是如果我尝试使用curl,它会挂起:

使用ping:

$ ping db-machine-02
Pinging db-machine-02.comp.org [xxx.xx.x.xxx] with 32 bytes of data:
Reply from xxx.xx.x.xxx: bytes=32 time=12ms TTL=51
Reply from xxx.xx.x.xxx: bytes=32 time=12ms TTL=51
Reply from xxx.xx.x.xxx: bytes=32 time=12ms TTL=51
Reply from xxx.xx.x.xxx: bytes=32 time=12ms TTL=51

Ping statistics for xxx.xx.x.xxx:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 12ms, Maximum = 12ms, Average = 12ms

卷曲失败/超时:

$ curl -v db-machine-02
* STATE: INIT => CONNECT handle 0x600077108; line 1332 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x600077108; line 1373 (connection #0)
*   Trying xxx.xx.x.xxx:80...
* TCP_NODELAY set
* STATE: WAITRESOLVE => WAITCONNECT handle 0x600077108; line 1452 (connection #0)
* Connection timed out after 300181 milliseconds
* multi_done
* Closing connection 0
* The cache now contains 0 members
curl: (28) Connection timed out after 300181 milliseconds

为什么我可以用ping命令而不是curl命令连接?

2 个答案:

答案 0 :(得分:1)

这可能是由于远程计算机上的端口80关闭而引起的。 检查您的防火墙规则,以确保此端口已打开。

Ping不连接到端口(它使用ICMP),因此这就是为什么ping无需打开端口即可工作的原因。

在旁注中,您的ping和curl命令显示您正在尝试连接到“ db-machine-02”。请注意,默认情况下,数据库通常不会通过端口80进行通信。

答案 1 :(得分:0)

如果使用代理服务器,如果代理服务器无法“查看”目标主机,则可能会遇到麻烦。例如,如果使用测试或开发环境,并且将Linux开发主机配置为使用公司代理,那么您可能需要配置或覆盖no_proxy环境变量。

例如:当从本地VM开发者框中访问本地VM Web服务器(并且no_proxy被设置为公司代理)时,覆盖curl使http_proxy能够工作。在Linux中,一种选择是在发出no_proxy命令时覆盖curl

joe@vm-dev-host:~$ no_proxy="192.168.1.123" curl -X GET "http://192.168.1.123/somedata"