指南

IPv6를 포함한 올바른 nftables 방화벽

중급15분 읽기업데이트됨 2026년 4월 22일
간단한 답변

nftables는 inet 패밀리를 통해 IPv4와 IPv6를 함께 처리하는 단일 통합 규칙 세트로 iptables를 대체합니다. 올바른 기본 정책은 기본적으로 인바운드를 차단하고, 설정된 연결을 허용하며, 루프백과 ICMP를 허용하고, 서비스하는 포트만 엽니다.

01 inet 패밀리가 중요한 이유

The most common firewall mistake on a modern VPS is a v4-only ruleset. Every OnionVPS instance has a routed IPv6 /64, so services remain fully reachable over v6 unless the ruleset covers both. The inet family covers both in one place.

02 완전한 기본 규칙 세트

Write it to /etc/nftables.conf and enable the service. Keep a second session open while testing.

#!/usr/sbin/nft -f
flush ruleset

table inet filter {
  chain input {
    type filter hook input priority 0; policy drop;

    ct state established,related accept
    ct state invalid drop
    iif lo accept

    ip protocol icmp accept
    ip6 nexthdr icmpv6 accept

    tcp dport { 22, 80, 443 } accept
    udp dport 51820 accept          # WireGuard

    limit rate 5/minute burst 10 packets log prefix "nft-drop: "
  }
  chain forward { type filter hook forward priority 0; policy drop; }
  chain output  { type filter hook output  priority 0; policy accept; }
}

03 안전하게 적용하기

Schedule a flush before applying, so a mistake resolves itself rather than requiring the console.

echo 'nft flush ruleset' | at now + 10 minutes
nft -f /etc/nftables.conf
# verify you are still connected, then:
atrm $(atq | cut -f1)
systemctl enable nftables

04 ICMPv6를 절대 차단하지 마세요

IPv6 depends on ICMPv6 for neighbour discovery and path MTU discovery. Blocking it wholesale, which people do out of IPv4 habit, produces intermittent failures that are extremely hard to diagnose.

자주 묻는 질문

nftables를 사용해야 할까요, ufw를 사용해야 할까요?

ufw is a friendlier front end and handles both address families correctly by default. Use nftables directly when you need rules ufw cannot express, such as rate limiting or NAT.

무엇이 차단되고 있는지 어떻게 확인하나요?

위의 로그 규칙은 "nft-drop" 접두사와 함께 커널 로그에 기록됩니다. journalctl -k -g nft-drop으로 읽으세요.