Home
Packages
Forums
Wiki
GitLab
Security
AUR
Download
コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
目次
コミュニティに貢献
最近の出来事
おまかせ表示
特別ページ
交流
ヘルプ
貢献
最近の更新
最近の議論
新しいページ
統計
リクエスト
ArchWiki
検索
検索
表示
アカウント作成
ログイン
個人用ツール
アカウント作成
ログイン
Nftablesのソースを表示
ページ
議論
日本語
閲覧
ソースを閲覧
履歴を表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
ソースを閲覧
履歴を表示
全般
リンク元
関連ページの更新状況
ページ情報
表示
サイドバーに移動
非表示
←
Nftables
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
{{DISPLAYTITLE:nftables}} [[Category:ファイアウォール]] [[en:nftables]] {{Related articles start}} {{Related|ファイアウォール}} {{Related|iptables}} {{Related articles end}} [http://netfilter.org/projects/nftables/ nftables] は既存の ip-, ip6-, arp-, ebtables フレームワークを置き換える netfilter のプロジェクトです。新しいパケットフィルタリングフレームワーク、新しいユーザースペースユーティリティ (nft)、そして ip- と ip6tables の互換レイヤーを提供します。現行のフック、接続追跡システム、ユーザースペースのキューイングコンポーネント、そして netfilter のログサブシステムを使っています。 最初のリリースは Linux 3.13 から使うことが可能で、このカーネルは現在 [core] リポジトリに入っています ({{Pkg|linux}})。(ユーザースペースコンポーネントの) nftables は [extra] リポジトリから利用でき ({{Pkg|nftables}})、[[Arch User Repository|AUR]] には {{AUR|nftables-git}} パッケージがあります。 ==概要== nftables は3つのメインコンポーネントから構成されています: カーネルの実装、libnl netlink communication そして nftables ユーザースペースフロントエンド。カーネルは netlink の設定インターフェイスだけでなく、小さなクラス言語インタプリタを使用するランタイムのルールセットの評価も提供します。libnl にはカーネルと通信するためのローレベルな関数が含まれています。nftables フロントエンドはユーザーが対話するものです。 ==nft== nftables のユーザースペースユーティリティ {{ic|nft}} は現在カーネルのためにルールセットを処理する前にほとんどのルールセットの評価を行います。そのため、nftables はデフォルトのテーブルやチェインを提供していません。しかしながらユーザーが iptables のような設定をエミュレートすることが可能です。 ifconfig や iproute2 と同じような感じで動作します。iptables のように引数のスイッチを使う代わりに、長く構造化された連続のコマンドになります。例えば: nft add rule ip6 filter input ip6 saddr ::1 accept {{ic|add}} はコマンドです。{{ic|rule}} は {{ic|add}} のサブコマンドです。{{ic|ip6}} は {{ic|rule}} の引数で、ip6 ファミリーを使うことを宣言しています。{{ic|filter}} と {{ic|input}} は {{ic|rule}} の引数で、それぞれ使用するテーブルとチェインを指定しています。残りはルールの定義で、マッチ ({{ic|ip}}) とパラメータ ({{ic|saddr}})、パラメータの引数 ({{ic|::1}}) そしてジャンプ ({{ic|accept}}) からなります。 以下は nft で利用できるコマンドの不完全なリストです: <nowiki> list tables [family] table [family] <name> chain [family] <table> <name> add table [family] <name> chain [family] <table> <name> [chain definitions] rule [family] <table> <chain> <rule definition> table [family] <name> (shortcut for `add table`) insert rule [family] <table> <chain> <rule definition> delete table [family] <name> chain [family] <table> <name> rule [family] <table> <handle> flush table [family] <name> chain [family] <table> <name></nowiki> {{ic|family}} は任意ですが、デフォルトは {{ic|ip}} になります。 ==テーブル== テーブルの用途はチェインを保持することです。iptables のテーブルと違って、nftables には初めから組み込まれているテーブルはありません。テーブルは指定の4つのファミリーのうちどれか一つを持つことができ、それによって様々な iptables のユーティリティを一つに統一します: {| class="wikitable" ! nftables ファミリー || iptables ユーティリティ |- | ip || iptables |- | ip6 || ip6tables |- | arp || arptables |- | bridge || ebtables |} {{ic|ip}} がデフォルトのファミリーです。Linux 3.15 では ip と ip6 ファミリーを統一してルールを簡単に定義できるようにする5番目のファミリーが予定されています。 ===表示=== ファミリーの現在のテーブルは {{ic|nft list}} コマンドで一覧できます。 # nft list tables # nft list tables ip6 テーブルの名前を指定することで完全なテーブルの定義を一覧できます: # nft list table foo # nft list table ip6 foo ===作成=== テーブルは2つのコマンド (片方はもう片方のショートカットです) で追加することができます。以下は foo という名前の ip テーブルと foo という名前の ip6 テーブルを追加する例です: # nft add table foo # nft table ip6 foo ファミリーが異なっていれば同じ名前のテーブルを作ることが可能です。 ===削除=== テーブルを削除することができるのはチェインが存在しない場合だけです。 # nft delete table foo # nft delete table ip6 foo ==チェイン== チェインの用途はルールを保持することです。iptables のチェインと違って、nftables には初めから組み込まれているチェインはありません。そのためチェインが netfilter フレームワークにあるタイプやフックをどれも使わない場合、iptables とは異なりチェインを通り抜けるパケットは nftables の影響を受けません。 ===表示=== {{ic|nft list table foo}} コマンドは foo テーブルの全てのチェインを表示します。個々のチェインからルールを一覧することもできます。 # nft list chain foo bar # nft list chain ip6 foo bar 上記コマンドは ip と ip6 の {{ic|foo}} テーブルの {{ic|bar}} チェインを表示します。 ===作成=== テーブルがファイル定義や {{ic|nft add chain}} コマンドによって作成されたら、チェインを追加することができます。 # nft add chain foo bar # nft add chain ip6 foo bar 上記コマンドは {{ic|bar}} という名前のチェインを ip と ip6 の {{ic|foo}} テーブルに追加します。 ====プロパティ==== nftables には組み込みチェインが存在しないため、チェインは netfilter フレームワークの特定の機能にアクセスすることができます。 # nft add chain filter input { type filter hook input priority 0\; } 上記コマンドは nftables に {{ic|input}} という名前のチェインを {{ic|filter}} テーブルに追加させ、そのタイプ・フック・プライオリティを定義します。これらのプロパティは基本的に iptables で組み込まれているテーブルやチェインを置き換えるものです。 =====タイプ===== チェインには3つのタイプがあり、iptables で使われているテーブルと対応しています: *filter *nat *route (mangle) =====フック===== チェインは5つのフックを使うことができ、iptables で使われているチェインと対応しています: *input *output *forward *prerouting *postrouting =====プライオリティ===== {{Note|Priorities do not currently appear to have any effect on which chain sees packets first.}} {{Note|Since the priority seems to be an unsigned integer, negative priorities will be converted into very high priorities.}} プライオリティは nftables がどのパケットを初めに通過させるかを示します。整数で指定し、高い値を与えるほど優先されます。 ===削除=== チェインはルールが存在しない場合にのみ削除することができます。 # nft delete chain foo bar # nft delete chain ip6 foo bar 以上のコマンドは ip と ip6 の {{ic|foo}} テーブルから {{ic|bar}} チェインを削除します。 ==ルール== ルールの用途はパケットを識別(マッチ)して処理を実行(ジャンプ)することです。iptables と同じように、様々なマッチやジャンプが利用できますが、nftables には欠けている機能も存在します。 ===表示=== テーブルを表示するのと同じ方法を使って、{{ic|nft list}} コマンドでテーブルの中の現在のルールを表示することができます。個別のチェインからルールを表示することも可能です。 # nft list chain foo bar # nft list chain ip6 foo bar These commands will list the rules in the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables. ===作成=== テーブルがファイル定義や {{ic|nft add rule}} コマンドによって作成されたら、ルールを追加することができます。 # nft add rule foo bar ip saddr 127.0.0.1 accept # nft add rule ip6 foo bar ip saddr ::1 accept These commands will add a rule to the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables that matches an {{ic|ip}} packet when its {{ic|saddr}} (source address) is 127.0.0.1 (IPv4) or ::1 (IPv6) and accepts those packets. ====マッチ==== There are various matches available in nftables and, for the most part, coincide with their iptables counterparts. The most noticeable difference is that there are no generic or implicit matches anymore. A generic match was one that was always available, such as {{ic|--protocol}} or {{ic|--source}}. Implicit matches were protocol-specific, such as {{ic|--sport}} when a packet was determined to be TCP. The following is an incomplete list of the matches available: *meta (meta properties, e.g. interfaces) *icmp (ICMP protocol) *icmpv6 (ICMPv6 protocol) *ip (IP protocol) *ip6 (IPv6 protocol) *tcp (TCP protocol) *udp (UDP protocol) *sctp (SCTP protocol) *ct (connection tracking) The following is an incomplete list of match arguments: <nowiki> meta: oif <output interface INDEX> iif <input interface INDEX> oifname <output interface NAME> iifname <input interface NAME> (oif and iif accept string arguments and are converted to interface indexes) (oifname and iifname are more dynamic, but slower because of string matching) icmp: type <icmp type> icmpv6: type <icmpv6 type> ip: protocol <protocol> daddr <destination address> saddr <source address> ip6: daddr <destination address> saddr <source address> tcp: dport <destination port> sport <source port> udp: dport <destination port> sport <source port> sctp: dport <destination port> sport <source port> ct: state <new | established | related | invalid></nowiki> ====ジャンプ==== ジャンプは iptables と同じように使うことができますが、ひとつのルールで複数のジャンプを使用できるようになっています。 # nft add rule filter input tcp dport 22 log accept 以下はジャンプの未完成なリストです: *accept (accept a packet) *reject (reject a packet) *drop (drop a packet) *snat (perform source NAT on a packet) *dnat (perform destination NAT on a packet) *log (log a packet) *counter (keep a counter on a packet; counters are optional in nftables) *return (stop traversing the chain) ===挿入=== {{ic|nft insert rule}} コマンドでチェインにルールを挿入することができます。 # nft insert rule filter input ct state established,related accept ===削除=== Individual rules can only be deleted by their handles. The {{ic|nft --handle list}} command must be used to determine rule handles. Note the {{ic|--handle}} switch, which tells {{ic|nft}} to list handles in its output. The following determines the handle for a rule and then deletes it. The {{ic|--number}} argument is useful for viewing some numeric output, like unresolved IP addresses. {{hc|# nft --handle --numeric list chain filter input|2= <nowiki> table ip filter { chain input { type filter hook input priority 0; ip saddr 127.0.0.1 accept # handle 10 } } </nowiki> }} # nft delete rule filter input handle 10 All the chains in a table can be flushed with the {{ic|nft flush table}} command. Individual chains can be flushed using either the {{ic|nft flush chain}} or {{ic|nft delete rule}} commands. # nft flush table foo # nft flush chain foo bar # nft delete rule ip6 foo bar The first command flushes all of the chains in the ip {{ic|foo}} table. The second flushes the {{ic|bar}} chain in the ip {{ic|foo}} table. The third deletes all of the rules in {{ic|bar}} chain in the ip6 {{ic|foo}} table. ==ファイル定義== {{Warning|[http://people.netfilter.org/wiki-nftables/index.php/Atomic_rule_replacement netfilter wiki] に書かれていることとは違って、{{ic|nft -f}} コマンドは'''アトミックではありません'''。そのため古いテーブルを削除するのと新しいルールセットをロードする間に、全てのパケットを許可する必要があります。}} {{Note|{{ic|nft -f}} コマンドは使う前に衝突するテーブルを全て削除する必要があります。}} {{ic|nft -f}} コマンドでファイル定義を利用することができます。このコマンドは {{ic|iptables-restore}} コマンドと同じように動作します。 {{hc|/etc/nftables/filter.rules|2= <nowiki> table ip filter { chain input { type filter hook input priority 0; ct state established,related accept ip saddr 127.0.0.1 accept tcp dport 22 log accept reject } } </nowiki> }} ==はじめに== [[iptables|iptables]] のようなチェインを設定するには、まず備え付けの IPv4 フィルターファイルを使う必要があります: # nft -f /etc/nftables/ipv4-filter 作成されたチェインを表示するには: # nft list table filter Drop output to a destination: # nft add rule ip filter output ip daddr 1.2.3.4 drop Drop packets destined for local port 80: # nft add rule ip filter input tcp dport 80 drop Delete all rules in a chain: # nft delete rule filter output ==サンプル== ===シンプルな IP/IPv6 ファイアウォール=== {{hc|firewall.rules|2= <nowiki> # A simple firewall table firewall { chain incoming { type filter hook input priority 0; # established/related connections ct state {established, related} accept # invalid connections ct state invalid drop # loopback interface iifname lo accept # icmp ip protocol icmp accept # open tcp ports: sshd (22), httpd (80) tcp dport {ssh, http} accept # everything else reject } } table ip6 firewall { chain incoming { type filter hook input priority 0; # established/related connections ct state {established, related} accept # invalid connections ct state invalid drop # loopback interface iifname lo accept # icmp ip6 nexthdr icmpv6 accept # open tcp ports: sshd (22), httpd (80) tcp dport {ssh, http} accept # everything else reject } } </nowiki> }} ===Limit rate と tcp flags の IP/IPv6 ファイアウォール=== {{hc|firewall.2.rules|2= <nowiki> table firewall { chain incoming { type filter hook input priority 0; # bad tcp -> avoid network scanning: tcp flags & (fin|syn) == (fin|syn) drop tcp flags & (syn|rst) == (syn|rst) drop tcp flags & (fin|syn|rst|psh|ack|urg) < (fin) drop # == 0 would be better, not supported yet. tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop # no ping floods: ip protocol icmp limit rate 10/second accept ip protocol icmp drop ct state {established, related} accept ct state invalid drop iifname lo accept # avoid brute force on ssh: tcp dport {ssh} limit rate 15/minute accept reject } } table ip6 firewall { chain incoming { type filter hook input priority 0; # bad tcp: tcp flags & (fin|syn) == (fin|syn) drop tcp flags & (syn|rst) == (syn|rst) drop tcp flags & (fin|syn|rst|psh|ack|urg) < (fin) drop # == 0 would be better, not supported yet. tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop # no ping floods: ip6 nexthdr icmpv6 limit rate 10/second accept ip6 nexthdr icmpv6 drop ct state {established, related} accept ct state invalid drop # loopback interface iifname lo accept # avoid brute force on ssh: tcp dport {ssh} limit rate 15/minute accept reject } } </nowiki> }} ===Priority-based Atomic Fix=== If priorities ever actually take effect, this may be a workaround for {{ic|nft -f}}'s lack of true atomicness (being able to replace all the current rules with new ones in one go): {{hc|atomic.rules|2= table atomic { chain incoming { type filter hook input priority 0; ct state new reject } } table ip6 atomic { chain incoming { type filter hook input priority 0; ct state new reject } } }} Set the priority of other chains that hook input to higher than 0. This should block new connections while no other input chains are loaded. ===Rules Script with Atomic Fix=== Because using {{ic|nft -f}} to reload rulesets is time consuming, it's far easier to script it. This will include an atomic fix not based on priorities. It uses the two rules files from above. {{hc|firewall.sh|2= #!/bin/sh # Load atomic rules first nft -f atomic.rules # New incoming traffic should now be stopped # Get rid of both the ip and ip6 firewall tables nft flush table firewall 2>/dev/null nft delete chain firewall incoming 2>/dev/null nft delete table firewall 2>/dev/null nft flush table ip6 firewall 2>/dev/null nft delete chain ip6 firewall incoming 2>/dev/null nft delete table ip6 firewall 2>/dev/null # Reload the firewall rules nft -f firewall.rules # Get rid of both the ip and ip6 atomic tables nft flush table atomic 2>/dev/null nft delete chain atomic incoming 2>/dev/null nft delete table atomic 2>/dev/null # New incoming IP traffic should be working nft flush table ip6 atomic 2>/dev/null nft delete chain ip6 atomic incoming 2>/dev/null nft delete table ip6 atomic 2>/dev/null # New incoming IPv6 traffic should be working }} This should take anywhere from 100ms to 400ms, which is clearly unacceptable, but the only apparent solution. ==起動時にルールをロードする== システムの起動時にルールを自動的にロードするには、{{ic|systemctl enable nftables}} を実行して nftables の systemd サービスを有効にしてください。 {{Note|systemd サービスが正しく動作するように必要な nftables 関連のモジュール全てのエントリを含む {{ic|/etc/modules-load.d/nftables.conf}} を作成する必要があります。モジュールのリストは次のコマンドで取得可能です: {{bc|<nowiki>lsmod | grep nf</nowiki>}} 作成していないと、{{ic|Error: Could not process rule: No such file or directory}} エラーで終了してしまいます。}} ==Syslog にログを出力する== Syslog にログを残すには、{{ic|xt_LOG}} モジュールをロードする必要があります。 ==参照== * [http://people.netfilter.org/wiki-nftables/index.php/ netfilter nftables wiki] * [https://lwn.net/Articles/324251/ nftables の最初のリリース] * [https://home.regit.org/netfilter-en/nftables-quick-howto/ nftables クイックハウツー] * [https://lwn.net/Articles/564095/ nftables の帰還]
このページで使用されているテンプレート:
テンプレート:AUR
(
ソースを閲覧
)
テンプレート:Hc
(
ソースを閲覧
)
テンプレート:Ic
(
ソースを閲覧
)
テンプレート:META Related articles start
(
ソースを閲覧
)
テンプレート:Man
(
ソースを閲覧
)
テンプレート:Note
(
ソースを閲覧
)
テンプレート:Pkg
(
ソースを閲覧
)
テンプレート:Related
(
ソースを閲覧
)
テンプレート:Related articles end
(
ソースを閲覧
)
テンプレート:Related articles start
(
ソースを閲覧
)
テンプレート:Tip
(
ソースを閲覧
)
Nftables
に戻る。
検索
検索
Nftablesのソースを表示
話題を追加