{"id":1008,"date":"2015-01-02T08:58:05","date_gmt":"2015-01-02T08:58:05","guid":{"rendered":"http:\/\/cdblog.cdstealer.com\/?p=1008"},"modified":"2017-05-29T08:01:36","modified_gmt":"2017-05-29T07:01:36","slug":"block-countries-with-iptables","status":"publish","type":"post","link":"https:\/\/cdblog.cdstealer.com\/?p=1008","title":{"rendered":"Block countries with IPTables"},"content":{"rendered":"<p>I get an absolute battering from China on a daily basis with the occasional attack from France, Germany or the US. \u00a0Time to block countries :)<\/p>\n<p>First and foremost, make sure you have iptables installed, configured and working.<br \/>\nNext we'll install some additions:<\/p>\n<pre>emerge -av\u00a0xtables-addons\u00a0geoipupdate<\/pre>\n<p>You may need to remove some of the modules to allow xtables to install (depends on your setup). \u00a0This can be achieved by adding the following line to\u00a0\/etc\/portage\/make.conf:<\/p>\n<pre>XTABLES_ADDONS=\"=account =chaos =condition =delude =dhcpmac =fuzzy geoip =iface =ipmark =ipp2p =ipv4options =length2 =logmark =lscan =pknock =psd =quota2 =rawnat =steal =sysrq =tarpit =dnetmap =echo =gradm\"<\/pre>\n<p>I'm only interested in geoip, so I removed everything else.<\/p>\n<p>Make the directory where iptables will look for the database:<\/p>\n<pre>mkdir -p \/usr\/share\/xt_geoip\/<\/pre>\n<p>Execute the following to download the geoiplite databases:<\/p>\n<p>If you have a paid account, you could potentially replace the URLs in the download script (untested)<\/p>\n<pre>cd \/usr\/share\/xt_geoip\/ &amp;&amp; \/lib64\/xtables-addons\/xt_geoip_dl &amp;&amp; \/lib64\/xtables-addons\/xt_geoip_build *.csv<\/pre>\n<p>You could cron this as a weekly update.<\/p>\n<p>xt_geoip_dl: Downloads the CSV database files<br \/>\nxt_geoip_build: Processes the files into a format iptables can read.<\/p>\n<p>\/usr\/share\/xt_geoip\/LE\/&lt;country abbreviation&gt;.iv4 &amp; .iv6<\/p>\n<p>Now you can block countries using iptables<\/p>\n<pre>iptables -A INPUT -m geoip --src-cc CN -j DROP<\/pre>\n<p>An\u00a0<strong>iptables -L -n<\/strong> will show<\/p>\n<pre>DROP all -- 0.0.0.0\/0 0.0.0.0\/0 -m geoip --source-country CN<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I get an absolute battering from China on a daily basis with the occasional attack from France, Germany or the US. \u00a0Time to block countries :) First and foremost, make sure you have iptables installed, configured and working. Next we'll install some additions: emerge -av\u00a0xtables-addons\u00a0geoipupdate You may need to remove some of the modules to &hellip; <a href=\"https:\/\/cdblog.cdstealer.com\/?p=1008\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Block countries with IPTables<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[203,298,157],"class_list":["post-1008","post","type-post","status-publish","format-standard","hentry","category-gentoo","tag-country","tag-geoip","tag-iptables"],"_links":{"self":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/1008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1008"}],"version-history":[{"count":5,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/1008\/revisions"}],"predecessor-version":[{"id":1753,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/1008\/revisions\/1753"}],"wp:attachment":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}