Chain
을 포함hook
을 통해 커널 네트워크 스택에 연결됨Hook Location | Description | Applicable Table |
---|---|---|
prerouting | 패킷이 시스템에 도착했을 때 즉시 처리 | ip, ip6, inet, arp |
input | 시스템이 대상인 패킷을 필터링 | ip, ip6, inet |
forward | 다른 인터페이스로 전달되는 패킷 필터링 | ip, ip6, inet |
output | 시스템이 생성한 패킷 필터링 | ip, ip6, inet |
postrouting | 인터페이스를 통해 나가기 직전 패킷을 처리 | ip, ip6, inet, arp |
Install Package
apt install -y nftables
systemctl enable --now nftables
Basic Structure
nft add rule [family] [table] [chain] ip saddr [Source] sport [Source_Port] ip daddr [Destination] dport [Destination_Port] [Action]
Command
nft add table ip [Table_Name]
Table 생성 (대소문자 구별함)
nft add chain ip [NAT] [Chain_Name] { type [Type] hook [postrouting] priority [Priority_Number] \; }
Additional Description
Type | Description | Use Hook |
---|---|---|
Filter | 방화벽 규칙 (패킷 필터링) | INPUT, OUTPUT, FORWARD |
NAT | NAT 변환 (IP 주소 변경) | PREROUTING, POSTROUTING |
Route | 패킷 경로 변경 | PREROUTING, OUTPUT |
Security | 보안 정책 적용 | INPUT, OUTPUT, FORWARD |
Priority Range | Description |
---|---|
-300 ~ -100 | 패킷을 수정하는 규칙 (ex: mangle, route) |
-99 ~ -1 | 연결 추적 및 정책 결정 관련 (ex: conntrack) |
0 | 기본 우선순위 (특별한 설정이 없으면 이 값 사용) |
1 ~ 99 | 일반적인 방화벽 및 필터 규칙 |
100 이상 | NAT 규칙 (postrouting에서 주로 사용됨) |
nft list tables
테이블 조회
nft table ip [Table_Name]
nft add rule ip [Table_Name] [Chain_Name] ip saddr [Source_IP] ip daddr [Destination_IP] counter [Action]
ntf insert rule ip [Table_Name] input [Protocol] dport [Destination_Port] counter accept
단일 Port 필터링
ntf insert rule ip [Table_Name] input [Protocol] dport {[Destination_Port], [Destination_Port]} counter accept
멀티 Port 필터링