永久iptables

永久iptables

私は今読んだ。iptables - 持続性デザインに完全に抜けましたね。はい唯一の人ではありません、それがどのように機能するのか理解していませんでしたが、実際には私の想像をはるかに超えているようです。

私は次のことを想像しました。クローンタップ-e: ルールセットを編集すると、エディタを閉じたときにそのルールが保持され、適用されます。彼らは保存されていますどこかにそして私はユーザーとしてどこにいるのかわかりません。言わないでください。それでは完璧だと思います。

そのようなツールがありますか?なぜiptables-persistentこれを行うのは難しい方法で作業するのですか?

ベストアンサー1

通常、テキストエディタを使用してiptables-saveファイルにルールを書き込むコマンドを使用して、IPv4のアクティブなiptablesルールを編集できます。操作が完了したら、コマンドを使用してiptables-restore新しいルールを再ロードできます。例:

user@host:~$ iptables-save > rules.v4
user@host:~$ vim rules.v4
user@host:~$ iptables-restore rules.v4

ip6tables-saveIPv6では、次のような同様のコマンドを使用できますip6tables-restore

user@host:~$ ip6tables-save > rules.v6
user@host:~$ vim rules.v6
user@host:~$ ip6tables-restore rules.v6

サービスiptables-persistentは次の場所で確認します。

/etc/iptables/rules.v4
/etc/iptables/rules.v6

したがって、ルールを適用して維持するには、上記と同じ手順に従いますが、ファイルを編集しますiptables-persistent。たとえば、次のようになります。

user@host:~$ iptables-save > /etc/iptables/rules.v4
user@host:~$ vim /etc/iptables/rules.v4
user@host:~$ iptables-restore /etc/iptables/rules.v4

私はあなたが説明したようにiptablesルールを編集するインタラクティブコマンドを知りませんが、自分で作成するのは簡単です。簡単な例は次のとおりです。

#!/usr/bin/env bash

# iptables-e.sh

# Create a temporary file to store the new rules
TEMPFILE=$(mktemp)

# Save the current rules to a file
iptables-save > "${TEMPFILE}"

# Edit the rules interactively with a text editor
"${EDITOR}" "${TEMPFILE}" 

# Try to load the rules and update the persistent rules if no errors occur
iptables-restore "${TEMPFILE}" && cat "${TEMPFILE}" > /etc/iptables/rules.v4

crontab -eこれは、アクティブなcrontabを/var/spool/cron/crontabsディレクトリ内のファイルに自動的に保存してcrontabが永続化される仕組みとは大きく異なりません。このトピックの詳細については、次の投稿をご覧ください。

次のスクリプトにも興味があるかもしれません。

しかし、私はそれを保証することはできません。私はそれを使用したことがありません。これが私がInteractive iptables editを検索して見つけた唯一のものです。

おすすめ記事