Can't connect to remote ElasticSearch server using local machine's IP Address - elasticsearch

I can't connect to ElasticSearch on my Digital Ocean droplet using my local machine's IP Address.
I got the IP Address by: Terminal > ipconfig getifaddr en0
- With that result, let's say: 100.888.777.99
I logged into my droplet by running: ssh username#111.222.3.444
Updated my UFW Rules by running: sudo ufw allow 9200 from 100.888.777.99
From my local machine I ran: curl -X GET 'http://111.222.3.444:9200'
And received: curl: (7) Failed to connect to 111.222.3.444 port 9200: Operation timed out
What am I doing wrong?
Things I've tried:
Changing the network.host variable in elasticsearch/elasticsearch.yml
network.host: 0.0.0.0 (also this a security risk since ip addresses are allowed )
Restarting the server
sudo /etc/init.d/elasticsearch restart
Adding more varibles to elasticsearch/elasticsearch.yml
transport.host: localhost
transport.tcp.port: 9300
http.port: 9200

I found that when I changed the UFW Rules to allow all connection to port 9200, I was able to connect to ElasticSearch from my local machine, but without that, it would not connect.
sudo ufw allow 9200
After some deep diving I found the issue was that the IP address that was returned by Terminal wasn't the correct one to use. I had to use the Public IP Address which I got from https://www.whatismyip.com/, you can also get this by:
Terminal > curl ifconfig.me
So when I removed the old UFW rule: 9200 ALLOW IN 100.888.777.99
And used the Public IP Address: sudo ufw allow 9200 from Public_IP_Address it connected.
I'm still not sure why my machine's IP Address doesn't work though...

Related

What port does elasticsearch listen on when installed via homebrew?

I'm using Mac 10.13.6. I just installed elasticsearch via homebrew and launched it ...
brew services start elasticsearch
Service `elasticsearch` already started, use `brew services restart elasticsearch` to restart.
In my /usr/local/etc/elasticsearch/elasticsearch.yml configuration file, I have
http.port: 9200
However, when I attempt to see if that port is available, I get a connection refused ...
localhost:tmp davea$ telnet localhost 9200
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
What port is elasticsearch getting launched on and how can I change that?
That may be the problem of Mac firewall? Edit elasticsearch.yml file in elasticsearch/config folder. Change the localhost to 127.0.0.1 to take a try?
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 9200
#

elasticsearch setup on Gcloud VM fails

I wish to run my elasticsearch remotely on gcloud VM, this is configured to run at 127.0.0.1 at a specific port 9200. How to access this from a website outside this vm? If I change the network host to 0.0.0.0 on the yml file, even 9200 port becomes inaccessible. How do I overcome this problem?
Changed network.host: [_site_ , _local_ , _global_ ]
_site_ = internal ip given by google cloud vm,
_local_ = 127.0.0.1,
_global_ = found using curl ifconfig.me,
Opened a specific port (9200) and tried to connect with global IP address.
curl to the global ip gives
>Output: Failed to connect to (_global_ ip) port 9200: connection refused.
So put network.host:0.0.0.0 and then try to allow 9200 and 9201 port and restart the elasticsearch service.If you are using ubuntu then sudo service elasticsearch restart then check by doing curl -XGET 'http://localhost:9200?pretty'.Let me know if you are still facing any issues.
Use following configurations for elasticsearch.yml
network.host: 0.0.0.0
action.auto_create_index: false
index.mapper.dynamic: false
Solved this problem by going through the logs and found out that the public ip address is re-mapped to the internal ip address, hence network.host can't be set to external ip directly. Elasticsearch yml config is as follows:
'network.host: xx.xx.xxx.xx' is set to the internal ip (given by google),
'http.cors.enabled: true',
'http.cors.allow-origin:"*", (Do not use * in production, its a security issue)
'discovery.type: single-node' in my case to make it work independently and not in a cluster
Now this sandboxed version can be accessed from outside the VM using the external IP address given by Google.

Connection refused with ElasticSearch on Digital Ocean

I install Elastic Search using this tutorial changing only version by Elastic Search.
Set network.host: 127.0.0.1 to access by terminal. But show this error when try connect:
curl: (7) Failed to connect to localhost port 9200: Connection refused
Check your port 9200 is open or not, then check if you're not using the UFW firewall.
In case of you are using the UFW firewall :
sudo ufw allow 9200

Elasticsearch 2.3 enable access from outer ip

I have an Elasticsearch installed on my host.
Request from localhost works fine
curl -X GET http://localhost:9200/
But how can I configure elasticsearch.yml in order to connect from one outer ip?
On the elasticsearch.yml file, locate the line #network.host:, uncoment it (remove the "#") and change to network.host: 0.0.0.0
Then add the exception to the firewall and reload it (In my case I use UFW, so I ran sudo ufw allow 9200 and sudo ufw reload)
Obs: Tested on version: 2.3

Empty reply from server - can't connect to vagrant vm w/port forwarding

I'm running werkzeug (as part of a Tilestache setup) inside a Vagrant VM, running ubuntu 'precise.'
In my Vagrantfile, I have:
config.vm.network :forwarded_port, guest: 8080, host: 8080
When I start the server in the VM, I see:
* Running on http://127.0.0.1:8080/
If I curl that address from within the VM, I get the expected result. When I curl it from the host machine, I get:
curl: (52) Empty reply from server
And Chrome says "No data received."
Troubleshooting info:
The server responds to pings from the host machine
a port sniffer verifies that the port is open
running netstat -ntlp | grep 8080 in the vm shows that the server is listening on 8080
My local hostsfile doesn't have any weird conflicts
I'm also forwarding 22 => 2222, and I can ssh in with no trouble
I've disabled the firewall on the host, and i don't believe there's one on the guest (iptables and ufw are disabled, at least)
I've set auto_correct: true in case there are conflicts (there aren't)
I know I could set up a private network, but I'd like to understand why this isn't working and how to troubleshoot it.
Any other ideas?
When running a server from within a VM, start the server on 0.0.0.0 instead of 127.0.0.1.
127.0.0.1 is only accessible to the local machine, which for a VM means nothing outside of the VM can reach it! 0.0.0.0 is accessible from anywhere on the local network, which to a VM includes the host machine.
The answer came from here: Connection Reset when port forwarding with Vagrant
(Which apparently got its answer from here: https://stackoverflow.com/a/5999945/738675)
With help from: https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1
Google-bait:
Here are the errors you might receive if this is the problem:
Chrome: "No data received"
Firefox: "The connection was reset - The connection to the server was reset while the page was loading."
Safari: "Safari can’t open the page [URL] because the server unexpectedly dropped the connection"
curl: "Empty reply from server"
In the /etc/hosts inside the VM, change line
127.0.0.1 localhost -> 0.0.0.0 localhost
and then restart server
This can also be a problem with your firewall on the vagrant machine. If you can curl the address while on the vagrant box, then check your firewalld settings or turn it off:
on CENTOS:
sudo service firewalld stop
Then you should update your firewalld settings and restart it ;)

Resources