Current status!
I managed to fix the geoip database for xtables:
Code:
aptitude install libtext-csv-xs-perl xtables-addons-common # added xtables-addons-common for completeness of the example
mkdir -p /var/geoip/LE /usr/src/GeoIP
wget -O /usr/src/GeoIP/GeoIPCountryCSV.zip http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
wget -O /usr/src/GeoIP/csv2bin-20041103.tar.gz http://people.netfilter.org/peejix/geoip/tools/csv2bin-20041103.tar.gz
wget -O /usr/src/GeoIP/xtables-addons-1.21.tar.bz2 http://downloads.sourceforge.net/project/xtables-addons/1.21/xtables-addons-1.21.tar.bz2
cd /usr/src/GeoIP
tar xf csv2bin-20041103.tar.gz unzip GeoIPCountryCSV.zip
Also put the following perl file in the /usr/src/GeoIP directory (filename: geoip_csv_iv0.pl)
Code:
#!/usr/bin/perl
#
# Converter for MaxMind CSV database to binary, for xt_geoip
# Copyright © Jan Engelhardt <jengelh@medozas.de>, 2008
#
# Use -b argument to create big-endian tables.
#
use Getopt::Long;
use IO::Handle;
use Text::CSV_XS; # or trade for Text::CSV
use strict;
my %country;
my %names;
my $csv = Text::CSV_XS->new({binary => 0, eol => $/}); # or Text::CSV
my $mode = "VV";
&Getopt::Long::Configure(qw(bundling));
&GetOptions("b" => sub { $mode = "NN"; });
while (my $row = $csv->getline(*ARGV)) {
if (!defined($country{$row->[4]})) {
$country{$row->[4]} = [];
$names{$row->[4]} = $row->[5];
}
my $c = $country{$row->[4]};
push(@$c, [$row->[2], $row->[3]]);
if ($. % 4096 == 0) {
print STDERR "\r\e[2K$. entries";
}
}
print STDERR "\r\e[2K$. entries total\n";
foreach my $iso_code (sort keys %country) {
printf "%5u ranges for %s %s\n",
scalar(@{$country{$iso_code}}),
$iso_code, $names{$iso_code};
open(my $fh, ">".uc($iso_code).".iv0");
foreach my $range (@{$country{$iso_code}}) {
print $fh pack($mode, $range->[0], $range->[1]);
}
close $fh;
}
And we continue:
Code:
cd /usr/src/GeoIP/csv2bin
make
cd /var/geoip
/usr/src/csv2bin/csv2bin /usr/src/GeoIP/GeoIPCountryWhois.csv
cd /var/geoip/LE
perl /usr/src/GeoIP/geoip_csv_iv0.pl /usr/src/GeoIP/GeoIPCountryWhois.csv
Ok the database is made.
But now we have a nasty problem:
Code:
root@orestes:~# iptables -A INPUT -p tcp -m geoip --src-cc CN -j DROP
iptables: No chain/target/match by that name.
Iptables does not recognize geoip as match module.
Code:
root@orestes:~# cat /proc/net/ip_tables_matches
multiport
multiport
recent
udplite
udp
tcp
state
icmp
Iptables -m geoip --help does show geoip related help.
I also don't see it in lsmod:
Code:
root@orestes:~# lsmod
Module Size Used by
xt_multiport 2794 0
xenfs 6105 1
xt_recent 8218 0
xt_tcpudp 2667 13
nf_conntrack_ipv6 12770 11
nf_conntrack_ipv4 12742 12
nf_defrag_ipv4 1481 1 nf_conntrack_ipv4
xt_state 1490 23
nf_conntrack 73326 3 nf_conntrack_ipv6,nf_conntrack_ipv4,xt_state
ip6t_LOG 5649 2
ipt_LOG 5370 2
ip6table_filter 1712 1
ip6_tables 19428 2 ip6t_LOG,ip6table_filter
iptable_filter 1841 1
ip_tables 18201 1 iptable_filter
lp 9336 0
x_tables 22361 8 xt_multiport,xt_recent,xt_tcpudp,xt_state,ip6t_LOG,ipt_LOG,ip6_tables,ip_tables
parport 37160 1 lp
xen_netfront 17890 0
xen_blkfront 10697 5