How Block Certain IP Address in Apache Tomcat?

In general configuration first we might have HTTPD server in front of application servers.So all the redirection and blocking the ips can be done using redirect rules if we use HTTPD server.
In case we don't have any httpd server in front of our application, then how can use block certain IP address?. There are two ways we can achieve this. 1. We can use Custom filter in application and implement blocking of IP's as per our requirement 2. We can block the IP's in Tomcat server level using filter. In our example we are going to see how can we block the IP's in tomcat level.In order to achieve this we need to do some changes in web.xml.

    <filter-name>Remote IP Filter</filter-name>

    <filter-name>Remote IP Filter</filter-name>

In above example two parameters are important first one is allow or deny and which means we wanted to reject the IP or allow the particular IP.Next parameter is what is the status needs to be send in case of rejection, if we are not specify any status code by default 403 will be send by the container.


Post a Comment

Powered by Blogger.