이런 세상..

[LINUX] iptables 본문

> [IT]/>> Linux

[LINUX] iptables

GANWI 2016. 1. 14. 19:10

CLIENT -> INPUT -> (CHAIN) -> SERVER -> (CHAIN) -> OUTPUT -> CLIENT


[1] 기본 동작 확인


(사전) ping 확인

# ping 168.126.63.1

PING 168.126.63.1 (168.126.63.1) 56(84) bytes of data.

64 bytes from 168.126.63.1: icmp_seq=1 ttl=54 time=8.10 ms

64 bytes from 168.126.63.1: icmp_seq=2 ttl=54 time=6.33 ms

...생략



1. 정책 추가

# iptables -A OUTPUT -p icmp -m icmp --icmp-type 8 -j DROP



2. 리스트 확인

# 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

DROP       icmp --  anywhere             anywhere            icmp echo-request



3. 동작 확인

# ping 168.126.63.1

PING 168.126.63.1 (168.126.63.1) 56(84) bytes of data.

ping: sendmsg: 명령을 허용하지 않음

ping: sendmsg: 명령을 허용하지 않음

^C

--- 168.126.63.1 ping statistics ---

2 packets transmitted, 0 received, 100% packet loss, time 1635ms



4. 정책 제거

# iptables -D OUTPUT -p icmp -m icmp --icmp-type 8 -j DROP



5. 제거 후 ping 확인

# ping 168.126.63.1

PING 168.126.63.1 (168.126.63.1) 56(84) bytes of data.

64 bytes from 168.126.63.1: icmp_seq=1 ttl=54 time=16.8 ms

64 bytes from 168.126.63.1: icmp_seq=2 ttl=54 time=6.14 ms

^C

--- 168.126.63.1 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1661ms

rtt min/avg/max/mdev = 6.147/11.483/16.819/5.336 ms





[2] 응용 (서버기준)


1. 포트 열기

# iptables -A  INPUT -p tcp --dport 22 -j ACCEPT


2. 기본 서버로의 접속 정책 all drop 설정

# iptables -P  INPUT DROP    // 순서 유의 (서비스 포트를 먼저 열어두고 all drop 설정을 해야 접근 가능함)



3. --help

[출처] [Linux 기초] iptables|작성자 지킴이

*Target :

 ACCEPT : 패킷을 받아들임

 REJECT : 패킷을 버리고 거절했다는 응답을 줌.

 DROP : 패킷을 삭제.

 LOG : 패킷을 syslog에 기록


*Commands :

 -A(--append) : Rule 추가 

 -D(--delete) : Rule 삭제

 -I(--insert) : Rule 추가 삽입

 -R(--replace) : Rule 교체 

 -L(--list) : Rule 리스트 출력

 -F(--flush) : chain 으로부터 Rule 삭제

 -Z(--zero) : 모든 chain의 패킷과 바이트 카운터를 0 으로 변경

 -N(--new) : 새로운 chain을 추가

 -X(--delete-chain) : chain 삭제

 -P(--policy) : 기본 정책 변경


*Options :

 -p(--protocol) : 프로토콜

 -s(--source) : 출발지 (IP주소, 네트워크 등)

 -d(--destination) : 목적지 (ip주소나 네트워크)

 -i(--in-interface) : 입력 인터페이스 

 -j(--jump) : 규칙에 맞는 패킷을 어떻게 처리할지를 명시

 -m(--match) : 특정 모듈

 -o(out-interface) : 출력 인터페이스

 -t(--table) : 처리될 테이블

 -f(--fragment) : 두 번째 이후의 조각에 대해서 규칙을 명시

'> [IT] > >> Linux' 카테고리의 다른 글

[LINUX] dmesg 시간 일반 형식으로 변환  (0) 2016.01.15
[LINUX] 표준 입력/출력/에러  (0) 2016.01.14
[LINUX] shell script 파일을 binary 파일로 암호화  (0) 2016.01.14
[LINUX] find  (0) 2016.01.14
[LINUX] proc  (0) 2016.01.14
Comments