Tag Archives: maxmind

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.

GeoIP – Converting IPs to Physical Locations. | locate based on IP geoip maxmind tracing

I manage a large scale SSH server. This server is open to the world via SSH port 22.

Considering I only have Australian clients I would expect only Australian IP’s connected to it, so how would I know?

You can google the IP but that is a manual time consuming process. So I have automated it!

There is a open source tool called GeoIP. Its available by default on Debian and Redhat based distros. Install it with the following method.

Debian

 

Redhat

 

Usage

 

As you can see above, it resolves IP to country. This was perfect for the work I was doing but if you want specific city and GPS coordinates you need to download a higher detailed database from Maxmind.

So to update the database perform the following.

 

Now that you have the new database, you need to advise Geoip of the new database file.

Usage

As you can see, more detail than before.