Linux ネットワーク構成 - ポート転送、ファイアウォール

iptables を使用した NAT 転送

フォワード プロキシとリバース プロキシ
https://blog.csdn.net/boyemachao/article/details/107059329
具体的な手順
https://www.cnblogs.com/justmine/p/10478722.html
さまざまな状況
https://zhuanlan .zhihu .com/p/42153839
https://blog.csdn.net/zzchances/article/details/124062478
iptables を開始する
https://zhuanlan.zhihu.com/p/482207507
Linux で iptables を介してポート転送を実装する
https:/ /zhuanlan .zhihu.com/p/165043421
ルールの表示、作成、削除
https://www.freebuf.com/articles/web/289254.htmlインストール前に、どの iptables がiptalbes である
かがインストールされているか確認してください。

ファイアウォール

iptables、firewalld メソッド
https://blog.csdn.net/y368769/article/details/104490697
ufw メソッド
https://blog.51cto.com/u_15127647/4297560

iptables エラー

  • ユニットを有効にできませんでした: ユニット ファイル iptables.service が存在しません。
    Systemd サービス:
    iptables がインストールされた後でも、一部のディストリビューションには iptables 用の systemd サービス ファイルが付属していない場合があります。その場合は、systemd サービスを使用せずに iptables コマンドを直接使用することも、systemd サービスを手動で作成することもできます。

作成する場合の基本的な例を次に示します。

[Unit]
Description=Packet Filtering Framework
DefaultDependencies=no
Before=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/iptables-restore /etc/iptables/iptables.rules
ExecReload=/usr/sbin/iptables-restore /etc/iptables/iptables.rules
ExecStop=/usr/libexec/iptables/iptables.init save
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

上記の内容を /etc/systemd/system/iptables.service に保存し、systemd デーモンをリロードします。

sudo systemctl daemon-reload

問題を解決したら、サービスを有効にして開始できます。

sudo systemctl enable iptables
sudo systemctl start iptables
  • 制御プロセスがエラー コードで終了したため、iptables.service のジョブが失敗しました

iptables.service ユニット ファイルを調べて、ExecStart ディレクティブに iptables コマンドへの有効なパスが含まれていることを確認します。ユニット ファイルは、コマンド sudo systemctl cat iptables を使用して表示できます。

システムに /etc/iptables/iptables.rules ファイルと /usr/sbin/iptables-restore コマンドがない場合は、まず iptables がインストールされていることを確認してください。Debian や Ubuntu の特定のバージョンなど、一部のシステムでは、iptables-restore が /usr/sbin/ ではなく /sbin/ ディレクトリにある場合があります。

この問題に対処するための推奨手順を次に示します。

1 iptables-restore と iptables-save の場所を確認します。

これらのコマンドの正確なパスを確認するには、what コマンドを使用します。
which iptables-restore、
that iptables-save
は、これらのコマンドのパスが /sbin/iptables-restore および /sbin/iptables-save であると想定します。

2ルールを保存する場所を選択します。

iptables ルールを保存するには任意の場所を選択できますが、通常は /etc/ ディレクトリが推奨されます。たとえば、パス /etc/iptables.rules を使用します。

/etc/iptables.rules はフォルダーではなくファイルです。このファイルは、システムの再起動後にこれらのルールを復元できるように、iptables ルール セットを保存するために使用されます。

iptables サービスを初めてセットアップするときは、既存のルール ファイルがない限り、このファイルを手動で作成する必要があります。

現在の iptables ルールを手動で作成してこのファイルに保存する手順は次のとおりです。

ファイルを作成します (まだ存在しない場合)。

sudo touch /etc/iptables.rules

3 systemd サービス ファイルを変更します。

上記のパスに従って、/etc/systemd/system/iptables.service ファイルの ExecStart および ExecStop 命令を変更します。

ExecStart=/sbin/iptables-restore /etc/iptables.rules
ExecStop=/sbin/iptables-save > /etc/iptables.rules

4 systemd 構成をリロードします。

sudo systemctl デーモン-リロード

おすすめ

転載: blog.csdn.net/xyl295528322/article/details/132053553