仮想マシン用の汎用DNS - iptables / netfilterを使用する

仮想マシン用の汎用DNS - iptables / netfilterを使用する

私のホストコンピュータにBind9があります。
ゲスト仮想マシンが複数あります。
私の仮想マシンがホストマシンでBind9を使用したいと思います。

Bind9が自分の仮想マシンからの要求を受け入れる方法を知っています(受信+再帰を許可)。
Bind9設定を変更せずにiptables / netfilterを使用して実装したいと思います。(別名127.0.0.1でのみ聞く)。
-->これはローカルポートリダイレクトです。 socatを使用してこれを行う方法を知っていますが、iptables / netfilterを使用して実行することはできません。

127.0.0.1でのみリスニングをバインドするため、パケットは127.0.0.1で開始する必要があります。
仮想マシンはブリッジ vmbr0 10.10.10.0/24 にあります。
ホストもブリッジ10.10.10.1にあります。

パケットをカスタムチェーンに送信してからDNAT + SNATに送信する必要がありますか、それとも簡単な方法がありますか?

私はこれをしました(しかしうまくいきません):

sysctl -w net.ipv4.conf.vmbr0.route_localnet=1     # not sure if necessary. Let's see that when everything will work

iptables  --table nat  --new-chain dns-prerouting
iptables  --table nat  --append PREROUTING  --source 10.10.10.0/24  --destination 10.10.10.1  --protocol udp  --destination-port 53  --jump dns-prerouting
iptables  --table nat  --append PREROUTING  --source 10.10.10.0/24  --destination 10.10.10.1  --protocol tcp  --destination-port 53  --jump dns-prerouting

iptables  --table nat  --new-chain dns-postrouting
iptables  --table nat  --append POSTROUTING  --source 10.10.10.0/24  --destination 127.0.0.1  --protocol udp  --destination-port 53  --jump dns-postrouting
iptables  --table nat  --append POSTROUTING  --source 10.10.10.0/24  --destination 127.0.0.1  --protocol tcp  --destination-port 53  --jump dns-postrouting


iptables  --table nat  --append dns-prerouting   --jump DNAT  --to-destination 127.0.0.1
iptables  --table nat  --append dns-postrouting  --jump SNAT  --to-source      127.0.0.1

ベストアンサー1

以前と同じように使用する必要がありますsysctl -w net.ipv4.conf.XXX.route_localnet=1が、おそらく仮想イーサネットインターフェイスで使用する必要があります。
これにより、カーネルはマーティンパケットを保持することができます。

また、ローカルで生成されたパケットはPREROUTINGチェーンに転送されません。したがって、OUTPUTチェーンを使用する必要があります。

最後に、非常に特定のケースではNATを試してはいけません。代わりに使用してください--jump TPROXY
思い出に残る実際の例を提示することはできないので、正確な設定を見つける必要があります。次に、後で参考になるように回答を作成してください。

おすすめ記事