Software & AppsOperating SystemLinux

Fixing Elastic Search Connection Refused Error on Ubuntu Server

Ubuntu 21

In this article, we will delve into the common issue of the “Connection refused” error when trying to access Elasticsearch on an Ubuntu server. We will provide a step-by-step guide on how to diagnose and resolve this issue.

Understanding the Error

The “Connection refused” error usually occurs when you try to access Elasticsearch using the curl command like so:

curl -X GET "localhost:9200/"

This error indicates that the server is not accepting connections on the port you’re trying to access, which is 9200 in this case. There could be several reasons for this, such as Elasticsearch not running, incorrect network host configuration, firewall restrictions, or incorrect use of the curl command.

Checking if Elasticsearch is Running

The first step is to make sure that the Elasticsearch service is running. You can verify this by executing the following command:

sudo systemctl status elasticsearch.service

If Elasticsearch is not running, you can start it using this command:

sudo systemctl start elasticsearch.service

Checking the Network Host Configuration

If Elasticsearch is running but you’re still facing the error, the next step is to check the network host configuration. You can do this by opening the Elasticsearch configuration file located at /etc/elasticsearch/elasticsearch.yml.

In this file, locate the setting. By default, it is set to localhost. However, in some cases, you may need to modify it. Try changing it to _local_ or, save the file, and then restart Elasticsearch:

sudo systemctl restart elasticsearch.service

Verifying the Elasticsearch Port

The default port for Elasticsearch is 9200. You can confirm if Elasticsearch is listening on this port by checking the output of the following command:

netstat -natp | grep LISTEN

In the output, look for a line that shows or If you don’t see it, Elasticsearch might not be properly configured or running.

Checking Firewall or Security Group Restrictions

If you have a firewall or security group enabled, it might be blocking inbound connections on port 9200. You can check your firewall settings to ensure that it allows access to Elasticsearch. If you’re using UFW, you can allow access using the following command:

sudo ufw allow 9200

Verifying the Curl Command

Lastly, double-check the syntax of the curl command you are using. It should be:

curl -X GET "localhost:9200/"

If you are running the command from a different machine, replace localhost with the IP address or hostname of the Elasticsearch server.


By following these steps, you should be able to resolve the “Connection refused” error and successfully access Elasticsearch on your Ubuntu server. If you’re still facing issues, you may want to consult the Elasticsearch documentation or seek help from the Elasticsearch community.

Remember, it’s crucial to maintain your server’s health and ensure all services are running correctly for optimal performance. Regularly checking your server’s status and logs can help you identify and resolve issues promptly.

What is Elasticsearch?

Elasticsearch is a distributed, RESTful search and analytics engine built on top of Apache Lucene. It is designed for scalability and can handle large amounts of data.

How can I check if Elasticsearch is running on my Ubuntu server?

You can check if Elasticsearch is running on your Ubuntu server by executing the command sudo systemctl status elasticsearch.service. If Elasticsearch is running, you will see a status message indicating that it is active.

How can I start Elasticsearch if it is not running?

You can start Elasticsearch on your Ubuntu server by using the command sudo systemctl start elasticsearch.service. This will initiate the Elasticsearch service and make it accessible.

What should I do if changing the network host configuration does not resolve the “Connection refused” error?

If changing the network host configuration does not resolve the error, you can try checking the Elasticsearch port, firewall or security group restrictions, and the syntax of the curl command. These steps are outlined in the article and can help identify and fix the issue.

How can I allow access to Elasticsearch through the firewall using UFW?

You can allow access to Elasticsearch through the firewall using the command sudo ufw allow 9200. This will open port 9200 and allow inbound connections to Elasticsearch.

Can I access Elasticsearch from a different machine?

Yes, you can access Elasticsearch from a different machine by replacing localhost in the curl command with the IP address or hostname of the Elasticsearch server. For example: curl -X GET "".

Where can I find more information and help regarding Elasticsearch?

You can find more information and seek help regarding Elasticsearch in the Elasticsearch documentation and the Elasticsearch community forums. These resources provide comprehensive guides, tutorials, and a platform to ask questions and get assistance from the Elasticsearch community.

Leave a Comment

Your email address will not be published. Required fields are marked *