ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • iptables 사용법
    프로그래밍/Linux 2015. 8. 5. 03:09
    반응형


    iptables의 현재 룰셋 확인



    shell> iptables -n -L

    Chain INPUT (policy ACCEPT)

    target     prot opt source               destination

    fail2ban-SSH  tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22

    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:8888


    Chain FORWARD (policy ACCEPT)

    target     prot opt source               destination


    Chain OUTPUT (policy ACCEPT)

    target     prot opt source               destination


    Chain fail2ban-SSH (1 references)

    target     prot opt source               destination

    RETURN     all  --  0.0.0.0/0            0.0.0.0/0



     

    --line-numbers 옵션을 추가하면 룰셋의 적용순서도 확인할 수 있다.


    shell> iptables -nL --line-numbers

    Chain INPUT (policy ACCEPT)

    num  target     prot opt source               destination

    1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

    2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0

    3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

    4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22

    5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80

    6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306

    7    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

    8    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:9200

    9    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:9300



    iptables 수정방법

     

     iptables 설정 파일을 직접 수정하는 것과 iptables 명령어를 사용하는 두 가지 수정 방법이 있다.


    - /etc/sysconfig/iptables 내용을 직접 수정한후 service iptables restart 로 서비스를 재시작한다 



    shell>  vi /etc/sysconfig/iptables

    iptables 파일 수정

    shell> service iptables restart




    예시) FTP 통신을 위한 방화벽 세팅

    -A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT

    -A OUTPUT -p tcp -m state --state NEW -m tcp --sport 21 -j ACCEPT

     

    예시) MySql (port: 3306)

    -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

     


     

     

     


    - iptables 명령어를 사용하여 방화벽 규칙을 변경하고 service iptables save 명령어로 현재 방화벽 규칙을 /etc/sysconfig/iptables에 저장한다 


     



    예시) elasticsearch를 위한 방화벽 세팅 



    shell> iptables -A INPUT -p tcp -m tcp --dport 9200 -j ACCEPT

    shell> iptables -A INPUT -p tcp -m tcp --dport 9300 -j ACCEPT

    shell> service iptables save

    iptables: 방화벽 규칙을 /etc/sysconfig/iptables에 저장 중: [  OK  ]





    참고 : http://webdir.tistory.com/170





    728x90
    반응형
Designed by Tistory.