AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 830776
Accepted
JumpAlways
JumpAlways
Asked: 2017-02-06 17:49:57 +0800 CST2017-02-06 17:49:57 +0800 CST 2017-02-06 17:49:57 +0800 CST

lxc-net 不喜欢桥接容器的静态 ip

  • 772

我刚刚开始使用 LXC 容器,我发现即使我在 lxc 容器配置文件上设置了一个特定的 IP 地址,lxc-ls --fancy也总是显示另一个 IP,它是可 ping 的,并且/etc/network/interfaces设置不会覆盖lxc-net设置。

我正在使用lxc2.0.7。


容器配置:

lxc.network.type = veth
lxc.network.hwaddr = 00:1a:b2:ff:62:32
lxc.network.link = lxcbr0
lxc.network.ipv4 = 10.0.3.2/24
lxc.network.ipv4.gateway = 10.0.3.1
lxc.network.flags = up

lxc.rootfs = /var/lib/lxc/debcontainer/rootfs
lxc.rootfs.backend = dir

# Common configuration
lxc.include = /usr/share/lxc/config/debian.common.conf

# Container specific configuration
lxc.tty = 4
lxc.utsname = debcontainer
lxc.arch = amd64


接口配置:

auto eth0

iface eth0 inet static
 address 10.0.3.3
 netmask 255.255.255.0
 gateway 10.0.3.1


主机接口:

eth0      Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX
          ...

lo        Link encap:Local Loopback
          ...

lxcbr0    Link encap:Ethernet  HWaddr 00:16:3e:00:00:00  
          inet addr:10.0.3.1  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:fe00:0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:137 errors:0 dropped:0 overruns:0 frame:0
          TX packets:131 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:16641 (16.2 KiB)  TX bytes:14826 (14.4 KiB)

vethE2RLT9 Link encap:Ethernet  HWaddr fe:66:28:6b:1a:f1  
          inet6 addr: fe80::fc66:28ff:fe6b:1af1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:137 errors:0 dropped:0 overruns:0 frame:0
          TX packets:161 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:18559 (18.1 KiB)  TX bytes:19428 (18.9 KiB)


容器配置:

eth0      Link encap:Ethernet  HWaddr 00:1a:b2:ff:62:32  
          inet addr:10.0.3.2  Bcast:255.255.255.255  Mask:255.255.255.255
          inet6 addr: fe80::216:abff:fec4:63ff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:170 errors:0 dropped:0 overruns:0 frame:0
          TX packets:147 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:20061 (19.5 KiB)  TX bytes:20259 (19.7 KiB)

lo        Link encap:Local Loopback
          ...


lxc-fs输出:

user@debian-8-test:~$ sudo lxc-ls --fancy
NAME         STATE   AUTOSTART GROUPS IPV4                 IPV6 
debcontainer RUNNING 0         -      10.0.3.2, 10.0.3.211 -
linux networking bridge containers lxc
  • 2 2 个回答
  • 2695 Views

2 个回答

  • Voted
  1. Best Answer
    JumpAlways
    2017-02-09T18:14:09+08:002017-02-09T18:14:09+08:00

    解决方案

    编辑 /etc/default/lxc-net 并注释或删除 LXC 网桥名称(如果指定)和 dhcp 选项:

    USE_LXC_BRIDGE="true"
    #LXC_BRIDGE="lxcbr0"
    LXC_ADDR="10.0.3.1"
    LXC_NETMASK="255.255.255.0"
    LXC_NETWORK="10.0.3.0/24"
    #LXC_DHCP_RANGE="10.0.3.2,10.0.3.254"
    #LXC_DHCP_MAX="253"
    #LXC_DHCP_CONFILE=""
    LXC_DOMAIN=""
    


    编辑/etc/network/interfaces和设置静态配置:

    auto eth0
    iface eth0 inet static
        address 10.0.3.3
        gateway 10.0.3.1
        netmask 255.255.255.0
    



    或者

    设置网络配置<container>/config:

    lxc.network.type = veth
    lxc.network.hwaddr = 00:1a:b2:ff:62:32
    lxc.network.link = lxcbr0
    lxc.network.ipv4 = 10.0.3.2/24
    lxc.network.ipv4.gateway = 10.0.3.1
    lxc.network.flags = up
    


    并设置手动界面配置/etc/network/interfaces:

    auto eth0
    iface eth0 inet manual
    
    • 1
  2. Tombart
    2017-02-07T00:33:39+08:002017-02-07T00:33:39+08:00

    可能dnsmasq正在运行“动态”IP分配,您将在其中保留某些IP /etc/lxc/dnsmasq.conf,例如:

    dhcp-host=web,10.0.3.2
    

    更改主机映射后,您需要重新加载dnsmasq:

    kill -HUP $(cat /var/run/lxc/dnsmasq.pid)
    

    dnsmasq依赖于lxc-net服务,你应该可以在服务状态中看到配置:

    systemctl status lxc-net
    
    • 0

相关问题

  • 更改 PHP 的默认配置设置?

  • 有什么软件可以模拟局域网?

  • 保护新的 Ubuntu 服务器 [关闭]

  • 带宽利用工具?[关闭]

  • (软)Ubuntu 7.10 上的 RAID 6,我应该迁移到 8.10 吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve