ip2location facebbook  ip2location twitter  ip2location google+ ip2location github

Apache Module

This is an IP2Location Apache Module that enables the user to identify the country, region, city, latitude, longitude, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type by IP address. It contains a demo IP2Location IP-COUNTRY BIN database which consists of real data for IP address range to This database contains IP address blocks as key and countries as values. The paid version of IP2Location database covers all IP address ranges. In general, it is more complete, faster and more accurate than using reverse DNS lookups.

Developers can download other sample databases to evaluate other features such as region, city, latitude, longitude, zip code, ISP and domain name using the same Apache module.

Download Download   Source Source




  1. Download IP2Location C library at here.
  2. Decompress C library.
    tar xvfz ip2location-c-x.x.x.tar.gz
  3. Download and decompress Apache module.
  4. Get into working directory.
    cd ip2location-apache-x.x.x
  5. Start compilation.
    apxs2 -i -a -L /usr/local/lib/ -I ../ip2location-c-x.x.x/libIP2Location/ -l IP2Location -c mod_ip2location.c
  6. Add following lines into /etc/apache2/apache2.conf
    <IfModule mod_ip2location.c>
    	IP2LocationEnable On
    	IP2LocationDetectProxy <On|Off>
    	IP2LocationSetmode <ALL>
    	IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>


  1. Download IP2Location C library at here.
  2. Decompress C library using 7-zip or other compression tools.
  3. Download and decompress Apache module.
  4. Navigate to ip2location-apache-x.x.x folder.
  5. Edit Makefile.win to change the path for C library.
    IP2LOCATION_CSRC_PATH = C:/ip2location-c-x.x.x/libIP2Location
    IP2LOCATION_CLIB_PATH = C:/ip2location-c-x.x.x/libIP2Location
    APACHE_INSTALL_PATH = "C:/Program Files/Apache Software Foundation/Apachex.x"
  6. Start compilation.
    nmake /f Makefile.win
  7. Copy IP2Location_apache.dll generated to Apache modules directory.
  8. Add following lines into httpd.conf
    <IfModule mod_ip2location.c>
    	IP2LocationEnable <ON|OFF>
    	IP2LocationDetectProxy <ON|OFF>
    	IP2LocationSetmode <ALL>
    	IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>


Module Settings
IP2LocationEnableON | OFF. Enable or disable the IP2Location Apache Module.
IP2LocationDetectProxyON | OFF. If enabled, the module will detect the proxy IP address from X-Forwarded-For server variable. If disabled, IP address is from REMOTE_ADDR server variable.
IP2LocationSetmodeALL | ENV | NOTES. ENV will set the environment variables; NOTES will set the Apache NOTES variables; ALL will set both the ENV and NOTES variables.
IP2LocationDBFileFull qualified path to the IP2Location BIN database file.


Sample Codes
Apache .htaccess
RewriteEngine On
RewriteRule ^(.*)$ http://www.google.co.uk [L]

Apache Mod Security
SecRule ENV:IP2LOCATION_COUNTRY_SHORT "NG|VN" "deny,status:500,id:5000888,msg:'Block visitor from Nigeria and Vietnam'"


Sample IP2Location Databases (BIN)

The following evaluation copy of the database file has limited range of IP address information compare to commercial. For evaluation purpose, you can query IP addresses from (IPv4) or 2A04:0:0:0:0:0:0:0-2A04:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF (IPv6).

Sample Packages IPv4 IPv6
IP2Location DB1 Sample Bin File679.73 kB350.84 kB
IP2Location DB2 Sample Bin File37.69 MB378.66 kB
IP2Location DB3 Sample Bin File19.55 MB363.65 kB
IP2Location DB4 Sample Bin File54.14 MB388.27 kB
IP2Location DB5 Sample Bin File29.71 MB370.18 kB
IP2Location DB6 Sample Bin File63.78 MB393.44 kB
IP2Location DB7 Sample Bin File60.12 MB398.64 kB
IP2Location DB8 Sample Bin File70.10 MB403.55 kB
IP2Location DB9 Sample Bin File34.33 MB373.45 kB
IP2Location DB10 Sample Bin File75.59 MB408.65 kB
IP2Location DB11 Sample Bin File35.01 MB374.17 kB
IP2Location DB12 Sample Bin File76.13 MB409.59 kB
IP2Location DB13 Sample Bin File33.51 MB371.65 kB
IP2Location DB14 Sample Bin File77.47 MB410.29 kB
IP2Location DB15 Sample Bin File37.98 MB378.07 kB
IP2Location DB16 Sample Bin File82.04 MB415.93 kB
IP2Location DB17 Sample Bin File40.49 MB380.09 kB
IP2Location DB18 Sample Bin File89.27 MB425.95 kB
IP2Location DB19 Sample Bin File72.85 MB404.88 kB
IP2Location DB20 Sample Bin File91.67 MB427.07 kB
IP2Location DB21 Sample Bin File41.36 MB380.72 kB
IP2Location DB22 Sample Bin File95.58 MB430.11 kB
IP2Location DB23 Sample Bin File73.31 MB405.90 kB
IP2Location DB24 Sample Bin File96.54 MB431.79 kB