RadarURL

유닉스/리눅스
2014.10.20 18:25

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

조회 수 1372 추천 수 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처누 Views928129
    read more
  2. [U2L] Unix to Linux 기대효과 분석

    Date2023.05.16 Category유닉스/리눅스 ByJaeSoo Views1259
    Read More
  3. 리눅스 inodes full 이슈 해결 방법

    Date2023.05.02 Category유닉스/리눅스 ByJaeSoo Views169
    Read More
  4. inode full

    Date2023.05.01 Category유닉스/리눅스 ByJaeSoo Views115
    Read More
  5. 마이크로서비스 아키텍처(MSA) 개념 소개

    Date2023.01.26 Category유닉스/리눅스 ByJaeSoo Views170
    Read More
  6. 리눅스(Linux) 디렉토리 구조

    Date2016.10.20 Category유닉스/리눅스 ByJaeSoo Views693
    Read More
  7. ssh서버가 비밀번호를 거부했습니다. 다시 시도하십시오.

    Date2016.08.23 Category유닉스/리눅스 ByJaeSoo Views302
    Read More
  8. [리눅스] IP 설정 변경 하기

    Date2016.08.23 Category유닉스/리눅스 ByJaeSoo Views326
    Read More
  9. 리눅스 설치후 초기설정해야 할 것들 [2]

    Date2016.07.13 Category유닉스/리눅스 ByJaeSoo Views400
    Read More
  10. 리눅스 설치후 초기설정해야 할 것들 [1]

    Date2016.07.13 Category유닉스/리눅스 ByJaeSoo Views360
    Read More
  11. 쉘 프로그래밍을 이용한 시스템 관리 기법

    Date2016.05.12 Category유닉스/리눅스 ByJaeSoo Views679
    Read More
  12. AIX 자주 쓰이는 관리 명령 모음

    Date2016.05.12 Category유닉스/리눅스 ByJaeSoo Views615
    Read More
  13. AIX 시스템상의 core, SMT(Simultaneous Multi Threading) 수 확인하기

    Date2016.05.12 Category유닉스/리눅스 ByJaeSoo Views695
    Read More
  14. 리눅스 호스트명 변경

    Date2016.05.11 Category유닉스/리눅스 ByJaeSoo Views728
    Read More
  15. AIX 서버 기초

    Date2016.05.11 Category유닉스/리눅스 ByJaeSoo Views631
    Read More
  16. AIX Admin Study 교육 자료

    Date2016.05.11 Category유닉스/리눅스 ByJaeSoo Views716
    Read More
  17. 성능 엔지니어링 대한 접근 방법 (Performance tuning)

    Date2016.05.05 Category유닉스/리눅스 ByJaeSoo Views874
    Read More
  18. Linux/Unix용 nmon 설치 및 구성

    Date2016.05.04 Category유닉스/리눅스 ByJaeSoo Views773
    Read More
  19. [AIX] 파일시스템 관리 (du, df)

    Date2016.05.04 Category유닉스/리눅스 ByJaeSoo Views770
    Read More
  20. IBM AIX Admin (사용자 DISK 관리)

    Date2016.05.04 Category유닉스/리눅스 ByJaeSoo Views686
    Read More
  21. [UNIX] 유닉스 기본명령어

    Date2016.05.04 Category유닉스/리눅스 ByJaeSoo Views562
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9


즐겨찾기 (가족)

JAESOO's HOMEPAGE


YOUNGAE's HOMEPAGE


장여은 홈페이지


장여희 홈페이지


장여원 홈페이지


즐겨찾기 (업무)

알리카페 홀릭

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

말레이시아 KL Sentral 한국인 GuestHouse


즐겨찾기 (취미)

어드민아이디

유에코 사랑회

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

JServer.kr

제이서버 메타블로그

재수 티스토리


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

재수 강의 홈페이지


한소리


VTMODE.COM


숭실대 인공지능학과


숭실대 통신연구실


베너