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
번호 제목 글쓴이 날짜 조회 수
28 iptables 명령어로 ip 차단 법. ADMINPLAY 2009.05.28 9283
27 해외에서 접근하는 IP 차단하기 ADMINPLAY 2009.11.30 9257
26 웹취약점 점검 ADMIN 2008.11.25 9253
25 iptables/sysctl을 이용하여 DDOS SYN 공격 방어하기 ADMINPLAY 2009.05.28 9204
24 rootkit 검색 프로그램 rkhunter-1.2.9.tar.gz file ADMINPLAY 2009.09.22 9193
23 리눅스용 백신 AVG ADMINPLAY 2009.06.04 9088
22 홈페이지 변조 대처법 (FTP 계정을 이용한 아이프레임 코... ADMINPLAY 2009.10.15 9043
21 간단한 보안 설정 (TCP Wrapper) ADMINPLAY 2009.05.22 8941
20 홈페이지 보안 강화 도구(CASTLE) 보급 안내 1 file ADMINPLAY 2010.01.22 8925
19 iptables 설정, centos64 설치 간단셋팅 ADMINPLAY 2009.05.28 8854
18 iptables 옵션 및 상태 추적 테이블 및 rule ADMINPLAY 2009.11.30 8851
17 Kernel 2.4.23 버전 이하에 나온 ptrace 버그에 관한 사항 ADMINPLAY 2009.12.13 8797
» 서버의 iptable 보안설정 일부분 ADMINPLAY 2009.05.28 8786
15 시스템 로그를 메일로 - logcheck file ADMINPLAY 2009.09.08 8772
14 LINUX 해킹당했을 때 대처요령 l2zeo 2010.03.08 8731
13 pam_abl 을 통한 SSH 무작위 공격 방어 ADMINPLAY 2009.06.04 8731
12 ZONE-H.KR ADMIN 2008.11.11 8542
11 Tcpdump 용어 정리 ADMINPLAY 2010.01.30 8505
10 SSH(Security SHell) 보안쉘 ADMINPLAY 2009.10.20 8404
9 SSH 공격막아내기 방법 l2zeo 2010.03.08 8391
Board Pagination Prev 1 2 3 4 5 Next
/ 5

Copyright ADMINPLAY corp. All rights reserved.

abcXYZ, 세종대왕,1234

abcXYZ, 세종대왕,1234