Firewall
Firewall is a network security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules.
Overview
μΈλΆμμ ν μλ²λ‘ μ κ·Όμ΄ κ°λ₯νλ€λ©΄ μλ²μ 보μμ μν΄ λ°©νλ²½μ μ€μ νλ κ²μ΄ μ’λ€. μ°λΆν¬λ κΈ°λ³Έμ μΌλ‘ ufwλ₯Ό λΌλ λ°©νλ²½ κ΄λ¦¬ ν΄μ μ 곡νλλ°, μ΄λ iptables λ₯Ό μ½κ² μ€μ νλλ‘ νλ μνμ ν λΏμ΄λ€.
The Uncomplicated Firewall (ufw) is a frontend for iptables and is particularly well-suited for host-based firewalls. ufw aims to provide an easy to use interface for people unfamiliar with firewall concepts, while at the same time simplifies complicated iptables commands to help an adminstrator who knows what he or she is doing.
ufwλ₯Ό ν΅ν΄ λ°©νλ²½ μ€μ μ νλ κ²λ³΄λ€ iptablesλ₯Ό μ§μ λ€λ£¨λκ² μ§κ΄μ μ΄λ―λ‘ ufwλ₯Ό μ κ±°νκ³ iptablesλ‘ λ°©νλ²½μ μ§μ μ€μ ν κ²μ΄λ€.
UFW μ κ±°
$ sudo apt-get purge ufw
$ sudo rm -rf /etc/ufw
$ sudo rm /etc/default/ufwiptables μ΄κΈ°ν
iptables μλ 5κ°μ ν
μ΄λΈμ΄ μλ€.
rawis used only for configuring packets so that they are exempt from connection tracking.filteris the default table, and is where all the actions typically associated with a firewall take place.natis used for network address translation (e.g. port forwarding).mangleis used for specialized packet alterations.securityis used for Mandatory Access Control networking rules (e.g. SELinux β see this article for more details).
μΌλ°μ μΈ κ²½μ° κΈ°λ³Έ ν
μ΄λΈμΈ filterλ§ μ¬μ©νλ©΄ λλ€.
-Fλ κ° μ²΄μΈμ μ€μ λμ΄ μλ κ·μΉμ λͺ¨λ μ κ±°νλ€. -Xλ₯Ό κΈ°λ³Έ 체μΈμ μ μΈν λλ¨Έμ§ μ²΄μΈμ μμ νλ€.
INPUTμ μμ€ν
μΌλ‘ λ€μ΄μ€λ ν¨ν·μ μ μ±
μ΄κ³ , FORWARDλ μμ€ν
μμ λ€λ₯Έ μμ€ν
μΌλ‘ 보λ΄λ ν¨ν·μ μ μ±
, OUTPUTμ μμ€ν
μμ λκ°λ ν¨ν·μ μ μ±
μ΄λ€. (policy ACCEPT)μ μ무쑰건λ ν΄λΉλμ§ μμ λ ACCEPT νλ€λ μλ―Έμ΄λ€.
iptables κΈ°λ³Έ μ€μ
iptables λͺ
λ Ήμ΄λ‘ νμ¬ μμ€ν
μ μ μ±
μ μ€μ ν μ μλ€.
μ΄λ―Έ μ°κ²°λμλ€λ©΄(established sessions) νμ©
loopback νμ©
PING νμ©
SSHκ° μ¬μ©νλ TCP 22λ² ν¬νΈ νμ©
λ§μ§λ§μΌλ‘ κΈ°λ³Έ κ·μΉμΈ INPUTκ³Ό FORWARDλ μ°¨λ¨μν¨λ€.
iptables κ·μΉμ if elseλ°©μμΌλ‘ μμ μλ κ·μΉμ΄ λ¨Όμ μ μ©λκΈ° λλ¬Έμ μμλ μ€μνλ€.
νμ¬ μ μ± μ νμΈνλ€.
κ·μΉ μμ λ°©λ²
κ·μΉ μμ λ κ·μΉ μΆκ° μ΅μ
μΈ -Aλ₯Ό -Dλ‘ λ°κΏμ£Όλ©΄ λλ€.
SSH νΉμ IPλμλ§ μ μ νμ© λ°©λ²
-s IPμ£Όμ μ΅μ
μΌλ‘ νΉμ IPμ£Όμλ§ μ μκ°λ₯ νλλ‘ μ€μ νμ¬ λ³΄μμμ€μ λμΈλ€. 192.168.122.1 κ°μ΄ νΉμ IPμ μ
λ ₯νκ±°λ 192.168.122.0/24 κ°μ΄ λ€νΈμν¬ λμμ μ
λ ₯ν μλ μλ€.
μ¬λΆν
μ μλμΌλ‘ μ μ±
λΆλ¬μ€κΈ°
iptablesλ νμ¬ μμ€ν
μ λ°©νλ²½μ μ€μ νμ§λ§ μ μ₯νμ§λ μλλ€. μ¦, μλ²λ₯Ό μ¬μμνλ©΄ μ€μ ν λ΄μμ΄ μ΄κΈ°νλλ€. μ€μ ν λ΄μμ μ¬λΆν
μ μλμΌλ‘ λΆλ¬μ€κΈ° μν΄ netfilter-persistent λ₯Ό μ€μΉνλ€.
μ€μΉ μ νμ¬ iptables κ·μΉμ /etc/iptables/rules.v4μ μ μ₯ν κ²μΈμ§ 묻λλ€. Yesλ₯Ό μ ννλ€.

ipv6μ λν΄ μ μ₯ν κ²μΈμ§λ λ¬Όμ΄λ³Έλ€. Yesλ₯Ό μ ννλ€.

/etc/iptables λΌλ λλ ν 리μ rules.v4μ rules.v6κ° μμ±λμλ€.
netfilter-persistent save λͺ
λ Ήμ΄λ‘ μ μ₯νκ³ netfilter-persistent reload λͺ
λ Ήμ΄λ‘ 리λ‘λν μ μλ€.
μ¬λΆν
ν iptables -S λ‘ μ μ±
μ΄ μ μ§λλμ§ νμΈνλ€.
ipv6 μ°¨λ¨
/etc/sysctl.conf νμΌμ μ΄μ΄ 맨 λ°μ μλ λ΄μ©μ μΆκ°νλ€.
Last updated