V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
moxuanyuan
V2EX  ›  Linux

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

  •  
  •   moxuanyuan · 281 天前 · 1415 次点击
    这是一个创建于 281 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在一台 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

    4 条回复    2023-07-21 22:46:50 +08:00
    allplay
        1
    allplay  
       281 天前
    对网络不精通,看你描述估计是容器的问题。
    你对容器内的文件修改没有持久化存储,容器的卷应该映射到容器外的磁盘目录里面。
    以 docker 为例: -v <source>:<destination> 来指定容器内外的卷的映射定义,这样你修改容器外的文件,就等于修改了容器内的文件。这样定义的卷不受容器重启和删除的影响。
    Proxmox 用的 LXC ,和 Docker 相似,但不完全相同,解决思路类似。按照 LXC 的命令来处理文件。
    你也可以在 Proxmox 上装 docker ,用 portainer 来管理。你的机器配置完全够。
    moxuanyuan
        2
    moxuanyuan  
    OP
       281 天前
    @allplay #1 在容器中安装其它软件,重启是可以用的,说明文件有持久化,就是修改网络配置不行
    allplay
        3
    allplay  
       281 天前
    @moxuanyuan 试一下卷映射呢,把/etc/network/interfaces 强行映射出来,看它还会不会发生变化
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   886 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:19 · PVG 05:19 · LAX 14:19 · JFK 17:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.