{"id":1050,"date":"2019-12-07T10:54:08","date_gmt":"2019-12-07T19:54:08","guid":{"rendered":"\/blog\/?p=1050"},"modified":"2023-12-21T14:48:04","modified_gmt":"2023-12-21T05:48:04","slug":"wevo-11ac-nas-geoip-%ec%a0%81%ec%9a%a9%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/hasu0707.duckdns.org\/blog\/?p=1050","title":{"rendered":"[WeVO 11AC NAS] GeoIP \uc801\uc6a9\ud558\uae30"},"content":{"rendered":"\n<p>\uc544\ub798 \uc2a4\ud06c\ub9bd\ud2b8\ub97c \ub9ac\ub205\uc2a4\uc5d0\uc11c \uc2e4\ud589\ud558\uc5ec GeoIP DB\ub97c \ub9cc\ub4e0\ub2e4.<\/p>\n\n\n\n<p>\uc544\ub798 \uc2a4\ud06c\ub9bd\ud2b8\ub97c OpenWRT\uc5d0\uc11c \uc2e4\ud589\ud558\uc5ec GeoIP\ub97c \uc124\uce58\ud55c\ub2e4.<\/p>\n\n\n\n<p>download_geoip_in_pc.sh<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n######################################################################\n#\n# geolite2.license \uc900\ube44 \ubc29\ubc95\n#\n# 1.https:\/\/www.maxmind.com\/en\/account\/login \ub85c\uadf8\uc778 \uc9c4\ud589\n#\n# 2.\uc88c\uce21 Manage License Keys \uc120\ud0dd\n#\n# 3.\"Generate new license key\"\uc744 \ud074\ub9ad\ud558\uc5ec \ub77c\uc774\uc120\uc2a4 \uc0dd\uc131\n#\n# 4.\ub77c\uc774\uc120\uc2a4\uac00 \uc0dd\uc131\ub418\uba74 Account ID\uc640 License key\uac00 \ubcf4\uc5ec\uc9c0\ub294\ub370 \ub2e4\uc2dc \ubcfc \uc218 \uc5c6\uc73c\ubbc0\ub85c \ubc18\ub4dc\uc2dc \ucea1\uccd0 \ub610\ub294 GeoIP.conf \ub2e4\uc6b4\ub85c\ub4dc\n#\n# 5. geolite2.license \ub0b4\uc6a9 \uc608\uc81c\n# YOUR_LICENSE_KEY='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'\n#\n######################################################################\n\n######################################################################\n#\n# iptables\uc758 GeoIP \uc801\uc6a9\uc744 \uc704\ud55c \uad6d\uac00\ubcc4 DB \uc900\ube44 \uc791\uc5c5\n#\n######################################################################\nSCRIPT_NAME=`basename $0`\nTIMESTAMP_STR1=`date \"+%Y%m%d_%H%M%S\"`\nTIMESTAMP_STR2=`date \"+%Y%m%d\"`\nTIMESTAMP_STR3=`date \"+%Y-%m\"`\nCURRENT_DIR=`pwd -P`\n# \ubc84\uc804\uc740 \ubcc0\uacbd\ud558\uc9c0 \ub9d0\uac83!\nXTABLES_ADDONS_VER=\"2.15\"\n\n######################################################################\n#\n# Error Handling\n#\n######################################################################\nerror_exit()\n{\n  clear\n  echo \"${SCRIPT_NAME}: ${1:-\\\"Unknown Error\\\"}\" 1>&amp;2\n  exit 1\n}\n\n######################################################################\n#\n# \uc2e4\ud589\uc5d0 \ud544\uc694\ud55c \ud328\ud0a4\uc9c0 \uc124\uce58\n#\n######################################################################\napt_install() {\n  apt -y install libnetaddr-ip-perl\n  apt -y install libnet-cidr-lite-perl\n  apt -y install libtext-csv-xs-perl\n  apt -y install xtables-addons-common\n  apt -y install iptables-dev\n  apt -y install linux-headers-generic\n}\n\n######################################################################\n#\n# xtables-addons \ub2e4\uc6b4\ub85c\ub4dc\n# https:\/\/codeberg.org\/jengelh\/xtables-addons\n# https:\/\/inai.de\/projects\/xtables-addons\/\n#\n######################################################################\ndownload_xtables_addons() {\n  if [ -d xtables-addons-* ]\n  then\n    rm -rf xtables-addons-*\n  fi\n  if [ -f xtables-addons-${XTABLES_ADDONS_VER}.tar.xz ]\n  then\n    rm -f xtables-addons-${XTABLES_ADDONS_VER}.tar.xz\n  fi\n  wget --no-check-certificate \"https:\/\/inai.de\/files\/xtables-addons\/xtables-addons-${XTABLES_ADDONS_VER}.tar.xz\" -O \"xtables-addons-${XTABLES_ADDONS_VER}.tar.xz\"\n  if [ ! -f xtables-addons-${XTABLES_ADDONS_VER}.tar.xz ]\n  then\n    error_exit\n  fi\n  tar -xJf xtables-addons-*.tar.xz\n  rm -f xtables-addons-*.tar.xz\n}\n\n######################################################################\n#\n# dbip-country-lite-YYYY-MM.csv.gz \ub2e4\uc6b4\ub85c\ub4dc\n#\n######################################################################\ndownload_dbip_country_lite() {\n  rm -f dbip-country-lite-${TIMESTAMP_STR3}.csv.gz\n  wget --no-check-certificate \"https:\/\/download.db-ip.com\/free\/dbip-country-lite-${TIMESTAMP_STR3}.csv.gz\"\n  if [ ! -f dbip-country-lite-${TIMESTAMP_STR3}.csv.gz ]\n  then\n    error_exit\n  fi\n  gzip -d dbip-country-lite-${TIMESTAMP_STR3}.csv.gz\n}\n\n######################################################################\n#\n# \uc2e0DB > \uad6cDB\ub85c \ubcc0\ud658\ud558\uae30 \uc704\ud55c GeoLite2xtables \ub2e4\uc6b4\ub85c\ub4dc\n#\n######################################################################\ndownload_geolite2xtables() {\n  if [ -d GeoLite2xtables ]\n  then\n    rm -rf GeoLite2xtables\n  fi\n  git clone \"https:\/\/github.com\/mschmitt\/GeoLite2xtables.git\"\n  if [ ! -d GeoLite2xtables ]\n  then\n    error_exit\n  fi\n  if [ ! -f geolite2.license ]\n  then\n    echo \"geolite2.license not found.\"\n    error_exit\n  fi\n  cp -f geolite2.license GeoLite2xtables\n}\n\n######################################################################\n#\n# \uc2e0DB\ub97c \uad6cDB\ub85c \ubcc0\ud658\ud558\ub294 \uc791\uc5c5\n# https:\/\/github.com\/mschmitt\/GeoLite2xtables\n#\n######################################################################\nconv_geolite2xtables() {\n  if [ -d \/usr\/share\/xt_geoip ]\n  then\n    rm -rf \/usr\/share\/xt_geoip\n  fi\n  rm -f \/tmp\/GeoLite2-Country-Blocks-*\n  rm -f \/tmp\/CountryInfo.txt\n\n  mkdir -p \/usr\/share\/xt_geoip\/{BE,LE}\n  cd ${CURRENT_DIR}\/GeoLite2xtables\n  echo \"***********************00_download_geolite2\"\n  .\/00_download_geolite2\n  sync\n\n  echo \"***********************10_download_countryinfo\"\n  .\/10_download_countryinfo\n  sync\n\n  echo \"***********************20_convert_geolite2\"\n  cat \/tmp\/GeoLite2-Country-Blocks-IPv{4,6}.csv | .\/20_convert_geolite2 \/tmp\/CountryInfo.txt > \/usr\/share\/xt_geoip\/GeoIP-legacy.csv\n  sync\n\n  echo \"***********************xt_geoip_build\"\n  cd ${CURRENT_DIR}\/xtables-addons-${XTABLES_ADDONS_VER}\/geoip\n  .\/xt_geoip_build -D \/usr\/share\/xt_geoip \/usr\/share\/xt_geoip\/GeoIP-legacy.csv\n  sync\n\n  echo \"***********************tar -cvzf xt_geoip_all.tar.gz \/usr\/share\/xt_geoip\"\n  if [ -f \/usr\/share\/xt_geoip\/GeoIP-legacy.csv ]\n  then\n    rm -f \/usr\/share\/xt_geoip\/GeoIP-legacy.csv\n  fi\n  cd ${CURRENT_DIR}\n  rm -f xt_geoip_all.tar.gz\n  tar -czf xt_geoip_all.tar.gz \/usr\/share\/xt_geoip\n  sync\n  cd ${CURRENT_DIR}\n\n  echo \"***********************tar -cvzf xt_geoip_kr_only.tar.gz \/tmp\/xt_geoip_kr_only\"\n  mkdir -p \/tmp\/xt_geoip_kr_only\/usr\/share\/xt_geoip\/BE\n  mkdir -p \/tmp\/xt_geoip_kr_only\/usr\/share\/xt_geoip\/LE\n  cp -f \/usr\/share\/xt_geoip\/BE\/KR.iv4 \/tmp\/xt_geoip_kr_only\/usr\/share\/xt_geoip\/BE\n  cp -f \/usr\/share\/xt_geoip\/BE\/KR.iv6 \/tmp\/xt_geoip_kr_only\/usr\/share\/xt_geoip\/BE\n  cp -f \/usr\/share\/xt_geoip\/LE\/KR.iv4 \/tmp\/xt_geoip_kr_only\/usr\/share\/xt_geoip\/LE\n  cp -f \/usr\/share\/xt_geoip\/LE\/KR.iv6 \/tmp\/xt_geoip_kr_only\/usr\/share\/xt_geoip\/LE\n  cd \/tmp\/xt_geoip_kr_only\n  tar -czf ${CURRENT_DIR}\/xt_geoip_kr_only.tar.gz *\n  rm -rf \/tmp\/xt_geoip_kr_only\n  sync\n  cd ${CURRENT_DIR}\n}\n\n######################################################################\n#\n# \ub2e4\uc6b4\ubc1b\uc740 \ud30c\uc77c\ub4e4 \uc0ad\uc81c\n#\n######################################################################\nclean_data() {\n  cd ${CURRENT_DIR}\n  if [ -d xtables-addons-* ]\n  then\n    rm -rf xtables-addons-*\n  fi\n  if [ -d GeoLite2xtables ]\n  then\n    rm -rf GeoLite2xtables\n  fi\n  rm -f \/tmp\/GeoLite2-Country-Blocks-*\n  rm -f \/tmp\/CountryInfo.txt\n}\n\nrm -f xt_geoip_all.tar.gz\nrm -f xt_geoip_kr_only.tar.gz\nclean_data\napt_install\n#download_dbip_country_lite\ndownload_xtables_addons\ndownload_geolite2xtables\nconv_geolite2xtables\nclean_data<\/pre>\n\n\n\n<p>10_setup_geoip.sh<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/sh\ntar -C \/ -xvzf \/tmp\/xt_geoip_kr_only.tar.gz\nrm -f \/tmp\/xt_geoip_kr_only.tar.gz\necho TEST\necho iptables -A INPUT -m geoip --src-cc KR -j ACCEPT\niptables -A INPUT -m geoip --src-cc KR -j ACCEPT\necho iptables -A OUTPUT -p tcp --dport 80 -m string --algo bm --icase --string \"test string\"  -j ACCEPT\niptables -A OUTPUT -p tcp --dport 80 -m string --algo bm --icase --string \"test string\"  -j ACCEPT\nrm -f \/tmp\/10_setup_geoip.sh<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uc544\ub798 \uc2a4\ud06c\ub9bd\ud2b8\ub97c \ub9ac\ub205\uc2a4\uc5d0\uc11c \uc2e4\ud589\ud558\uc5ec GeoIP DB\ub97c \ub9cc\ub4e0\ub2e4. \uc544\ub798 \uc2a4\ud06c\ub9bd\ud2b8\ub97c OpenWRT\uc5d0\uc11c \uc2e4\ud589\ud558\uc5ec GeoIP\ub97c \uc124\uce58\ud55c\ub2e4. download_geoip_in_pc.sh 10_setup_geoip.sh<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1050","post","type-post","status-publish","format-standard","hentry","category-development_openwrt"],"_links":{"self":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1050"}],"version-history":[{"count":0,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1050\/revisions"}],"wp:attachment":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}