LoginSignup
0
0

More than 3 years have passed since last update.

iptables と nft の近しいコマンド対比表 ※現在1コマンドのみ

Last updated at Posted at 2020-01-25

未だnftのコマンドを覚えられないので、自分がよく使うコマンドを記載します。
私の利用環境は主に Debian ですが、あんまりディストリは関係ないかな?

エグゼクティブサマリー

コマンドの概要 iptables nftables
今動いているパケットフィルターがiptablesなのかnftなのか調べる iptables --version iptables --version
設定を一覧表示する iptables -L -v -n nft list ruleset

今動いているパケットフィルターがiptablesなのかnftなのか調べる

iptables --version

【実行例】

iptables の場合

% iptables --version
iptables v1.8.3 (legacy)

legacy となっていますので、nftablesではなく、iptablesが動いています。

nftables (NFT) の場合

% iptables --version
iptables v1.8.4 (nf_tables)

nf_tables となっていますので、nftが動いているようです。

設定を一覧表示する

itpablesとnftで現在動いているフィルター設定を一覧表示します。
nft のこれが未だに覚えらんない。

iptables の場合

iptables -L -v -n

nftables (NFT) の場合

nft list ruleset

【実行例】sshguardの奮闘状況確認

sshguardがちゃんと動いているか確認するときとかに使えます。
iptablesの場合、sshguardチェインにたくさん列挙されていても、INPUTチェインからsshguardチェインに飛ばすのが抜けてたりしないことを確認。

iptables の場合

% sudo iptables -L -v -n
Chain INPUT (policy ACCEPT 29 packets, 2988 bytes)
 pkts bytes target     prot opt in     out     source               destination
1770K  227M sshguard   all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 DOCKER-ISOLATION-STAGE-1  all  --  *      *       0.0.0.0/0            0.0.0.0/0
<中略>
Chain sshguard (1 references)
 pkts bytes target     prot opt in     out     source               destination
   22  1772 DROP       all  --  *      *       106.54.127.159       0.0.0.0/0
   27  2100 DROP       all  --  *      *       222.186.175.140      0.0.0.0/0
   31  2208 DROP       all  --  *      *       54.39.97.17          0.0.0.0/0
   27  2100 DROP       all  --  *      *       222.186.175.163      0.0.0.0/0
   74  4892 DROP       all  --  *      *       111.229.110.107      0.0.0.0/0
   72  4648 DROP       all  --  *      *       159.203.36.154       0.0.0.0/0
   61  4120 DROP       all  --  *      *       114.67.74.151        0.0.0.0/0
   21  1356 DROP       all  --  *      *       218.92.0.145         0.0.0.0/0
   73  4832 DROP       all  --  *      *       221.143.48.143       0.0.0.0/0
   17  1544 DROP       all  --  *      *       222.186.180.41       0.0.0.0/0
   59  3540 DROP       all  --  *      *       139.199.48.217       0.0.0.0/0
  107  6780 DROP       all  --  *      *       159.65.26.61         0.0.0.0/0
   26  2040 DROP       all  --  *      *       222.186.175.216      0.0.0.0/0
   26  1928 DROP       all  --  *      *       45.80.65.1           0.0.0.0/0
  144  9044 DROP       all  --  *      *       80.232.246.116       0.0.0.0/0
   24  1852 DROP       all  --  *      *       218.92.0.165         0.0.0.0/0
  201 12468 DROP       all  --  *      *       198.199.101.113      0.0.0.0/0

INPUTから全部一度sshguardに飛ばしてあり、うまくブロックできています。

nftables (NFT) の場合

% sudo nft list ruleset
table ip sshguard {
        set attackers {
                type ipv4_addr
                flags interval
                elements = { 121.11.113.225 }
        }

        chain blacklist {
                type filter hook input priority filter - 10; policy accept;
                ip saddr @attackers drop
        }
}
table ip6 sshguard {
        set attackers {
                type ipv6_addr
                flags interval
        }

        chain blacklist {
                type filter hook input priority filter - 10; policy accept;
                ip6 saddr @attackers drop
        }
}
table ip filter {
        chain INPUT {
                type filter hook input priority filter; policy accept;
        }

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

        chain OUTPUT {
<省略>

サーバ再起動直後なのでまだ1個しか検知していないですが、nftのsshguardテーブルにちゃんと列挙されてて大丈夫そうです。

その他

  • 222.186.0.0/16はブロックしてよさげ
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0