ÀÛ¼ºÀÏ : 10-06-07 18:59
¹æÈ­º® ¼³Á¤
 ±Û¾´ÀÌ : hereis
Á¶È¸ : 10,447  
   http://blog.bagesoft.com/712 [3368]
   http://blog.daum.net/_blog/BlogView.do?blogid=0FSvI&articleno=7913842#¡¦ [3325]
#>iptables -L
#>/etc/init.d/iptables status
µîµîÀ¸·Î ¿Ã¶ó ¿Â°ÍÀ» È®ÀÎÇÒ¼ö ÀÖÀ¾¼î...

iptables´Â µ¥¸óÀÌ ¾Æ´Ï¶ó. Ä¿³Î¿¡ ¿Ã¶ó¿Â netfilter ÀÇ ·êÀ» ¼¼¿öÁÖ°íº¸¿© ÁÖ´Â
±â´ÉÀÏ »ÓÀÌ´Ù.




¢Ã iptables ¼³Á¤

 

¹æÈ­º®ÀÔ´Ï´Ù~~

´ëºÎºÐ ¾Æ½Ç°Å¶ó°í »ý°¢ÇÏÁö¸¸ Áß¿äÇÑ Á¡Àº ±ÔÄ¢À» Á¤ÇÒ ¶§ÀÇ ¼ø¼­!!! ÀÔ´Ï´Ù.

IF ¸ðµç ÆÐŶÀ» °ÅºÎÇÏ´Â ±ÔÄ¢ÀÌ °¡Àå ¸ÕÀú ³ª¿Â´Ù¸é ±× ÀÌÈÄÀÇ ±ÔÄ¢Àº ¹«½Ã°¡ µÇ¾î¹ö¸³´Ï´Ù.

±×¸®ÇÏ¿© Çã¿ëµÇ´Â ±ÔÄ¢ÀÌ ¸ÕÀú ³ª¿À°í ³ªÁß¿¡ °ÅºÎÇÏ´Â ±ÔÄ¢À» Á¤ÀÇÇØ¾ß ÇÕ´Ï´Ù. ^^

 

- ±âº» ½Ã½ºÅÛ È¯°æÁ¶°Ç

1. ¿©·¯´ëÀÇ ¼­¹ö°¡ Á¸ÀçÇÕ´Ï´Ù.
2. °¢ ¼­¹ö°£¿¡´Â »ç¼³¾ÆÀÌÇÇ(192.168.0.x)·Î ³×Æ®¿öÅ·À» ÇÕ´Ï´Ù.
3. ¸ðµç À¥¼­¹ö´Â ´Ü ÇϳªÀÇ Å¬¶óÀÌ¾ðÆ®¿Í ´ÜÇϳªÀÇ À¥»çÀÌÆ®¸¦ ¿î¿µÇÑ´Ù.(Æ®·¡ÇÈÀÌ ³ôÀº »çÀÌÆ®¿¡¼­ L4¸¦ ÀÌ¿ëÇÑ ·Îµå¹ë·±½ÌÀ» Çϰí ÀÖ´Ù.)

- iptables¿Í hosts.deny, hosts.allow ¸¦ ÀÌ¿ëÇÑ ipÇã¿ë/Â÷´Ü¿¡ ´ëÇÑ °£·«ÇÑ ¼³¸í

ssh¸¦ ÀÌ¿ëÇÑ ¿ø°ÝÁ¢¼Ó
shell > ssh -l userid hostip

-- hosts.deny·Î ¾ÆÀÌÇÇ Â÷´Ü½Ã º¸¿©Áö´Â Çö»ó

¾Æ·¡ÀÇ ¸Þ½ÃÁö¸¦ ¶ç¿ì°í ssh Á¢¼Ó ¸ØÃã
ssh_exchange_identification: Connection closed by remote host

-- iptables ·Î Â÷´Ü½Ã º¸¿©Áö´Â Çö»ó
shell > ssh -l userid hostip

