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/ufw

iptables μ΄ˆκΈ°ν™”

iptables μ—λŠ” 5개의 ν…Œμ΄λΈ”μ΄ μžˆλ‹€.

  • raw is used only for configuring packets so that they are exempt from connection tracking.

  • filter is the default table, and is where all the actions typically associated with a firewall take place.

  • nat is used for network address translation (e.g. port forwarding).

  • mangle is used for specialized packet alterations.

  • security is 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