2009. 5. 23. 12:16 IT/리눅스 TIP
데비안 iptables 사용하기(IP 선별 허용)
내가 관리하는 데비안서버에서는 WEB과 FTP를 돌리고 있었다.
전문적인 관리자가 아닌지라 자주 보안업데이트를 해 주는 것도 아니고, 보안에 대해서 그렇게 잘 안다고 할 수는 없었다.
그렇지만 언제나 골치아픈 중국아닌가....
그래서 나는 특정대역외의 IP에서는 아예 접근을 하지 못하게 하고 싶었다.
이런 때 유용한 것이 iptables 패키지였다.
=========================================================================
#!/bin/sh
case "$1" in
start)
echo "iptables start"
iptables-restore /etc/iptables.conf
;;
stop)
echo "iptables stop"
iptables -F
iptables -t nat -F
;;
restart)
echo "iptables stop"
iptables -F
iptables -t nat -F
echo "iptables start"
iptables-restore /etc/iptables.conf
;;
esac
exit 0
debian:/etc# iptables-save -t > iptables.conf
debian:/etc# more /etc/iptables.conf
=========================================================================
# Generated by iptables-save v1.2.11 on Mon Oct 23 13:43:39 2006
*filter
:INPUT ACCEPT [416:26453]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [409:229792]
-A INPUT -i lo -j ACCEPT
#ntp allow
-A INPUT -p udp --dport 123 -j ACCEPT <==서버의 시간을 동기화하기 위해 ntp포트는 허용했다.
#대역 허용
-A INPUT -s xxx.1.0.0/255.255.0.0 -j ACCEPT
-A INPUT -s xxx.2.0.0/255.255.0.0 -j ACCEPT
-A INPUT -s xxx.3.0.0/255.255.0.0 -j ACCEPT
-A INPUT -s xxx.3.0.0/255.255.0.0 -j ACCEPT
-A INPUT -s xxx.4.0.0/255.255.0.0 -j ACCEPT
-------------중략------------------- <==실제로 사용되는 IP대역을 추가하면된다.
#그외 차단
-A INPUT -i eth0 -j DROP
COMMIT
# Completed on Mon Oct 23 13:43:39 2006
======데몬추가======
# /etc/init.d/iptables.sh restart
# update-rc.d iptables.sh defaults
======확인======
# iptables -L
target prot opt source destination
ACCEPT 0 -- anywhere anywhere
ACCEPT udp -- anywhere anywhere udp dpt:ntp
ACCEPT 0 -- xxx.1.0.0/16 anywhere
ACCEPT 0 -- xxx.2.0.0/16 anywhere
ACCEPT 0 -- xxx.3.0.0/16 anywhere
ACCEPT 0 -- xxx.4.0.0/16 anywhere
DROP 0 -- anywhere anywhere
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
# iptables -L -v <==실제 적용예이다.
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
3 286 ACCEPT 0 -- lo any anywhere anywhere
2544 193K ACCEPT udp -- any any anywhere anywhere udp dpt:ntp
-------------------------중략--------------------------
70006 38M DROP 0 -- eth0 any anywhere anywhere <==DROP된 패킷 수
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destinationChain OUTPUT (policy ACCEPT 324K packets, 49M bytes)
pkts bytes target prot opt in out source destination
주) 국내에 할당된 IP대역은 한국인터넷진흥원에서 알 수 있었다. 아마도 이런 할당 IP대역을 사용하여 다양한 룰 적용이 가능할 것이다.
참고사이트: http://ip.nida.or.kr/
IP대역 참고: http://ip.nida.kr/main.html 에서 IPv4/국내 IPv4주소 목록 혹은 관리대행자별 IPv4주소 목록
IP대역을 안다고 해도 RULE로 만들어 넣는 것은 쉬운 일은 아니었다. ㅜ_ㅜ 인터넷진흥원에서 시작IP~끝IP 이런 식으로 관리하고 있어서, 일일히 변환해야 했다.
'IT > 리눅스 TIP' 카테고리의 다른 글
리눅스/유닉스 텍스트 편집 명령어(요약) (0) | 2009.11.20 |
---|---|
데비안 iptables 사용하기(IP 선별 허용) (0) | 2009.05.23 |
promise raid카드 데비안에서 사용하기(첫번째) (0) | 2009.05.22 |
데비안 하드디스크 추가방법 (0) | 2009.05.22 |
promise raid카드 데비안에서 사용하기(두번째) (0) | 2009.05.22 |
데비안에서 rsync를 이용한 백업 (0) | 2009.05.22 |
댓글을 달아 주세요