==> °è¼Ó ´ë±â»óÅÂ(¾ðÁ¦ ³¡³ª·Á³ª..??)

À̸¦ º¸¸é, hosts.deny·Î ¾ÆÀÌÇÇ/¼­ºñ½º¸¦ ¸·°Ô µÇ¸é ½Ã½ºÅÛ¿¡ Á¢¼ÓÇÏ¿© °ÅºÎ´çÇß°í, iptables·Î Â÷´ÜÇßÀ» °æ¿ì¿¡´Â ½Ã½ºÅÛ ÀÚü¿¡ Á¢¼ÓÀ» ÇÒ¼ö°¡ ¾ø´Ù.

º¸¾È°ü·Ã °øºÎ¸¦ ¾à°£ÀÌ¶óµµ ÇÑ»ç¶÷À̶ó¸é hosts.deny´Â ½Ã½ºÅÛ Â÷¿ø¿¡¼­ÀÇ blockÀ̰í, iptables´Â networkÂ÷¿ø¿¡¼­ÀÇ blockÀÌ´Ù.  network´Â physical °èÃþº¸´Ù ÇѴܰè À§ÀÇ °èÃþÀÓÀ¸·Î system¿¡¼­ ÇÏ´Â ÀÏÀ» network°¡ ´ë½ÅÇØ ÁÖ´Â °ÍÀÌ´Ù. ±×·¯¸é 2ÁßÀ¸·Î Â÷´ÜÇϴ°͵µ ÁÁÀ» °ÍÀÌ´Ù.


 

¡Þ ¿É¼Ç :

-A  üÀο¡ »õ·Î¿î ±ÔÄ¢ Ãß°¡
-D  üÀÎÀÇ ¾î¶² ÁöÁ¡ÀÇ ±ÔÄ¢ »èÁ¦
-F  üÀÎÀ¸·ÎºÎÅÍ ¸ðµç ±ÔÄ¢ »èÁ¦
-L  ¾î¶² üÀÎÀÇ ±ÔÄ¢ º¸±â

-I    üÀÎÀÇ ¾î¶² ÁöÁ¡¿¡ ±ÔÄ¢À» »ðÀÔ

