在 arm 版的 pve 中建了一个 alpine lxc 容器,发现每次重启容器后网络配置都被还原

294 天前
 moxuanyuan

在一台 arm vps ( 6c16g200G ) 上装了 pve ,

因为只有单 ip ,网络按照文档中的基于 iptables 的网络地址转换配置进行配置

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug enp1s0
iface enp1s0 inet static
	address xxx.xxx..xxx..xxx./24
	gateway xxx..xxx..xxx..xxx.
	# dns-* options are implemented by the resolvconf package, if installed
	dns-nameservers 1.0.0.1 8.8.4.4 
iface enp1s0 inet6 dhcp


auto vmbr0
iface vmbr0 inet static
address  10.10.10.1/24
bridge-ports none
bridge-stp off
bridge-fd 0
post-up   echo 1 > /proc/sys/net/ipv4/ip_forward
post-up   iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o enp1s0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o enp1s0 -j MASQUERADE

然后在 pve webui 中新建一个 alpine 非特权容器,网络设置中也手动设置了 ip 和网关

进入容器后,发现容器没网络,进一步排查发现 /etc/network/interfaces 中的配置为 iface vmbr0 inet dhcp,于是手动修改了 /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 10.10.10.100/24
gateway 10.10.10.1

重启网络,连网正常,但。。一单容器重启,/etc/network/interfaces 文件被还原为

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

试过把容器删除重新建一个,也一样。。

arm vps 安装的是 debian 11 ,pve 用的是佛西版 https://github.com/jiangcuo/Proxmox-Arm64

1446 次点击
所在节点    Linux
4 条回复
allplay
294 天前
对网络不精通,看你描述估计是容器的问题。
你对容器内的文件修改没有持久化存储,容器的卷应该映射到容器外的磁盘目录里面。
以 docker 为例: -v <source>:<destination> 来指定容器内外的卷的映射定义,这样你修改容器外的文件,就等于修改了容器内的文件。这样定义的卷不受容器重启和删除的影响。
Proxmox 用的 LXC ,和 Docker 相似,但不完全相同,解决思路类似。按照 LXC 的命令来处理文件。
你也可以在 Proxmox 上装 docker ,用 portainer 来管理。你的机器配置完全够。
moxuanyuan
294 天前
@allplay #1 在容器中安装其它软件,重启是可以用的,说明文件有持久化,就是修改网络配置不行
allplay
294 天前
@moxuanyuan 试一下卷映射呢,把/etc/network/interfaces 强行映射出来,看它还会不会发生变化
flyqie
294 天前

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/958676

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX