Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can connect with ping but not curl

Tags:

curl

ping

I am testing connecting to a remote server from my local machine. Using ping I can successfully connect but if I try with curl it just hangs:

Working with 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

Fails/timeout with curl:

$ 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

Why can I connect with ping command but not with curl command?

like image 630
u123 Avatar asked Jan 27 '23 01:01

u123


1 Answers

This could be caused by port 80 on the remote machine being closed. Check your firewall rules to ensure this port is open.

Ping does not connect to a port (it uses ICMP), so that is why pinging works without opened ports.

On a side note, your ping and curl commands show you're trying to connect to "db-machine-02". Be aware that databases do not commonly communicate over port 80 by default.

like image 50
E13 Avatar answered Jan 31 '23 12:01

E13