-i    ( input interface, // i eth0 ´Â eth0·Î µé¾î¿À´Â ¸ðµç ÆÐŶ )

-o  ( output interface )

-R  üÀÎÀÇ ¾î¶² ÁöÁ¡ÀÇ ±ÔÄ¢À» ±³È¯

-s  Ãâ¹ßÁö ÁÖ¼Ò ( ÆÐŶ Ãâó IP ÁöÁ¤/µµ¸ÞÀÎ ¶Ç´Â 192.168.10.0/24 ó·³ ÁöÁ¤ÇÒ¼ö ÀÖ´Ù  )
-d  ¸ñÀûÁö ÁÖ¼Ò ( ÆÐŶ µµÂøÁö IP ÁöÁ¤ )
--sport  Ãâ¹ßÁö Æ÷Æ® ¹øÈ£ Á¦¾î
--dport  ¸ñÀûÁö Æ÷Æ® ¹øÈ£ Á¦¾î
-p  ÇÁ·ÎÅäÄÝ Á¦¾î ( p¿É¼ÇÀÇ ÀÎÀÚ´Â TCP,UDP,ICMP °¡ µÉ¼ö ÀÖ´Ù )
-j  ±ÔÄ¢ ¼³Á¤

 

 ¡Ø Âü°í

INPUT  Àº  ÆÐŶÀÌ µé¾î¿À´Â üÀο¡

DROP Àº ÆÐŶÀ» ¹ö¸®¶ó´Â ¶æ


iptables.sh¶ó´Â ¼¿½ºÅ©¸³Æ®¸¦ Çϳª »ý¼ºÇÏÀÚ.
--------------------------------------------------
#!/bin/sh

## iptables¸¦ ÃʱâÈ­
iptables -F

## ·£Ä«µå »ç¿ëÀ» ¸ðµÎ Çã¿ë
iptables -A INPUT -p ALL -i eth0 -j ACCEPT
iptables -A OUTPUT -p ALL -o eth0 -j ACCEPT
iptables -A INPUT -p ALL -i eth1 -j ACCEPT
iptables -A OUTPUT -p ALL -o eth1 -j ACCEPT

## TELNET Æ÷Æ® ¸·À½
iptables -A INPUT -p TCP --dport 23 -s ip¾Õ ¼¼ÀÚ¸®.0/24 -j ACCEPT
iptables -A INPUT -p TCP --dport 23 -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -p TCP --dport 23 -j DROP

## FTP Æ÷Æ® ¸·À½
iptables -A INPUT -p TCP --dport 21 -s ip¾Õ ¼¼ÀÚ¸®.0/24 -j ACCEPT
iptables -A INPUT -p TCP --dport 21 -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -p TCP --dport 21 -j DROP

## SSH Æ÷Æ® ¸·À½
iptables -A INPUT -p TCP --dport 22  -s ip¾Õ ¼¼ÀÚ¸®.0/24 -j ACCEPT
iptables -A INPUT -p TCP --dport 22  -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -p TCP --dport 22 -j DROP
--------------------------------------------------------
ÀÌ·¸°Ô ÆÄÀÏÀ» »ý¼ºÇؼ­ ½ÇÇà±ÇÇÑÀ» ºÎ¿© chmod 744 filename

¿©±â¼­´Â ´Ù¸¥ Æ÷Æ®´Â ½Å°æ¾²Áö ¸»°í  telnet, ftp, ssh ¸¸ °í·ÁÇß´Ù.
¸ðµç Æ÷Æ®¸¦ ¿­¾î µÐ »óÅ¿¡¼­(¾îÂ÷ÇÇ ´Ù¸¥ port´Â /etc/hosts.deny, hosts.allow¿¡¼­ ¶ÇÇѹø blockµÉ°ÍÀÌ´Ù.) telnet, ftp, ssh Æ÷Æ®´Â ƯÁ¤ip±º°ú »ç¼³¾ÆÀÌÇǸ¸ Çã¿ëÇÏ°í ³ª¸ÓÁö´Â ¸ðµÎ drop Çß´Ù. Á¤È®ÇÑ »ç¿ë¹ýÀ» ¸ð¸£´Â »óÅ¿¡¼­ ¸ðµç Æ÷Æ®¸¦ ºí·°ÇÑ »óÅ¿¡¼­ ½ÃÀÛÇÏ´Â °Íº¸´Ù´Â ¿­·ÁÀÖ´Â »óÅ¿¡¼­ ÇÊ¿äÇÑ Æ÷Æ®¸¦ Çϳª¾¿ ¸·¾Æ³ª°¡´Â°ÍÀÌ ÁÁÀ»µíÇÕ´Ï´Ù.
¡Ø service iptables save Çϸé ÇöÀç ·ê¼ÂÀÌ /etc/sysconfig/iptables ·Î ÀúÀåµÇ°í ¸®ºÎÆÃ ÈÄ¿¡µµ Àû¿ëµË´Ï´Ù.

 

- ¼³Á¤ ¿¹Á¦)

[root@bridge ~]# iptables -L              // ÇöÀç Á¤ÀÇµÈ ±ÔÄ¢ º¸¿©ÁÖ±â
Chain INPUT (policy ACCEPT)
target    prot opt source              destination
RH-Firewall-1-INPUT  all  --  anywhere            anywhere

Chain FORWARD (policy ACCEPT)
target    prot opt source              destination
RH-Firewall-1-INPUT  all  --  anywhere            anywhere

Chain OUTPUT (policy ACCEPT)
target    prot opt source              destination

