Raspberry Pi OS(Debian)で、firewalld を再起動したり、リロードすると下記のエラーが発生する。
ERROR: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.2 (nf_tables):
line 4: RULE_REPLACE failed (No such file or directory): rule in chain INPUT
line 4: RULE_REPLACE failed (No such file or directory): rule in chain OUTPUT
原因はiptables の不具合のようです。
すでに修正されたバージョンが存在しますが、現時点(2021/08/15)ではまだ自動でアップデートされません。
firewalld を再起動するとエラーが出る。
Contents
概要
iptables の問題。
Raspberry pi OS を使用。firewalld を再起動して、ステータスを確認するとエラーが出ている。
もしくは、リロード時にエラーが出る。
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-08-15 13:19:50 JST; 15min ago
Docs: man:firewalld(1)
Main PID: 8248 (firewalld)
Tasks: 2 (limit: 2062)
CGroup: /system.slice/firewalld.service
└─8248 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid
8月 15 13:19:49 raspberrypi systemd[1]: Starting firewalld - dynamic firewall daemon...
8月 15 13:19:50 raspberrypi systemd[1]: Started firewalld - dynamic firewall daemon.
8月 15 13:19:51 raspberrypi firewalld[8248]: ERROR: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.2 (nf_tables):
line 4: RULE_REPLACE failed (No such file or directory): rule in chain INPUT
line 4: RULE_REPLACE failed (No such file or directory): rule in chain OUTPUT
8月 15 13:19:51 raspberrypi firewalld[8248]: ERROR: '/usr/sbin/ip6tables-restore -w -n' failed: ip6tables-restore v1.8.2 (nf_tables):
line 4: RULE_REPLACE failed (No such file or directory): rule in chain INPUT
line 4: RULE_REPLACE failed (No such file or directory): rule in chain OUTPUT
8月 15 13:19:52 raspberrypi firewalld[8248]: ERROR: COMMAND_FAILED: '/usr/sbin/ip6tables-restore -w -n' failed: ip6tables-restore v1.8.2 (nf_tables):
line 4: RULE_REPLACE failed (No such file or directory): rule in chain INPUT
line 4: RULE_REPLACE failed (No such file or directory): rule in chain OUTPUT
8月 15 13:31:33 raspberrypi firewalld[8248]: ERROR: INVALID_ZONE
解決策
Raspberry Pi のフォーラムにこの問題が投稿されていて、解決策も投稿されてました。
Error with firewalld in raspberry pi4
現在の安定版ではこの問題は修正されていないのですが、
バックポートという安定版の一つ前のバージョンで解決されている様子。
「バックポートをインストールしたら直ったぜ。」
「オレもだぜ。サンクス」
みたいな投稿がされています。
以下は解決策を実施した内容です。
投稿されていたコマンドがそのまま使えました。
ありがとうございました。大変感謝しております。
解決までの手順
sources.list ファイルのコピー。
これから設定ファイルを編集するので、バックアップを取っています。
cp -p /etc/apt/sources.list /etc/apt/sources.list-$(date +%s)
こんな感じ。
root@raspberrypi:/home/uniuni# cp -p /etc/apt/sources.list /etc/apt/sources.list-$(date +%s)
root@raspberrypi:/home/uniuni#
uniuni@raspberrypi:~ $ ls /etc/apt -al
合計 56
drwxr-xr-x 7 root root 4096 8月 15 14:08 .
drwxr-xr-x 117 root root 4096 8月 15 14:12 ..
drwxr-xr-x 2 root root 4096 7月 13 22:42 apt.conf.d
drwxr-xr-x 2 root root 4096 4月 20 01:41 auth.conf.d
-rw-r--r-- 1 root root 150 5月 7 23:44 listchanges.conf
drwxr-xr-x 2 root root 4096 4月 20 01:41 preferences.d
-rw-r--r-- 1 root root 291 8月 15 13:59 sources.list
-rw-r--r-- 1 root root 235 5月 7 23:43 sources.list-1629003511
drwxr-xr-x 2 root root 4096 5月 7 23:43 sources.list.d
-rw-r--r-- 1 root root 8370 8月 15 14:08 trusted.gpg
drwxr-xr-x 2 root root 4096 5月 7 23:43 trusted.gpg.d
-rw-r--r-- 1 root root 2452 5月 7 23:41 trusted.gpg~
uniuni@raspberrypi:~ $
sources.list ファイルを編集。
cat << EOF >> /etc/apt/sources.list

