112
votes

Starting from v2.0 Elasticsearch is listening only on localhost by default, but I'd like to make request outside localhost.

For example, a request like this is allowed:

http://localhost:9200/

But this is not:

http://server_name:9200/ (from outside of the server, eg: a local computer in the same LAN).

Thanks for your help.

14
This is the answer you're looking for: stackoverflow.com/questions/33412549/…Val
Thanks! It was exactly what I was looking for!Abraham Duran

14 Answers

166
votes

In config/elasticsearch.yml put

network.host: 0.0.0.0
70
votes

By default http transport and internal elasticsearch transport only listens to localhost. If you want to access Elasticsearch from the host other than localhost then try adding following configurations in config/elasticsearch.yml.

transport.host: localhost 
transport.tcp.port: 9300 
http.port: 9200
network.host: 0.0.0.0

Here, network.host as 0.0.0.0 allow access from any host within the network.

19
votes

Rename the elasticsearch.yml file to elasticsearch.json inside config folder and add:

{
    "network" : {
        "host" : "10.0.0.4"
    }
}

Another option is to provide the settings externally either using the ES_JAVA_OPTS or as parameters to the elasticsearch command, for example:

$ elasticsearch -Des.network.host=10.0.0.4

Another option is to set es.default. prefix instead of es. prefix, which means the default setting will be used only if not explicitly set in the configuration file.

Another option is to use the ${...} notation within the configuration file which will resolve to an environment setting, for example:

{
    "network" : {
        "host" : "${ES_NET_HOST}"
    }
}

The location of the configuration file can be set externally using a system property:

$ elasticsearch -Des.config=/path/to/config/file

For more info, check out https://www.elastic.co/guide/en/elasticsearch/reference/1.4/setup-configuration.html

10
votes

In /etc/elasticsearch/elasticsearch.yml set the following value:

network.host: [ localhost, _site_ ]

This option allows you to access from both the localhost and from all computers on the local network (192.168.X.X), but not from outside.
Read more about this and other options read the documentation

9
votes

As @arsent mentioned add that ip address to the config file:

sudo nano /etc/elasticsearch/elasticsearch.yml

Jay also added an important point - if you're using a firewall, remember to add a rule allowing traffic to that port.

If you want to allow a master server to access ES over http, then add a rule allowing access to only from that particular address. For example, say you are using ufw, then run this command to add your port:

sudo ufw allow from xxx.xxx.xxx.xxx to any port zzzz

Replace xxx.xxx.xxx.xxx with your master server IP address and zzzz with the port you configured in config/elasticsearch.yml

It is recommended to use a custom port and not keep the default 9200

To test it, SSH into your master server and ping the ES ip with the correct port to see if you get a response:

curl -X GET 'http://xxx.xxx.xxx.xxx:zzzz'

You can also verify ES is inaccessible from other IPs by trying it with your browser.

There's an excellent article that shows how to set up ES on Ubuntu on DigitalOcean

8
votes

In the remote machine where elasticsearch is installed just add the below two configurations in /etc/elasticsearch/elasticsearch.yml

network.host: xx.xx.xx.xx #remote elastic machine's internal IP
discovery.type: single-node

Tested on elasticsearch 6.8.3 and AWS EC2 Linux AMI as remote machine

6
votes

In Elastic Search 7.0 update /etc/elasticsearch/elasticsearch.yml

network.host: 0.0.0.0
network.bind_host: 0.0.0.0
network.publish_host: 0.0.0.0

Additionally:

discovery.seed_hosts: ["0.0.0.0", "[::0]"]

** Don't forget to restart after changing the config. If still Elastic search not restarted check log journalctl -xe

5
votes

In /etc/elasticsearch/elasticsearch.yml:

network.host: 0.0.0.0
network.bind_host: 0.0.0.0
network.publish_host: 0.0.0.0
3
votes

For ElasticSearch 7.8 and up

Check if you're on single node. add following line

cluster.initial_master_nodes: node-1

To access the Elasticsearch server from another computer or application, make the following changes to the node’s C:\ProgramData\Elastic\Elasticsearch\config\elasticsearch.yml file:

Add following lines

network.host: ["0.0.0.0", 127.0.0.1", "[::1]"]
network.bind_host: 0.0.0.0
network.publish_host: 0.0.0.0
http.host: 0.0.0.0

Some time you might need to Enable CORS

http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length

Here is my full yml file

bootstrap.memory_lock: false
cluster.name: elasticsearch
http.port: 9200
node.data: true
node.ingest: true
node.master: true
node.max_local_storage_nodes: 1
cluster.initial_master_nodes: node-1
node.name: ITDEV
path.data: C:\ProgramData\Elastic\Elasticsearch\data
path.logs: C:\ProgramData\Elastic\Elasticsearch\logs
transport.tcp.port: 9300
xpack.license.self_generated.type: basic
xpack.security.enabled: false
network.host: ["0.0.0.0", 127.0.0.1", "[::1]"]
network.bind_host: 0.0.0.0
network.publish_host: 0.0.0.0
http.host: 0.0.0.0
http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length
2
votes

Replace localhost with 0.0.0.0 in two places.

  1. Goto /etc/elasticsearch/elasticsearch.yml. Look for value in network.host and change it to 0.0.0.0

  2. This is step if you are using Kibana. Goto /etc/kibana/kibana.yml. Look for value in server.host and change it to 0.0.0.0

Now you access remotely access with IP address and host.

1
votes

In config/elasticsearch.yml, put network.host: 0.0.0.0 as @arsent said. And also add Inbound Rule in firewall for your ElasticSearch port(9200 ByDefault).

It worked in ElasticSearch version 2.3.0

0
votes

Apart from setting network.host : 0.0.0.0

there might be need to set following params

node.name: elasticsearch-node-1

cluster.initial_master_nodes: ["elasticsearch-node-1"]

All setting go in elasticsearch/elasticsearch.yml

0
votes

Using Windows 10 and standalone Elasticsearch 7, putting this in elasticsearch.yml solve the issue:

network.host: 0.0.0.0 discovery.type: single-node

0
votes

My Setup was Kibana On windows and ES on Ubuntu, I was not able to access by changing only network.host

For ElasticSearch-7.10-1 Along with:

network.host: 0.0.0.0

I also had to add

transport.host: localhost

Otherwise, I was not able to access it within the same wifi network.