RadarURL

유닉스/리눅스
2014.10.20 18:25

CentOS에서 Iptables 방화벽 포트 OPEN하기

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

단축키

Prev이전 문서

Next다음 문서

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

단축키

Prev이전 문서

Next다음 문서

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

CentOS 에서는 Install을 하는경우 자동적으로 Iptables 방화벽이 설치되는 것 같다.

 

그럼 우선 설치다하고 나서 WAS , MYSQL 등등의 Setting 후 외부에서 접속하는 방법에 대해서 알아보자.

 

[1] 방화벽 설정파일은 어디있는가?

아래 경로를 보면 방화벽 설정파일을 열어볼 수가 있다.

 # vim /etc/sysconfig/iptables

 

[2] 설정파일을 대충 파악하자.

# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

 

(노랑색) 위 설정을 보면 22번 sshd port가 현재 열려있는것을 확인가능하다.

(파랑색) 또한 22번 이외의 다른 것들은 모두 막아라 라는 코드가 있다.

 

그럼 3306,21,80 포트를 를 추가하여 보자.

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 

 

위 처럼 포트를 추가하고 저장한다음 잘 추가되었는지 보도록 하자.

 

단!! 주의사항은 위 파랑색으로 된 -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited

요코드드는 삭제한 후에 해야 한다 그럼 다음과 같이 되겠죠?

 

 

 # Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

COMMIT

 

자 , 이제 iptables가 잘 적용이 되었는지 확인해 보도록 하자.

 

 

[root@localhost sysconfig]# 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     esp  --  anywhere             anywhere
ACCEPT     ah   --  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
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ftp
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:mysql
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http

[root@localhost sysconfig]# 

 

위 보는바와 같이 적용이 잘 되었다. 이제 데몬을 재시작 하도록 하자.

 

 # /etc/init.d/iptables restart

 

 

다시 이제 방화벽을 적용해야 한다, 아까 위에서 빼버린 코드를 넣고 다시금 재시작 하도록 한다.

-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited 코드 추가함

 

최종 적으로 , 다시 iptables -L 명령어를 통해 보도록 하자.

 

 

[root@localhost sysconfig]# 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     esp  --  anywhere             anywhere
ACCEPT     ah   --  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
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ftp
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:mysql
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

 

위 코드에서 보듯이 다시금 reject를 통해서 방화벽이 추가된 것을 확인할 수 있따.

 

이상이 IPTABLES의 PORT를 여는 방법에 대해서 서술 하였다.

 

 

                                                                            - 2012.07.02 랑이씀 -


출처 : http://srzero.tistory.com/entry/CentOS-Iptables-방화벽-포트-OPEN하기

?

공부 게시판

공부에 도움되는 글을 올려주세요.

  1. [공지] 공부 게시판 입니다.

    Date2003.08.18 By처누 Views2010664
    read more
  2. 강남건전지❤️OlO-8655-OO53❤️친절문의환영 #강남건전지 #강남유니콘 #선릉유니콘 #강남건전지위치 #선릉역건전지#대치동유니콘 #강남바커스 #선릉바커스 #선릉역바커스 #강남룸클럽 #선릉룸클럽 #강남베터리 #강남바데리

    Date2026.10.05 Category데이터베이스 By괴랄한재규어89 Views1
    Read More
  3. 용인두피문신 고민? 만족 후기 보려면

    Date2026.10.05 Category사무 소프트웨어 By날카로운꿩11 Views8
    Read More
  4. 웨딩누브라, 완벽한 드레스 핏을 위한 선택

    Date2026.10.05 Category윈도우즈 By날카로운감시자22 Views4
    Read More
  5. 인천맛집 순위

    Date2026.10.05 Category가상화 By차가운파편97 Views2
    Read More
  6. 손목터널증후군 치료, 현명한 선택 기준은?

    Date2026.10.05 Category웹서버,WAS By괴상한두루미52 Views1
    Read More
  7. 최근 테헤란로 벤처 밸리의 핵심 리더들 사이에서 ‘클래스가 다른 정통 수질과 프라이빗 무드’로 소문 자자한 '선릉 룸싸롱' 기습 방문, 인공미를 거부하는 무결점 뉴페이스들과 심장을 마비시킨 사심 플러팅에 제대로 저격당하고 온 솔직 후기

    Date2026.10.05 Category가상화 By희미한홍학99 Views4
    Read More
  8. 카­톡 gusim8003 급전/내구제 (24시문의) 선불폰 소액결제 일수 급전대출

    Date2026.10.05 Category웹서버,WAS By황금빛섬광82 Views2
    Read More
  9. 흥신소 선택 가이드

    Date2026.10.05 Category데이터베이스 By흔들리는골렘32 Views2
    Read More
  10. 양산싱크대막힘 완벽 해결 뚫자하수구

    Date2026.10.05 Category윈도우즈 By몽환적인태양핵44 Views1
    Read More
  11. 양산싱크대막힘 신속 해결의 모든 것

    Date2026.10.05 Category가상화 By조용한치타58 Views4
    Read More
  12. 카카오*톡 gusim8003 내구제대출/상조내구제 [24시문의] 선불유심 대출 폰내구제 가개통

    Date2026.10.05 Category유닉스/리눅스 By하얀라마72 Views7
    Read More
  13. 종로구가라오케 010 2817 0845 종로구 가라오케 예약 및 문의

    Date2026.10.04 Category윈도우즈 By흐릿한분석가84 Views10
    Read More
  14. 성공적인 중고화물차 선택 가이드

    Date2026.10.04 Category가상화 By붉은불꽃77 Views5
    Read More
  15. 센텀르엘, 하이엔드 라이프의 새로운 기준

    Date2026.10.04 Category데이터베이스 By검은파편81 Views6
    Read More
  16. 양산싱크대막힘 완벽 해결 뚫자하수구

    Date2026.10.04 Category가상화 By매혹적인곰18 Views5
    Read More
  17. 동탄 미시보다 자극적 첫사랑보다 그리운 마블 노래클럽 010++8293++0291

    Date2026.10.03 Category사무 소프트웨어 By광휘의퀘이사47 Views3
    Read More
  18. 탄현동노래방 탄현동에서 찾는 노래방 010 2817 0845

    Date2026.10.03 Category웹서버,WAS By울리는고래상어65 Views15
    Read More
  19. [Rocky Linux 9] /home 용량 줄이고 /root 용량 늘리기

    Date2026.04.03 Category유닉스/리눅스 ByYooN Views3802
    Read More
  20. [Rocky Linux] LVM 환경에서 /root 파티션 공간 부족 해결

    Date2026.04.03 Category유닉스/리눅스 ByYooN Views4177
    Read More
  21. 일반적인 Htaccess 301 리디렉션 규칙

    Date2026.04.01 Category웹서버,WAS ByYooN Views4182
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 36 Next
/ 36


즐겨찾기 (가족)

JAESOO's HOMEPAGE


장여은 홈페이지


장여희 홈페이지


장여원 홈페이지


즐겨찾기 (업무)

알리카페 홀릭

숭실대 컴퓨터 통신연구실 (서창진)

말레이시아 KL Sentral 한국인 GuestHouse


즐겨찾기 (취미)

어드민아이디

유에코 사랑회

아스가르드 좋은사람/나쁜사람

JServer.kr

제이서버 메타블로그

재수 티스토리


즐겨찾기 (강의, 커뮤니티)

재수 강의 홈페이지


한소리


VTMODE.COM


숭실대 인공지능학과


숭실대 통신연구실


베너