banner
Lifestream
  • 전체 카테고리 (104)
    • Digital Life (40)
      • Picture (20)
      • Video (20)
    • Daily Life (20)
    • Game Life (5)
    • Code Life (18)
    • Information Life (19)
profile
Home Category Guestboook Notice
Manage Write
  • 전체 카테고리 (104)
    • Digital Life (40)
      • Picture (20)
      • Video (20)
    • Daily Life (20)
    • Game Life (5)
    • Code Life (18)
    • Information Life (19)
GTK_LeonHeart
Manage Write
구독하기 RSS 어두운 모드 밝은 모드
Code Life
리눅스 해외IP 차단하기~
2018. 9. 21. 00:15 · GTK_LeonHeart ·

 

 

리눅스 해외 IP 차단하기
 

우선은 아래 링크에서 국가별IP목록이 있는 파일을 받아줍니다.

GeoIPCountryCSV.zip
13.06MB

최신버전 다운로드는 아래링크 클릭

 

Free updated GeoIP legacy databases

Free updated GeoIP legacy databases Here you can find regularly updated versions of the discontinued GeoIP legacy databases. Many distributions still use old GeoIP libraries, so you might find these useful. I use these on many systems myself, so consider t

mailfud.org

위 링크에서 GeoIP-legacy.csv.gz 파일을 받아 압축을 풀어 사용하면 됩니다,

 

쉘 스크립트 작성 (특정 국가 차단용)
 

파일을 받았으면 리눅스의 특정 폴더에 복사한 후 VI편집기를 이용해서 아래와 같이 쉘 스크립트를 작성 해줍니다. 

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
DATA=./GeoIPCountryWhois.csv
IPT=/sbin/iptables
 
// 차단할 국가 China
for IPRANGE in `egrep "China" $DATA | cut -d, -f1,2 | sed -e 's/"//g' | sed -e 's/,/-/g'`
 
do
         $IPT -A INPUT -p all -m iprange --src-range $IPRANGE -j DROP
done
Colored by Color Scripter
cs

이렇게 작성 후 실행하면 중국IP가 차단됩니다.
하지만 이렇게 한국가씩 차단하기에는 만들어야 할 스크립트가 많지요.
그럴땐 아래의 코드를 사용하면 됩니다.

쉘 스크립트 작성 ( 해외IP 차단용)
 

역시 VI편집기를 이용해서 아래와 같이 쉘 스크립트를 작성 해줍니다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
# iptables init
sudo iptables -P INPUT ACCEPT
sudo iptables -F
echo "IPTABLES INIT SUCCESS"
 
BLOCK_LIST_FILE=./GeoIPCountryWhois.csv
echo "BLOCK LIST FILE = $BLOCK_LIST_FILE"
 
# ADD BLOCK TARGET LIST
ALLOW_TARGET_COUNTRY="Korea"
 
# REGIST BLOCK IP FOR LOOP
for IP_BANDWIDTH in `egrep -v $ALLOW_TARGET_COUNTRY $BLOCK_LIST_FILE | awk -F, '{print $1, $2}' | awk -F\" '{print $2"-"$4}'`
 
do
echo "STARTING!!"
sudo iptables -I INPUT -p all -m iprange --src-range $IP_BANDWIDTH -j DROP
done
 
sudo iptables -L
Colored by Color Scripter
cs

 

이렇게 작성 후 실행하면 한국IP를 제외한 모든 해외IP가 차단됩니다.^^

 
제 블로그의 내용이 도움이 되셨나요?

여러분의 공감과 댓글이 큰 힘이됩니다 :)

▼▼▼▼▼▼▼▼▼▼▼

 

 

저작자표시 비영리 (새창열림)
카테고리 다른 글
related
윈도우 해외 IP 차단하기~
related
[HTML] 접기버튼 + C소스보기!
related
[WinAPI] 01 PE 파일 분석-헤더분석
related
[WinAPI] 02 PE 파일 분석-Import 분석
more

Links

  • faviconLifstream NAS
  • faviconThe LAST Web page
  • favicon월반장의 바구니
  • favicon박수홍2 의 고전컴 세상
  • favicon패싱님 티스토리
  • favicon혼자 끄적이는 블로그
  • favicon땀똔즈 블로그
  • favicon변덕 심한 묘한오빠
  • faviconSONYLOVE
  • favicon북쉐프 로샤씨

Notice

  • thumbnail20.01.05 블로그 스킨 업데이트
  • thumbnail18.04.18 안녕하세요

Recent Posts

+ 더 보기

Recent Comments

GTK_LeonHeart
Game, Media , Life, Infomation.
Blog by GTK_LeonHeart Designed by Marshall K

티스토리툴바