Elasticsearch : Curl -X GET “localhost:9200” gives “Network Error (dns_unresolved_hostname)”

I have installed as .tar.gz using wget and chown-ed the elasticsearch folder as a xyz user and xyzgrp group .

I did run the es using ./bin/elasticsearch and it ran fine with no errors.

then I curl-ed, curl -X GET "localhost:9200" which gives the following error. But if I run as root curl is spitting out the expected output.

as xyz user:

Network Error
Network Error (dns_unresolved_hostname)

Your requested host "localhost" could not be resolved by DNS.

For assistance, contact your network support team.

as root:

{
"name" : "wE3SaRO",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "YobA_1NiT_aHGlgQhAWdZA",
"version" : {
"number" : "6.4.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "04711c2",
"build_date" : "2018-09-26T13:34:09.098244Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
one more thing, i'm running the elasticsearch as xyz user not as root

It seems your system cannot resolve localhost which sounds extremely weird and more like a misconfiguration on your system. Can you run curl 127.0.0.1:9200 - does it work?

curl 127.0.0.1:9200

> <HTML>
> <HEAD><TITLE>Redirection</TITLE></HEAD>
> <BODY><H1>Redirect</H1></BODY>

This is what curl is spitting out :frowning:

What could be the misconfiged part? any guess?

Sounds like you have a proxy may be?

2 Likes

Was going to say the same thing, compare:

env | grep -i proxy

as root and as xyz

2 Likes

env | grep -i proxy

as xyz user
http_proxy=http://web-proxy.corp.mycomp.net:8080
https_proxy=http://web-proxy.corp.mycomp.net:8080

as root, it spits the same thing.. but if I'm not giving any proxy, I cannot download any packages because I'm inside my company network

That's your issue, it is completely unrelated to Elasticsearch.
You cannot reliably call the local server (localhost, 127.0.0.1) through a remote proxy used to go out on the internet.

Try:

curl -X GET "localhost:9200" --noproxy

Read:
https://ec.haxx.se/usingcurl-proxies.html
(Specifically the section called " Proxy environment variables")

Talk to your system administrator if you need assistance locally calling services on a server WITHOUT using a proxy or between servers in the same vlan.

Your user session on your servers is configured to send all HTTP/HTTPS traffic toward a remote proxy server, which breaks your call toward Elasticsearch which is installed locally on the server and which you are trying to call directly and locally.

1 Like

yeah this one works !

curl -X GET "localhost:9200" --noproxy "*"

{
  "name" : "wE3SaRO",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "YobA_1NiT_aHGlgQhAWdZA",
  "version" : {
    "number" : "6.4.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "04711c2",
    "build_date" : "2018-09-26T13:34:09.098244Z",
    "build_snapshot" : false,
    "lucene_version" : "7.4.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

This works for me ,but not sure whether ES will accompany LS and KB well . Will post after checking . Thanks a lot!

Thanks for others too :pray:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.