Question

Able to ssh to my droplet but unable to ping or call my services deployed on the droplet.

What I want to achieve

curl “http://128.199.27.21:9898/my_api

success response

The response I am getting

curl: (7) Failed to connect to 128.199.27.21 port 9898: Connection refused

What I have done so far

I just created an Ubuntu droplet, I am able to ssh to this droplet without any problem. Deployed my API, API calls are success if I do curl with localhost:port.

However when I try to call the API from my personal laptop it fails. I am unable to ping droplet’s IP from my personal laptop. I searched various websites for possible answers, found few solutions stating enabling/disabling and allowing particular IP using “ufw” but that solution is not working. I even tried modifiying Firewall rules through Digital Ocean Control Panel to allow inbound traffic for tcp/udp/ssh/http/https/icmp from all IPv4 and IPv6 but it isn’t working either.

OUTPUT:

lsof -i :9898

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
R        231   root   15u  IPv4  69259      0t0  TCP localhost:9898 (LISTEN)

ufw status

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
22/tcp                     ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
443/tcp                    ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
22/tcp (v6)                ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
443/tcp (v6)               ALLOW       Anywhere (v6)  

Even disabled ufw but it is still not working

Deleted the Firewall rules from DigitalOcean Control Panel still no response.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hi @rajeev29five:

@baraboom pointed out a critical issue in your API application. It must also listen on your droplet IP 128.199.27.21, not just localhost. Please reconfigure your application or modify its source code.

Also, if you want to enable UFW, add a new rule to allow incoming connections to your API application:

  1. sudo ufw allow to 128.199.27.21 port 9898 proto tcp

By default, UFW allows ping requests. If for some reason you are unable to ping your droplet, read this Ubuntu wiki page to learn how to enable ping requests.

baraboom
DigitalOcean Employee
DigitalOcean Employee badge
September 18, 2020

Hi! If you haven’t figured it out yet, you need to configure your service to bind to the IP address of the Droplet vs “localhost”

This line shows its only listening on localhost which is why your curl works:

R        231   root   15u  IPv4  69259      0t0  TCP localhost:9898 (LISTEN)

The key part of that line is localhost:9898, which is the “interface” and “port” combo.

To correct this, you can configure service via conf file or command flag when you start it to bind to the IP address of your droplet. When you’re done you should see something like 0.0.0.0:9898 (for any interface) or 192.168.1.55:9898 (whatever your Droplet IP is).

Hope this helps and if you’re still stuck, let us know what the underlying software is and we can see what is need to bind to the IP address.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel