Skip to content

조회 수 8786 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

#!/bin/sh

#iptables Path
iptables=/sbin/iptables

# SERVER IP 받아오기.
HOST_IP="`/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"
NETMASK="`/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $4}' | cut -d : -f 2`"

# rule delete
# 모두 지우고 다시 재설정합니다.
$iptables -F

######### 비정상적 패킷은 드롭시킨다. 로그에 남긴다. ###############
iptables -A FORWARD -m state --state INVALID -j DROP
iptables -A FORWARD -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
iptables -A FORWARD -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN,RST -j DROP

#iptables -A FORWARD -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit 5/minute -j LOG --log-level notice --log-prefix "NMAP-XMAS:"
#iptables -A FORWARD -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/minute -j LOG --log-level notice --log-prefix "SYN/FIN:"
#iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit 5/minute -j LOG --log-level notice --log-prefix "SYN/RST:"


#Drop RST/ACKs to limit OS detection through pinging
iptables -A FORWARD -p tcp --tcp-flags RST RST,ACK -j DROP
#iptables -A FORWARD -p tcp --tcp-flags RST RST,ACK -m limit --limit 5/minute -j LOG --log-level notice --log-prefix "RST/ACK:"

# INPUT Rules 설정
$iptables -Z INPUT
$iptables -P INPUT ACCEPT

# local 과 자기자신의 IP 는 허용.
$iptables -A INPUT -i lo -j ACCEPT
$iptables -A INPUT -s 도메인 -j ACCEPT

#  알 수 없는 패킷 즉,  NETWORK 상태가 INVALID 인 패킷들을 막아 버린다.
#  정상적인 접근에서는 나올 수 없는 상태.
$iptables -A INPUT -m state --state INVALID -j DROP

# ssh service
# ssh 접속 지역 지정.
$iptables -A INPUT -s 아이피.0.0/16 -p tcp --dport 22 -j ACCEPT
$iptables -A INPUT -s 아이피.0/24 -p tcp --dport 22 -j ACCEPT

# etc service
# 25(메일), 80(웹)은 모든 곳에서 ACCEPT 입니다. 반드시...
$iptables -A INPUT -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT
$iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT

# AUTH 는 서비스를 하지 않더라도 열어야 합니다. 클라이언트에서 요청합니다.
$iptables -A INPUT -p tcp --dport 113 -m state --state NEW,ESTABLISHED -j ACCEPT

# mysql
# 기본적으로 mysql 은 local에서만 접속하면 됩니다. DB 공유를 할 경우 대역 지정.
$iptables -A INPUT -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT

# mysql DB공유 대역설정
$iptables -A INPUT -s 아이피.0/24 -p tcp --dport 3306 -j ACCEPT

# ICMP service
# ping은 별 의미가 없지만...
$iptables -A INPUT -s 아이피.0.0/16 -p icmp --icmp-type echo-request -j ACCEPT

# 서버로 들어오는 SYN packet 을 모두 거절한다.
$iptables -A INPUT -p tcp --syn -j REJECT

# Drop All packet
# 원활한 서비스를 위해 65535 포트까지만 DROP 을 합니다. 물론 다 막아도 상관 없습니다.
$iptables -A INPUT -p tcp --dport 0:65535 -j DROP
$iptables -A INPUT -p udp --dport 0:65535 -j DROP
$iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT

# 각종 서비스들에 대해 최대의 성능을 발휘할 수 있도록 TOS 설정을 한다.
$iptables -t mangle -A OUTPUT -p tcp -s 0/0 --sport 80 -j TOS --set-tos 0x10
$iptables -t mangle -A OUTPUT -p tcp -d 0/0 --dport 22 -j TOS --set-tos 0x10
$iptables -t mangle -A OUTPUT -p tcp -d 0/0 --dport 21 -j TOS --set-tos 0x10
$iptables -t mangle -A OUTPUT -p tcp -d 0/0 --dport 20 -j TOS --set-tos 0x08
$iptables -t mangle -A OUTPUT -p tcp -s 0/0 --sport 23 -j TOS --set-tos 0x10

# 외부 서비스를 위한 설정. / udp service
# dns 상호 쿼리를 위해서...
#$iptables -A INPUT -p udp --sport 53 -m state --state ESTABLISHED -j ACCEPT

