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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With