This blog is for those who already have web server running and facing DDoS attacks or hacking issues. There are different types of hacking, we are here not to discuss about the hacking. In this blog, we will tell how you can block the any country like China in the apache web server.
Using the below procedure, you can block any country. We are taking the China as a example as it houses the largest number of hackers on Earth.
We have Cent OS 7 and apache web server in this blog.
1. Login to the server with root user using Putty.
2. Install the GeoIP and mod_geoip.
# yum install mod_geoip GeoIP GeoIP-devel GeoIP-data zlib-devel
3. Open configuration file of the apache web server.
# vi /etc/httpd/conf/httpd.conf
4. Copy the below lines and paste it anywhere in the file.
<Location />
SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
Deny from env=BlockCountry
</Location>
5. Save and exit.
6. Restart the httpd service.
7. Now, no one can access any webiste on your server from China.
8. To block multiple countries or any other country add the line as we did below to block Russia along with China. You can change ISO code of country names as per you requirement.
<Location />
SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
Deny from env=BlockCountry
</Location>