上記のコマンドを実行すると、入力待ちになるので、下記を追加で入力。
deb http://deb.debian.org/debian buster-backports main
EOF
EOF を入力すると、入力待ちの状態から抜けます。
こんな感じになります。
root@raspberrypi:/home/uniuni# cat << EOF >> /etc/apt/sources.list
> deb http://deb.debian.org/debian buster-backports main
>
> EOF
root@raspberrypi:/home/uniuni#
編集前
root@raspberrypi:/home/uniuni# cat /etc/apt/sources.list
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
編集後
ファイルに追記されているのが分かります。
root@raspberrypi:/home/uniuni# cat /etc/apt/sources.list
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://deb.debian.org/debian buster-backports main
暗号鍵の入手
鍵 を公開鍵サーバーから入手します。
先ほど追加したサイトのパッケージが偽物ではない事を確認してインストールするために必要な設定になります。
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 648ACFD622F3D138
root@raspberrypi:/home/uniuni# gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 648ACFD622F3D138
gpg: ディレクトリ'/root/.gnupg'が作成されました
gpg: keybox'/root/.gnupg/pubring.kbx'が作成されました
gpg: /root/.gnupg/trustdb.gpg: 信用データベースができました
gpg: 鍵DC30D7C23CBBABEE: 公開鍵"Debian Archive Automatic Signing Key (10/buster) <ftpmaster@debian.org>"をインポートしました
gpg: 処理数の合計: 1
gpg: インポート: 1