# TCP service
# ftp-data, 서버자체가 클라이언트가 될 경우...
$iptables -A INPUT -p tcp --dport 20 -m state --state NEW,ESTABLISHED -j ACCEPT
$iptables -A INPUT -p tcp --dport 20 -m state --state ESTABLISHED -j ACCEPT
$iptables -A INPUT -i eth0 -p tcp --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT

# ftp service
# ftp 를 이용할 수 있는 대역을 지정하였습니다. 좀더 세밀해 질 수 있겠죠.
#$iptables -A INPUT -s 아이피.0.0.0/8 -p tcp --dport 21 -j ACCEPT
#$iptables -A INPUT -s 아이피.0.0/16-p tcp --dport 21 -j ACCEPT
$iptables -A INPUT -s 아이피.0/24 -p tcp --dport 21 -j ACCEPT

# telnet
# telnet은 현재 서비스 하지 않습니다.
$iptables -A INPUT -s 아이피.0.0/16 -p tcp --dport 23 -j ACCEPT

# pop3s 를 이용하는 관계로 995번을 열고 있습니다.
#$iptables -A INPUT -p tcp --dport 995 -m state --state NEW,ESTABLISHED -j ACCEPT

# ip 대역 예제.
# ip 대역뿐만 아니라 아래와 같이 상태접속을 지정할 수도 있습니다.
$iptables -A INPUT -s 아이피.0.0/16 -p tcp --dport 23 -m state --state NEW,ESTABLISHED -j ACCEPT
$iptables -A INPUT -s 아이피.0.0/16 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
$iptables -A INPUT -s 아이피.0/24 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
$iptables -A INPUT -s 아이피.0.0/16 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT

# UDP service
# udp 서비스는 하나뿐이죠?
#$iptables -A INPUT -p udp --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT

echo -e "\nDone.\n"

exit;


<출처 : 세상을 향해 덤벼라... (http://skystory.kr)>

List of Articles
번호 제목 글쓴이 날짜 조회 수
68 간단한 보안 설정 (TCP Wrapper) ADMINPLAY 2009.05.22 8941
67 iptables 기본 ADMINPLAY 2009.05.22 8386
66 iptables/sysctl을 이용하여 DDOS SYN 공격 방어하기 ADMINPLAY 2009.05.28 9204
65 iptables 설정, centos64 설치 간단셋팅 ADMINPLAY 2009.05.28 8854
64 DDOS - iptables 방화벽 초간단 문서 ADMINPLAY 2009.05.28 12302
» 서버의 iptable 보안설정 일부분 ADMINPLAY 2009.05.28 8786
62 iptables 명령어로 ip 차단 법. ADMINPLAY 2009.05.28 9283
61 서버종합점검[리눅스] ADMINPLAY 2009.05.28 8367
60 iptables-connlimit & geoip 설치설정 ADMINPLAY 2009.05.28 10342
59 iptables 포트 포워딩 ADMINPLAY 2009.06.04 12037
58 pam_abl 을 통한 SSH 무작위 공격 방어 ADMINPLAY 2009.06.04 8731
57 mod_security 설치 2.X ADMINPLAY 2009.06.04 9410
56 리눅스용 백신 AVG ADMINPLAY 2009.06.04 9088
55 Tcpdump 사용법 ADMINPLAY 2009.06.06 11153
54 리눅스용 각종 보안도구 사이트모음 ADMINPLAY 2009.07.12 33653
53 Linux Security ADMINPLAY 2009.07.18 9749
52 SSL 인증서문제 ADMINPLAY 2009.07.19 9477
51 64bit 시스템에 ssl 설치 후 실행 시 X509_free 오류 ADMINPLAY 2009.07.19 9701
50 Apache 에 ModSecurity 모듈 설치하기 ADMINPLAY 2009.08.03 10539
49 find 명령어 활용(보안관련) ADMINPLAY 2009.08.08 9599
Board Pagination Prev 1 2 3 4 5 Next
/ 5

Copyright ADMINPLAY corp. All rights reserved.

abcXYZ, 세종대왕,1234

abcXYZ, 세종대왕,1234