Linux Iptables Just Block By Country

Linux Iptables Just Block By Country

Iptables is a powerful firewall utility that is included in many Linux distributions. It allows you to configure rules that control incoming and outgoing network traffic based on various criteria, such as IP addresses, port numbers, and protocol types.

To block traffic from a specific country using Iptables, you will need to use the geoip module, which allows you to specify rules based on the source or destination country of the traffic.

Here is an example of how to block incoming traffic from a specific country using Iptables:

  1. Install the xtables-addons-common package, which provides the geoip module:
refer to:‮tual‬turi.com
sudo apt install xtables-addons-common
  1. Load the geoip module:
sudo modprobe xt_geoip
  1. Create a new Iptables rule to block traffic from a specific country. For example, to block traffic from China, you can use the following command:
sudo iptables -A INPUT -m geoip --src-cc CN -j DROP

This command will block all incoming traffic from IP addresses in China. You can specify a different country code (e.g. US for the United States) to block traffic from a different country.

Keep in mind that this is just a basic example, and you can use the geoip module to specify more complex rules based on your specific needs. For more information on using the geoip module with Iptables, you can consult the documentation or seek guidance from the Linux community.

Created Time:2017-10-16 14:38:52  Author:lautturi