システムサービス iptables-restore は有効ですが、起動後に起動しません

システムサービス iptables-restore は有効ですが、起動後に起動しません

私はGentooシステム(デフォルトシステムバージョン2.2)を持っていて、起動時にiptablesルールを自動的にロードしたいと思います。

iptables-restoreそのため、起動時にsystemdサービスを実行しようとしました。

ファイルは/usr/lib/systemd/system/iptables-restore.service次のとおりです。

[Unit]
Description=Restore iptables firewall rules
# if both are queued for some reason, don't store before restoring :)
Before=iptables-store.service
# sounds reasonable to have firewall up before any of the services go up
Before=network.target
Conflicts=shutdown.target

[Service]
Type=oneshot
ExecStart=/sbin/iptables-restore /var/lib/iptables/rules-save

[Install]
WantedBy=basic.target

だから私はやる

systemctl daemon-reload
systemctl enable iptables-restore.service
systemctl start iptables-restore
systemctl status iptables-restore

サービスの開始後、iptables ルールが正常に適用され、次のコマンドで確認できます。iptables -L

ただし、状態は次のとおりです。

● iptables-restore.service - Restore iptables firewall rules
   Loaded: loaded (/usr/lib/systemd/system/iptables-restore.service; enabled)
   Active: inactive (dead)

再起動後もルールは適用されません。

また、同じコンテンツで別のシステムサービスを作成しましたが、次のようWantedBy=basic.targetに変更しました。WantedBy=multi-user.target

しかし、それも食べません...

ブート時にsystemdサービスを実行する方法についてのヒント、またはブート時にiptablesルールを適用する方法に代わる方法はありますか?

ベストアンサー1

ExecStart=/sbin/iptables-restore /var/lib/iptables/rules-save

iptables-restoreファイル名をコマンドライン引数として渡さないでください。この人によると(強調):

iptables-restoreは、指定されたデータからIPテーブルを復元するために使用されます。標準入力。ファイルを読み取るには、シェルが提供するI / Oリダイレクトを使用します。

リダイレクトを介してファイルを渡す必要があります。

ExecStart='/sbin/iptables-restore < /var/lib/iptables/rules-save'

おすすめ記事