Chain RH-Firewall-1-INPUT (2 references)
target    prot opt source              destination
ACCEPT    all  --  anywhere            anywhere
ACCEPT    icmp --  anywhere            anywhere            icmp any
ACCEPT    ipv6-crypt--  anywhere            anywhere
ACCEPT    ipv6-auth--  anywhere            anywhere
ACCEPT    udp  --  anywhere            224.0.0.251        udp dpt:mdns
ACCEPT    udp  --  anywhere            anywhere            udp dpt:ipp
ACCEPT    tcp  --  anywhere            anywhere            tcp dpt:ipp
ACCEPT    all  --  anywhere            anywhere            state RELATED,ESTABLISHED
ACCEPT    tcp  --  anywhere            anywhere            state NEW tcp dpt:ssh
REJECT    all  --  anywhere            anywhere            reject-with icmp-host-prohibited

 

[root@bridge ~]# iptables -F              // ±ÔÄ¢ ÃʱâÈ­
[root@bridge ~]# iptables -L
Chain INPUT (policy ACCEPT)
target    prot opt source              destination

Chain FORWARD (policy ACCEPT)
target    prot opt source              destination

Chain OUTPUT (policy ACCEPT)
target    prot opt source              destination

Chain RH-Firewall-1-INPUT (0 references)
target    prot opt source              destination

 

[root@bridge ~]# iptables -A INPUT -p icmp -s 127.0.0.1 -j DROP 
// Ãâ¹ßÁö°¡ 127.0.0.1ÀÎ (-s 127.0.0.1) icmp ÇÁ·ÎÅäÄÝ (-p icmp) ÆÐŶÀ» °ÅºÎ(-j DROP) ÇÏ´Â ±ÔÄ¢À» Ãß°¡(-A) ÇÕ´Ï´Ù.


[root@bridge ~]# iptables -L
Chain INPUT (policy ACCEPT)
target    prot opt source              destination
DROP      icmp --  bridge              anywhere

Chain FORWARD (policy ACCEPT)
target    prot opt source              destination

Chain OUTPUT (policy ACCEPT)
target    prot opt source              destination

Chain RH-Firewall-1-INPUT (0 references)
target    prot opt source              destination


[root@bridge ~]# ping 127.0.0.1          // ping ÀÌ ¸ÔÈ÷Áú ¾ÊÁÒ ¤»
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

--- 127.0.0.1 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 3999ms


[root@bridge ~]# iptables -A INPUT -p tcp --dport 23 -j DROP
// ¸ñÀûÁö Æ÷Æ®°¡ 23¹ø(--dport 23)À̰í tcp ÇÁ·ÎÅäÄÝ (-p tcp)ÀÎ ÆÐŶÀ» °ÅºÎ(-j DROP)ÇÏ´Â ±ÔÄ¢À» Ãß°¡(-A) ÇÕ´Ï´Ù.


 

[root@bridge ~]# iptables -L
Chain INPUT (policy ACCEPT)
target    prot opt source              destination
DROP      icmp --  bridge              anywhere
DROP      tcp  --  anywhere            anywhere            tcp dpt:telnet
// ÀÚµ¿À¸·Î 23¹øÆ÷Æ® telnet À¸·Î ¼³Á¤

Chain FORWARD (policy ACCEPT)
target    prot opt source              destination

Chain OUTPUT (policy ACCEPT)
target    prot opt source              destination

Chain RH-Firewall-1-INPUT (0 references)
target    prot opt source              destination


[root@bridge ~]# iptables -D INPUT 1
//INPUT ¶õÀÇ 2¹øÂ° (0,1,2...) ¼³Á¤À» »èÁ¦ ÇÏ´Â ±â´ÉÀÔ´Ï´Ù.


ºñÁî´Ï½º¡¤°æÁ¦, IT¡¤ÄÄÇ»ÅÍ