我的主机上有几个静态公共 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) | | |
+--------+---------+---------------------+-----------------------------------------------+-----------+-----------+
通过从主机的 /etc/network/interfaces 中删除 ip 并将 IP 添加到容器中来解决,如下所示: