iptables

-m multiport で 複数のdport

--dport が複数ある場合、-m multiport --dports aa,bb,cc と書けばよろし。

例:

geoipで日本以外からのTCP 22番、80番、443番へのTCPはDROPする。

/sbin/iptables -A INPUT -p tcp -m tcp -m multiport --dports 22,80,443 --tcp-flags FIN,SYN,RST,ACK SYN -m geoip ! --source-country JP  -j DROP

geoipからGeoLite2へ

xtables-geoipでGeoLite2を使うために。

参考:https://github.com/mschmitt/GeoLite2xtables

  1. GeoLite2のGeoLite2-Country-CSV.zipを入手する。
  2. unzip GeoLite2-Country-CSV.zip
  3. # apt install libnetaddr-ip-perl libnet-cidr-lite-perl
  4. $ git clone https://github.com/mschmitt/GeoLite2xtables.git
  5. $ cd GeoLite2xtables
  6. $ ./10_download_countryinfo
  7. $ cat ../GeoLite2-Country-CSV_20191231/GeoLite2-Country-Blocks-IPv{4,6}.csv > GeoIP-legacy.csv
  8. # /usr/lib/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip GeoIP-legacy.csv