If i do curl on localhost then its working fine.However if i replace with system ip address its giving error. I have entry for ip address in etc/hosts

curl -v https://<ip address>:9200
* About to connect() to <ip address> port 9200 (#0)
*   Trying <ip address>... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host

my /etc/host/ localhost
<ip address> Load-testing-1-4
  • Is the remote host accessible from your machine? Is there an external service running on port 9200 on the remote host? Does the local host's firewall allow you to make outgoing connection to the remote machine and does the remote machine's firewall allow incoming connections on that port? The /etc/hosts file will not make any difference here as you are already using an IP address with curl. – Kusalananda Jan 7 '20 at 8:01
  • ip address of same machine is not working while localhost is working fine – Sanjay Jan 7 '20 at 8:18
  • Oh, so the IP address is of the local host, but it's its external IP address? Ok, does the service listen on the port on all interfaces, or does it only listen on – Kusalananda Jan 7 '20 at 8:21
  • what is the result of netstat -an|grep 9200? – Romeo Ninov Jan 7 '20 at 8:34
  • 1
    Follow instructions from Kusalananda and Romeo Ninov to see if service is responding on external IP. If it, and it still does not work, I would recommend to check firewall, to see that it allows TCP connections to port 9200 on external IP. – nobody Jan 7 '20 at 8:50

The "Connection refused" should mean there is nothing listening to port 9200 on the address. I think the OP is asserting that <ip address> is an address for the local machine, and that curl -v https:localhost:9200 works but that curl -v https://Load-testing-1-4:9200 (maybe replacing Load-testing-1-4 with the ip address from /etc/hosts) doesn't.

If that is the case then you need to look at the thing that curl is trying to connect to, and make sure it is listening on all the addresses associated with the machine, or at least the one for Load-testing-1-4. Using as the address will usually do this for IPv4 rather than an explicit address such as

If I have misunderstood and Load-testing-1-4 is a different machine, then you need to look on that machine for the program that curl is trying to connect to.

An added complication is the https, I would suggest using http first to get things going before beefing up the security.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.