You cannot see this page without javascript.

DDOS 방어

Linux 조회 수 462 추천 수 0 2016.09.19 09:33:53

 

이럴때 일반적으로는 아래와 같이 해당 IP주소만 차단하는게 일반적이다.

1
$ sudo /sbin/iptables -I INPUT -s 5.9.108.149 -j DROP

 

그러나 매번 그렇게 차단하는게 귀찮다고 생각해서 조금 검색을 해보니 좋은 방법이 있어 정리 및 공유해 본다.

1
iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j RETURN

 

모든 tcp 접속에 대해서 limit이 될때 까지 허용한다.

여기서 2가지 추가 옵션이 있는데

  • –limit 1/s : 초당 최대 평균 매치 값
  • –limit-burst 3 : 매칭되는 최대 패킷 수

이다. 이 숫자를 조금 변경해서 적용해 보았는데, limit 숫자를 늘렸을때, 공격이 감지 되지 않는 케이스도 많고 해서 그냥 쓰고 있다.

각 파라메터에 대한 설명은 아래와 같다.

  • ‐‐limit rate: Maximum average matching rate: specified as a number, with an optional ‘/second’, ‘/minute’, ‘/hour’, or ‘/day’ suffix; the default is 3/hour.
  • ‐‐limit‐burst number: Maximum initial number of packets to match: this number gets recharged by one every time the limit specified above is not reached, up to this number; the default is 5.

아래의 예제는 전체적으로 자동화 된, 공격 차단 룰이다.
핑 확인을 하는 경우, 로그에 기록하고 차단하는 룰도 포함되어 있다.

 

 
# Limit the number of incoming tcp connections
# Interface 0 incoming syn-flood protection
iptables -N syn_flood
iptables -A INPUT -p tcp --syn -j syn_flood
iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
iptables -A syn_flood -j DROP
#Limiting the incoming icmp ping request:
iptables -A INPUT -p icmp -m limit --limit  1/s --limit-burst 1 -j ACCEPT
iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
iptables -A INPUT -p icmp -j DROP
iptables -A OUTPUT -p icmp -j ACCEPT

 

그 이외에 ssh로 접속을 계속적으로 시도하는 해킹 시도는 아래의 룰을 적용하면 어느정도 막을 수 있다.
10분동안 10개 이상 커넥션을 맺지 못하도록 하는 스크립트이다.

 

 
iptables -I INPUT -p tcp -s 0/0 -d $SERVER_IP --sport 513:65535 --dport 22 -m state --state NEW,ESTABLISHED -m recent --set -j ACCEPT
iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 600 --hitcount 11 -j DROP
iptables -A OUTPUT -p tcp -s $SERVER_IP -d 0/0 --sport 22 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT

 

시간을 변경하고 싶으면, –seconds의 뒷자리 숫자를 변경하고,
횟수를 변경하고 싶으면, –hitcount의 뒷자리 숫자를 변경하면 된다.

엮인글 :
List of Articles
번호 제목 글쓴이 날짜sort 조회 수

HardWare 라우터 기본설정

  • LynX
  • 2013-09-28
  • 조회 수 261

SoftWare 공인 IP와 사설 IP

  • LynX
  • 2013-09-28
  • 조회 수 334

HardWare PacketTracer60_Build45 file

  • LynX
  • 2013-09-28
  • 조회 수 320

Server Windows7에 Apache 설치 file

  • LynX
  • 2013-09-05
  • 조회 수 299

Linux vi 명령어

  • LynX
  • 2013-09-02
  • 조회 수 235

Linux 리눅스 명령어 모음

  • LynX
  • 2013-09-02
  • 조회 수 1182

Linux 리눅스 부팅과정

  • LynX
  • 2013-08-26
  • 조회 수 346

Printer HP Photosmart B210

  • LynX
  • 2013-08-20
  • 조회 수 356

Windows 7 윈도우7(Windows7) 공유폴더에 암호걸기 file [7]

  • LynX
  • 2013-07-25
  • 조회 수 2092

HTML Tag Flowplayer [11]

  • LynX
  • 2013-07-20
  • 조회 수 773

Programing HTML5 부라우저별 Video코덱 및 포멧변경 [29]

  • LynX
  • 2013-07-20
  • 조회 수 2722

HTML Tag 모바일 웹에서 동영상 재생방법

  • LynX
  • 2013-07-13
  • 조회 수 682

Xpress Engine 게시판 -> 기본글 양식

  • LynX
  • 2013-07-11
  • 조회 수 337

Media PDF 파일을 JPG 으로 변환하기 - Free PDF to JPG Converter file

  • LynX
  • 2013-06-25
  • 조회 수 455

HTML Tag JWPlayer 사용법 #2 포맷 [14]

  • LynX
  • 2013-06-25
  • 조회 수 984

HTML Tag JWPlayer 사용법 #1 시작 file [7]

  • LynX
  • 2013-06-25
  • 조회 수 766

Printer HP Officejet Pro K8600 호환 드라이버 [10]

  • LynX
  • 2013-06-21
  • 조회 수 499

Windows XP 핫픽스 통합 시디 만들기 [18]

  • LynX
  • 2013-06-20
  • 조회 수 683

Windows XP USB로 XP 설치하기 file

  • LynX
  • 2013-06-20
  • 조회 수 433

Windows XP XP 원본 이미지에 AHCI 드라이버 통합 file [6]

  • LynX
  • 2013-06-20
  • 조회 수 1532

XE Login