我的主机上有多个静态公共 IP 地址。我想将该 IP 分配给某个容器,但我真的找不到有关该容器的任何更新信息。我尝试创建一个具有辅助 IP 的新网络并将其分配给容器,但执行此操作后,容器会失去互联网连接。
我做了什么:
lxc network create publicip #New network
lxc network add publicip ipv4.address 10.3.3.3/30 #add random local IP
lxc network add publicip ipv4.routes 138.*.16.151/32 #add route to the actual public IP that I want to assign to the container
lxc network attach publicip myContainer eth0 #attach it as eth0 interface to the container
lxc config device set myContainer eth0 ipv4.address 10.3.3.2 #assign container local IP from the range of the new network I created with first command
你知道我做错了什么导致我的容器与外界失去联系吗?
输出:lxc network show publicip
config:
ipv4.address: 10.3.3.3/30
ipv4.nat: "true"
ipv4.routes: 138.201.16.151/32
ipv6.address: fd42:cefa:6941:1e25::1/64
ipv6.nat: "true"
description: ""
name: publicip
type: bridge
used_by:
- /1.0/instances/myContainer
managed: true
status: Created
locations:
- none
lxc 列表的输出:
+--------+---------+---------------------+-----------------------------------------------+-----------+-----------+
| myContainer | RUNNING | 10.3.3.2 (eth0) | fd42:cefa:6941:1e25:216:3eff:fefe:2e29 (eth1) | CONTAINER | 0 |
| | | | fd42:cefa:6941:1e25:216:3eff:fe6a:3cdc (eth0) | | |
| | | | fd42:cefa:6941:1e25:216:3eff:fe0d:a57c (eth2) | | |
+--------+---------+---------------------+-----------------------------------------------+-----------+-----------+
答案1
通过从主机的 /etc/network/interfaces 中删除 ip 并将 IP 添加到容器中来解决,如下所示:
lxc config device add c1 eth0 nic nictype=routed parent=eth0 ipv4.address=publicIP