プライベートネットワーク(lxdbr0)からのトラフィックルーティング

プライベートネットワーク(lxdbr0)からのトラフィックルーティング

私はホストシステムにlxdを設定し、lxdbr0ブリッジをネットワークカードとして使用しています。私のコンテナはdhcpを介してlxdbr0からIPアドレス(10.204.xxの範囲)を取得します。

また、2つのパブリックIPアドレスがあります。 1つはホスト用(xxxx)、もう1つはコンテナ用(bbbb)です。コンテナは出て行き、着信トラフィックに2番目のパブリックIPを使用する必要があります。両方のパブリックIPアドレスがホストシステムに移動するため、ホストシステムは最初にすべてのトラフィックを取得します。

パブリックIPからのすべての着信トラフィックが特定のコンテナに移動するように、パブリックIPからプライベートIPへのディクショナリパス(ホスト上)を設定しました。

しかし、コンテナからパブリックIPへのトラフィックをルーティングする方法はわかりません。着信トラフィックと同じように事前ルーティングを設定してみましたが、役に立ちませんでした。

iptables -Lショー

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:domain /* managed by lxd-bridge */
ACCEPT     udp  --  anywhere             anywhere             udp dpt:domain /* managed by lxd-bridge */
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:bootps /* managed by lxd-bridge */
ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootps /* managed by lxd-bridge */

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             /* managed by lxd-bridge */
ACCEPT     all  --  anywhere             anywhere             /* managed by lxd-bridge */

iptables -t nat -L 表示

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       all  --  anywhere             ip-b.ip-b-b-b.eu  to:10.204.119.5
DNAT       all  --  anywhere             10.204.119.5         to:b.b.b.b

b.b.b.b --> second public ip (for the container)
10.204.119.5 --> containers (private) ip in the lxdbr0 bridge

パブリックIPからの着信トラフィックはコンテナにルーティングされますが、コンテナからのトラフィックはそうではありません。

また、LXD_IPV4_NAT="false"コンテナが発信するトラフィックに自分のホストのIPアドレスを使用できるように、lxdブリッジ設定でこれを設定しました(不要)。

編集#1:パス-nを表示

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         x.x.x.1         0.0.0.0         UG    0      0        0 ens3
10.204.119.0    0.0.0.0         255.255.255.0   U     0      0        0 lxdbr0
x.x.x.1         0.0.0.0         255.255.255.255 UH    0      0        0 ens3

x.x.x.1 --> gateway of my hosts ip (x.x.x.x)

編集#2:はい

- pIP1 = public ip 1, should be used for host
- pIP2 = "      "  2, should be used for the container

the container runs on the host system.

container = 10.204.119.5 (device lxdbr0)
host      = pIP1 (device ens3) and pIP2 (device ens3:0)

Outgoing packets from the container come with the source ip 10.204.119.5. 
Now these packets should change the source ip to pIP2 and then sent to the 
gateway (so it appears to the router, that the packet from the container 
comes from the pIP2)

ベストアンサー1

コンテナのプライベートIPからコンテナのパブリックIP($ publicIP2)のホストインターフェイスにNATトラフィックを送信するだけです。

iptables -t nat -A POSTROUTING -s 10.204.119.5/32 -j SNAT --to-source $publicIP2

おすすめ記事