122

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.

Abraham Duran
  • 1,778
  • 3
  • 14
  • 22
  • 6
    This is the answer you're looking for: http://stackoverflow.com/questions/33412549/how-to-bind-elasticsearch-2-0-on-both-loopback-and-non-loopback-interfaces/33438638#33438638 – Val Nov 13 '15 at 16:19
  • Thanks! It was exactly what I was looking for! – Abraham Duran Nov 13 '15 at 20:58
  • Possible duplicate of [How to bind Elasticsearch 2.0 on both Loopback and Non-Loopback interfaces?](https://stackoverflow.com/questions/33412549/how-to-bind-elasticsearch-2-0-on-both-loopback-and-non-loopback-interfaces) – eckes May 29 '17 at 10:28

15 Answers15

178

In /etc/elasticsearch/elasticsearch.yml put

network.host: 0.0.0.0
Artyom Vancyan
  • 5,029
  • 3
  • 12
  • 34
arsent
  • 6,975
  • 3
  • 32
  • 31
  • 4
    network.host: 0.0.0.0 allows all local networks to access to this node. This is not recommended for production mode i guess. – Isengo May 19 '17 at 21:11
  • 2
    it means all ip addresses are allowed. Not secure! – Yavuz Dec 09 '17 at 20:18
  • 6
    The file on my CentOS system was found in `/etc/elasticsearch/elasticsearch.yml` and content: `network.host: ["0.0.0.0"]` – AlikElzin-kilaka Jan 18 '18 at 14:22
  • doesn't work for me. ES is still running on 127.0.0.1 `T_T` – E.Big May 31 '18 at 15:06
  • For those one who can't locate the config file on Windows please check the `C:\ProgramData\Elastic\Elasticsearch\config` location. If you want to connect programmatically to Elasticsearch you may need to set `transport.host: 0.0.0.0` in `elasticsearch.yml` file. – kojot Jul 03 '18 at 10:44
  • Pay attention that [additional virtual memory may be needed](https://github.com/elastic/elasticsearch/issues/30236) – Eli Jan 29 '19 at 13:41
  • Ajit's answer worked for me on a Windows 10 machine. I tried the above solution but it caused Elastic search to crash, preventing it from launching at all! – Yousuf Khan Feb 28 '20 at 06:14
  • 2
    This caused me not to be able to restart elasticsearch service on ubuntu and therefore it did not solve my problem. – max Sep 04 '20 at 19:30
  • The path is `/etc/elasticsearch/elasticsearch.yml` for `v7.10.0` on the ubuntu server. – Søren Dec 06 '20 at 09:41
  • I tried this and now I see this message `the default discovery settings are unsuitable for production use` – devaent Jan 19 '21 at 23:31
80

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.

AKs
  • 1,727
  • 14
  • 18
19

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

Deepika Chalpe
  • 404
  • 8
  • 19
  • Got: Exception in thread "main" BindTransportException[Failed to bind to [9300-9400]]; nested: ChannelException[Failed to bind to: /10.0.0.4:9400] – mountrix Jul 26 '16 at 09:42
  • 2
    How can this be done, I mean, we can't just rename `elasticsearch.yml` to `elasticsearch.json` because first one, hmmm, YAML and second one is `JSON`?? – Shubham A. May 25 '17 at 05:53
17

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

Mohammad Sayeed
  • 2,025
  • 1
  • 16
  • 27
  • legend! this worked. Mirror https://blog.eq8.eu/til/publicly-accessible-elasticsearch-7x.html – equivalent8 Mar 02 '21 at 12:13
  • still shows Timed out, when trying from remote. I have it installed on ubuntu 20.04 and i have disabled the ufw firewall. still can not curl from my local machine, but works find when try to curl from machine it self – Sizzling Code May 19 '21 at 00:41
  • This one has worked for me on Windows and ElasticSearch version: 7.15.1 – Wojciech Jakubas Nov 07 '21 at 21:50
  • 1
    legend !!! you saved my day. in ES 7 you need to add network.bind_host and network.publish_host if not it will not restart. thank you again – Mathieu Mourareau Dec 28 '21 at 09:38
12

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

Mentor
  • 3,058
  • 1
  • 22
  • 27
9

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

Ben
  • 2,957
  • 2
  • 27
  • 55
8

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

Animesh
  • 1,005
  • 10
  • 20
5

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
4

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
Kaleem Ullah
  • 6,799
  • 3
  • 42
  • 47
2

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.

bikram
  • 7,127
  • 2
  • 51
  • 63
1

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

Sampada
  • 2,931
  • 7
  • 27
  • 39
Jay Shah
  • 3,553
  • 1
  • 27
  • 26
1

in my server ubuntu 22.04, it needs like below:

transport.host: localhost
transport.tcp.port: 9300
http.port: 9200
network.host: 0.0.0.0
tesmojones
  • 2,496
  • 2
  • 21
  • 40
0

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

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

Franco Fontana
  • 115
  • 1
  • 6
0

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.

silentsudo
  • 6,730
  • 6
  • 39
  • 81