|
NAMEipup - ipdb -
ipdb-update.sh —
Tools for generating IP based Geo-blocking and Geo-routing
tables in order to configure the system's firewall and/or routing facilities
SYNOPSIS
DESCRIPTIONIn general, access control by the firewall is established by selectors that can be attributed to incoming and outgoing IP packets, like physical interfaces on which the packets are going, source and destination IP addresses, protocol types, port numbers, content types and content, etc., and routing is determined by destination IP addresses. The Geo-location would be just another selector, but this information is not carried explicitly with IP packets, however, it can be obtained using the IP address as a key for looking-up the location in an IP database. For example, the country to which a given IP address is delegated, can be obtained with the common Unix tool whois(1).whois does an online look-up in the IP databases of the 5 Regional Internet Registries (AFRINIC, APNIC, ARIN, LACNIC, RIPENCC), and this is the most reliable way to obtain the country code for a given IP address, because the RIR's are the authorities for internet number delegations. Unfortunately, online database look-up is by far too slow for even thinking about being utilized on the firewall level, where IP packets need to be processed in a microsecond time scale. Therefore, a locally maintained IP Geo-location database is indispensable in the given respect. The System's own routing and filtering tables can be configured to do these tasks if there is a source of the appropriate data. The ipdbtools(1) are designed to provide this data and to assist managing and using it. The three tools in the package are:
Setting up the local IP Geo-location tablesThe authoritative IP Geo-location information must be obtained from the 5 RIR's, and compiled into an optimized format, suitable for quickly looking-up the country codes of given IP addresses. This information is present in so called delegation statistics files on the ftp servers of each RIR, and APNIC, LACNIC and RIPENCC mirror the files of the other RIR's on their servers - as of the date of this writing, ARIN and AFRINIC do not mirror current delegation statistics of the other RIR's.1) Choose one of the three useful mirror sites, depending on where you are located:
2) As user root execute the shell script ipdb-update.sh with the chosen mirror as the parameter, for example ftp.apnic.net: # ipdb-update.sh ftp.apnic.net
As shown above, this will download the delegation statistics data together with MD5 hashes for integrity checking into the directory /usr/local/etc/ipdb/IPRanges/. Then the ipdb tool will process the data files and generate two binary sorted table (.bst) files, one for the IPv4 ranges /usr/local/etc/IPRanges/ipcc.bst.v4 and another one for the IPv6 ranges /usr/local/etc/IPRanges/ipcc.bst.v6. USAGE AND OPTIONSQuering the local IP Geo-location tablesUse the
EXAMPLESCheck whether the IP Geo-location tables are ready by looking-up some addresses using theipup tool:
$ ipup 62.175.157.33
$ ipup 141.33.17.2
$ ipup 99.67.80.80
$ ipup 192.168.1.1
$ ipup 2001:0618:85a3:08d3:1319:8a2e:0370:7344
Firewall Examplesipup can be used for Geo-blocking together with
ipfw(8). For this purpose, ipup would generate
tables of CIDR ranges for the selected country codes, and these tables can be
directly piped into ipfw(8). The respective configuration script may
contain something like:
...
OR vice versa: ...
In the case of a different firewall facility, a plain table
(without ipfw directives) can be generated using
# Output data in the format of some other fictional firewall:
OR /usr/local/bin/ipup -p -t US:CA | while read TABLE NUM ADD ADDR VAL; do myfirewall add filter $ADDR value $VAL; done Routing Exampleipup is well suited for manipulating the system's
routing table by the way of the route(8) utility:
... # Force packets to Austria to take a different route: /usr/local/bin/ipup -p -t AT | while read LINE; do /sbin/route add $LINE $SOMEROUTER; done ... Cronjob for keeping the IP Geo-location tables updatedipdb-update.sh may be executed by a weekly (perhaps daily) cronjob, for this you might want to add the following entry to /etc/crontab:...
FILES
SEE ALSOwhois(1), ipfw(8), route(8)in Ports: ip2cc(1), IP::Country(3) AUTHORDr. Rolf Jansen - Copyright (c) 2016 - all rights reserved.IMPORTANT NOTEImproper use of the ipdb tools may result in erroneous IP tables, and firewalls or routers may be rendered non-functional once configured with incorrect tables.In NO event shall the author and/or copyright owner be liable for ANY damages resulting from ANY use of this software. Use the ipdb tools at your own risk! BUGSThe ipdb tools have been carefully developed and tested. Anyway, the tools are provided without any expressed or implied warrantee of being 100 % bug free.
Visit the GSP FreeBSD Man Page Interface. |