본문 바로가기

nftables

테이블 설정 / configuring tables

source: https://wiki.nftables.org/wiki-nftables/index.php/Configuring_tables

이전 글: Ubuntu nftables 설치

다음 글: 체인 설정 / Configuring chains

 

테이블은 ruleset을 저장하는 top-level container입니다. table은 그 안에 chain, set, map, flowtable, stateful object를 포함합니다. 각 테이블은 1개의 family에 속하며(대응되며, 매칭되며), family는 ip, ip6, inet, arp, bridge, netdev가 있습니다. 

 

nftables을 설치하고 man nft를 입력하면 상세 안내를 볼 수 있습니다. 무려 2000 줄이 넘는 긴 내용입니다. 

nft(8)                                                                                            nft(8)

NAME
       nft - Administration tool of the nftables framework for packet filtering and classification

SYNOPSIS
       nft [ -nNscae ] [ -I directory ] [ -f filename | -i | cmd ...]
       nft -h
       nft -v

DESCRIPTION
       nft  is the command line tool used to set up, maintain and inspect packet filtering and classifi‐
       cation rules in the Linux kernel, in the nftables framework.  The Linux kernel subsystem is known
       as nf_tables, and 'nf' stands for Netfilter.

OPTIONS
       For a full summary of options, run nft --help.

여기에서 자주 이용할 table 명령어 형태는 아래와 같습니다. 

nft {add | delete | list | flush} table [family] {table}

 

Table 목록 확인

salsal@r3:~$ sudo nft list tables
table inet filter

 

nftables을 설치하고 table을 추가하지 않았더라도 기본적으로 family inet에 table 'filter'가 있다는 것을 알 수 있습니다.  family ip는 ipv4 packet에만 적용됩니다. family ip6는 ipv6 packet에만 적용됩니다. family inet는 ipv4, ipv6 packet에 적용됩니다. ruleset을 선언한 방식에 따라 ipv4에게만 적용되고도 하고 ipv6에게만 적용되기도 하며, 둘 다에 적용되기도 합니다. 

 

chain 목록을 확인할 수도 있습니다. 

salsal@r3:~$ sudo nft list chains
table inet filter {
	chain input {
		type filter hook input priority 0; policy accept;
	}
	chain forward {
		type filter hook forward priority 0; policy accept;
	}
	chain output {
		type filter hook output priority 0; policy accept;
	}
}

Table 추가

faminet ip (ipv4)에만 적용할 table filter와 table filter2를 추가한 것입니다. 

salsal@r3:~$ sudo nft add table ip filter

salsal@r3:~$ sudo nft list tables
table inet filter
table ip filter

salsal@r3:~$ sudo nft table ip filter2

salsal@r3:~$ sudo nft list tables
table inet filter
table ip filter
table ip filter2

** 1개의 family ip에 2개의 table filter, filter2가 있으면 어떻게 동작하나? 

** inet filter와 ip filter 2개 중에 어떤 것이 동작하나? 

** table ip filter 안에 있는 ruleset을 어떻게 확인하지? 

 

추가한 table ip filter를 확인해 보면 안에 chain이 아무것도 없다는 것을 알 수 있습니다. 

salsal@r3:~$ sudo nft list chains
table inet filter {
	chain input {
		type filter hook input priority 0; policy accept;
	}
	chain forward {
		type filter hook forward priority 0; policy accept;
	}
	chain output {
		type filter hook output priority 0; policy accept;
	}
}
table ip filter {
}

 

Table 삭제

salsal@r3:~$ sudo nft list tables
table inet filter
table ip filter
table ip filter2
salsal@r3:~$ sudo nft delete table ip filter2
salsal@r3:~$ sudo nft list tables
table inet filter
table ip filter

Table Flush

Flush는 Table을 삭제하는 것이 아니라, Table 안에 있는 모든 chain의 rule을 지웁니다. 다만 Table안에 있는 sets을 지우지 않습니다. 

salsal@r3:~$ sudo nft flush table ip filter
salsal@r3:~$ sudo nft flush table inet filter
salsal@r3:~$ sudo nft list table ip filter
table ip filter {
}
salsal@r3:~$ sudo nft list table inet filter
table inet filter {
	chain input {
		type filter hook input priority 0; policy accept;
	}

	chain forward {
		type filter hook forward priority 0; policy accept;
	}

	chain output {
		type filter hook output priority 0; policy accept;
	}
}