続けて鍵をエクスポートして、認証リストに追加。「-」は標準入力を読み込み。
gpg --export 648ACFD622F3D138 | apt-key add -
root@raspberrypi:/home/uniuni# gpg --export 648ACFD622F3D138 | apt-key add -
OK
追加後
「Debian Archive Automatic Signing Key (10/buster) ftpmaster@debian.org」 が追加されてます。
uniuni@raspberrypi:~ $ apt-key list
/etc/apt/trusted.gpg
--------------------
pub rsa2048 2012-04-01 [SC]
A0DA 38D0 D76E 8B5D 6388 7281 9165 938D 90FD DD2E
uid [ 不明 ] Mike Thompson (Raspberry Pi Debian armhf ARMv6+VFP) <mpthompson@gmail.com>
sub rsa2048 2012-04-01 [E]
pub rsa2048 2012-06-17 [SC]
CF8A 1AF5 02A2 AA2D 763B AE7E 82B1 2992 7FA3 303E
uid [ 不明 ] Raspberry Pi Archive Signing Key
sub rsa2048 2012-06-17 [E]
pub rsa4096 2019-04-14 [SC] [有効期限: 2027-04-12]
80D1 5823 B7FD 1561 F9F7 BCDD DC30 D7C2 3CBB ABEE
uid [ 不明 ] Debian Archive Automatic Signing Key (10/buster) <ftpmaster@debian.org>
sub rsa4096 2019-04-14 [S] [有効期限: 2027-04-12]
gcg については、下記の記事が非常に分かり易かったです。
パッケージのアップデートと確認。
apt update
apt list iptables -a
root@raspberrypi:/home/uniuni# apt update
取得:1 http://deb.debian.org/debian buster-backports InRelease [46.7 kB]
ヒット:2 http://archive.raspberrypi.org/debian buster InRelease
ヒット:3 http://raspbian.raspberrypi.org/raspbian buster InRelease
取得:4 http://deb.debian.org/debian buster-backports/main armhf Packages [473 kB]
取得:5 http://deb.debian.org/debian buster-backports/main Translation-en [407 kB]
926 kB を 2秒 で取得しました (505 kB/s)
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
アップグレードできるパッケージが 25 個あります。表示するには 'apt list --upgradable' を実行してください。
root@raspberrypi:/home/uniuni# apt list iptables -a
一覧表示... 完了
iptables/buster-backports 1.8.5-3~bpo10+1 armhf
iptables/stable,now 1.8.2-4 armhf [インストール済み]
インストール
apt -y install -t buster-backports iptables
root@raspberrypi:/home/uniuni# apt -y install -t buster-backports iptables
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
python-colorzero
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
libip4tc2 libip6tc2 libnftnl11 libxtables12 netbase
推奨パッケージ:
nftables
以下のパッケージが新たにインストールされます:
libip4tc2 libip6tc2
以下のパッケージはアップグレードされます:
iptables libnftnl11 libxtables12 netbase
アップグレード: 4 個、新規インストール: 2 個、削除: 0 個、保留: 118 個。
513 kB のアーカイブを取得する必要があります。
この操作後に 120 kB のディスク容量が解放されます。
取得:1 http://deb.debian.org/debian buster-backports/main armhf iptables armhf 1.8.5-3~bpo10+1 [338 kB]
取得:2 http://deb.debian.org/debian buster-backports/main armhf libxtables12 armhf 1.8.5-3~bpo10+1 [41.6 kB]
取得:3 http://deb.debian.org/debian buster-backports/main armhf libip4tc2 armhf 1.8.5-3~bpo10+1 [32.4 kB]
取得:4 http://deb.debian.org/debian buster-backports/main armhf libip6tc2 armhf 1.8.5-3~bpo10+1 [32.7 kB]
取得:5 http://deb.debian.org/debian buster-backports/main armhf netbase all 6.1~bpo10+1 [19.9 kB]
取得:6 http://deb.debian.org/debian buster-backports/main armhf libnftnl11 armhf 1.1.7-1~bpo10+1 [47.6 kB]
513 kB を 3秒 で取得しました (163 kB/s)
apt-listchanges: changelog を読み込んでいます...
apt-listchanges: ニュース
---------------------
iptables (1.8.4-1) unstable; urgency=medium
All the iptables binaries have been moved away from /sbin to /usr/sbin.
Compatibility symlinks were provided during the Buster release, but they
have been dropped now.
Please make sure your scripts aren't using hardcoded binary paths.
.
Also, please note that iptables is no longer Priority: important. This
means it is not installed by default in every system. It has been replaced
by nftables.
-- Arturo Borrero Gonzalez <arturo@debian.org> Wed, 04 Dec 2019 11:49:00 +0200
(データベースを読み込んでいます ... 現在 104950 個のファイルとディレクトリがインストールされています。)
.../0-iptables_1.8.5-3~bpo10+1_armhf.deb を展開する準備をしています ...
iptables (1.8.5-3~bpo10+1) で (1.8.2-4 に) 上書き展開しています ...
.../1-libxtables12_1.8.5-3~bpo10+1_armhf.deb を展開する準備をしています ...
libxtables12:armhf (1.8.5-3~bpo10+1) で (1.8.2-4 に) 上書き展開しています ...
以前に未選択のパッケージ libip4tc2:armhf を選択しています。
.../2-libip4tc2_1.8.5-3~bpo10+1_armhf.deb を展開する準備をしています ...
libip4tc2:armhf (1.8.5-3~bpo10+1) を展開しています...
以前に未選択のパッケージ libip6tc2:armhf を選択しています。
.../3-libip6tc2_1.8.5-3~bpo10+1_armhf.deb を展開する準備をしています ...
libip6tc2:armhf (1.8.5-3~bpo10+1) を展開しています...
.../4-netbase_6.1~bpo10+1_all.deb を展開する準備をしています ...
netbase (6.1~bpo10+1) で (5.6 に) 上書き展開しています ...
.../5-libnftnl11_1.1.7-1~bpo10+1_armhf.deb を展開する準備をしています ...
libnftnl11:armhf (1.1.7-1~bpo10+1) で (1.1.2-2 に) 上書き展開しています ...
libip4tc2:armhf (1.8.5-3~bpo10+1) を設定しています ...
libip6tc2:armhf (1.8.5-3~bpo10+1) を設定しています ...
libnftnl11:armhf (1.1.7-1~bpo10+1) を設定しています ...
libxtables12:armhf (1.8.5-3~bpo10+1) を設定しています ...
netbase (6.1~bpo10+1) を設定しています ...
新バージョンの設定ファイル /etc/services をインストールしています ...
iptables (1.8.5-3~bpo10+1) を設定しています ...
man-db (2.8.5-2) のトリガを処理しています ...
libc-bin (2.28-10+rpi1) のトリガを処理しています ...
root@raspberrypi:/home/uniuni#
インストールが完了したら、再起動 。
手順は以上です。
firewalld を再起動して、エラーが解消されている事を確認。
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-08-15 14:16:26 JST; 31min ago
Docs: man:firewalld(1)
Main PID: 1204 (firewalld)
Tasks: 2 (limit: 2062)
CGroup: /system.slice/firewalld.service
└─1204 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid
ピンバック: インターネット経由でWOL する。「プランB」 - .zapping
ピンバック: Raspberry Pi OS 【64bit 版】をダウンロードしたい。 - .zapping