Search code examples
spring-boottomcatdebianportiptables

Spring Boot, Debian, Embedded Tomcat close external port


This is my Spring Boot application properties:

server.port: 8081

On Debian 9 I run Spring Boot war with Embedded Tomcat in the following way:

java -Dfile.encoding=UTF-8 -jar api-0.0.1.war

enter image description here

Right after that, I can access the application by the following url:

http://localhost:8081/api/v1.0

I'd like to close external access to 8081 port and leave only access to this port from the internal system.

I order to achieve this, I applied the following rule:

/sbin/iptables -A INPUT -p tcp --destination-port 8081 -j DROP
/sbin/service iptables save

but right now I'm unable to access url http://localhost:8081/api/v1.0 from another application on the same machine.

What am I doing wrong and how to fix it?


Solution

  • You need to allow the localhost post.

    iptables -A INPUT -p tcp -s localhost --destination-port 8081 -j ACCEPT