·터미널 명령어

iptables

네트워크

쓰는 꼴

sudo iptables -L -n -v --line-numbers

지금 돌고 있는 패킷 필터를 고칩니다 — 규칙은 위에서 아래로 먼저 맞는 것이 이기므로 ACCEPT 뒤에 붙인 DROP은 영원히 안 걸리고, 저장하지 않으면 재부팅에 사라지며, 22번을 열기 전에 기본 정책을 DROP으로 두면 원격 기계에서 스스로 잠깁니다.

자주 쓰는 옵션

옵션
-L -n -v --line-numbersList the rules with counters and the numbers you need for -D.
-A <CHAIN>Append to the end of a chain, where an earlier rule may already have decided.
-I <CHAIN> 1Insert at the top, which is usually what you meant.
-D <CHAIN> <n>Delete rule number n.
-p tcp --dport 22Match protocol and destination port.
-s 10.0.0.0/8Match a source address or range.
-j ACCEPT|DROP|REJECTWhat to do with a matching packet.
-P <CHAIN> DROPSet the default policy, applied when no rule matched.

예시

sudo iptables -L -n -v --line-numbers

Read the current rules before changing anything.

sudo iptables -I INPUT 1 -p tcp --dport 22 -j ACCEPT

Guarantee your own SSH access first.

sudo iptables-save > /etc/iptables/rules.v4

Make the rules survive a reboot.

연결이 안 될 때 어디까지 갔는지 좁혀 갑니다 — 이름이 안 풀리는지, 길이 없는지, 포트가 막혔는지.

읽는 방법

  • 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
  • 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
  • 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.

자주 묻는 것

Q. iptables은 무엇을 하나요?

지금 돌고 있는 패킷 필터를 고칩니다 — 규칙은 위에서 아래로 먼저 맞는 것이 이기므로 ACCEPT 뒤에 붙인 DROP은 영원히 안 걸리고, 저장하지 않으면 재부팅에 사라지며, 22번을 열기 전에 기본 정책을 DROP으로 두면 원격 기계에서 스스로 잠깁니다.

Q. 어떻게 치나요?

sudo iptables -L -n -v --line-numbers — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 8개입니다. 전체 목록은 man iptables에 있습니다. 이 명령은 네트워크 갈래입니다.

같이 보는 명령

man 페이지: man iptables