Tag Archives: blocking

Blocking All IPs Outside Your Country | iptables linux centos ubuntu blocking coutries

I want to block all traffic that does not originate from my country (Australia)

Best way to do this is using IPTables, Australia alone has around 4500 IP ranges to block.

What I did was download the ranges from Maxmind in CSV format, link

So we need to covert the format of the CSV file to a format IPTABLES can import, I wrote the following script.

Change the country name to match your country,  it will work.

This will produce the whitelist required to block all other IPs, you will also need to append a deny all at the end, so this.

IPTABLES blocking traffic outbound to a specific IP | iptables block ip hosts outbound

I was in a situation today where an application was talking to hosts it shouldn’t have. A quick way to stop this from happening was with iptables. Make sure you ping the host first before the rule and after to ensure it has taken affect.

The rule to block a specific IP is

To check the rule is in,

To remove the rule, the ‘1’ means the first line in the table, in this case this was the only outbound rule.