1

Is there a way I can block entire countries by country code (such as RU and CN)?

Currently I have a UFW firewall rule enabled for every IP that tried to do shady stuff (logging in on SSH, searching for .php scripts on my nginx).

Is there a way I could block entire countries from accessing my SSH / Nginx?

This is my nginx access.log (in /var/log/nginx/access.log)

I'm trying to get a solution that blocks on country code, and not IP.

Kevin
  • 111

2 Answers2

2

This can be done if you have modsecurity-crs installed.

Big picture, you set up nation blocking in modsecurity by activating the Block Countries feature. You will need the GeoIP database.

Once that is working, you can also ban IP addresses from those countries by adding a modsecurity rule to fail2ban (if you have that installed).

If this approach sounds like it would work for you, ping me in comments and I can expand with details.

Organic Marble
  • 23,641
  • 15
  • 70
  • 122
1

You can use iptables to block the visitors by IP address.

For specific country IP address list, you can download it free from https://www.ip2location.com/free/visitor-blocker