How to make Spring Boot application accessible by external IP address of the server?

Viewed 6697

I'm a newbie to Spring Boot. I have a REST API application written in Spring Boot. When I execute my Spring Boot JAR, everything is okay and I can access the REST API with the localhost address instead of the actual one:

http://localhost:8083/articles

But when I try to access the REST API by my external IP address, I can't do it:

http://100.90.80.70:8083/articles

netstat -antu command in the Linux terminal gives me the following output:

Active Internet connections (servers and established)
Proto   Recv-Q  Send-Q  Local Address  Foreign Address  State
tcp6       0      0      :::8083            :::*        LISTEN

As I understand, my app is accessible only in localhost, because it hasn't a foreign address.

My application.properties file has only this line:

server.port=8083

Also, when I try to add a server.address line to application.properties like that:

server.address=100.90.80.70
server.port=8083

I have the following Exception: Caused by: java.net.BindException: Cannot assign requested address.

So my question is: how to make Spring Boot application accessible by external IP address of the server? Thank you.

3 Answers

As @Mark said, the problem is in the firewall. I have opened 8083 port in the firewall settings and now I can access my REST API app by the external IP address:

http://100.90.80.70:8083/articles

Linux command to check firewall status:

sudo ufw status verbose

Open 8083 port for remote access by TCP protocol:

sudo ufw allow 8083/tcp

More settings here: https://www.cyberciti.biz/faq/how-to-open-firewall-port-on-ubuntu-linux-12-04-14-04-lts/

I fixed the same by configuring port forwarding on my router, to allow traffic from public ip

In my OpenStack environment, after much debugging, the solution was to create a new Security Group Rule, which looks like this: Security Group Rule.

Note that my Spring Boot application was deployed on port 8080. I also noticed that on ubuntu18 the firewall is disabled by default. It did not cause any problems.

Related