大网数据广告活动
服务器运维问答

lxc-net doesn't like static ip for a bridged container

· 52CE 我爱测

I've just started to use LXC containers and I found that even if I set a particular ip address on lxc container config file, lxc-ls --fancy shows always another ip, which is pingable and the /etc/network/interfaces settings doesn…

问题原文

原帖链接 · JumpAlways · CC BY-SA 3.0

I've just started to use LXC containers and I found that even if I set a particular ip address on lxc container config file, lxc-ls --fancy shows always another ip, which is pingable and the /etc/network/interfaces settings doesn't override lxc-net settings.

I'm using lxc 2.0.7.


Container configs:

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


Interfaces configs:

auto eth0

iface eth0 inet static
 address 10.0.3.3
 netmask 255.255.255.0
 gateway 10.0.3.1


Host Interfaces:

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)


Container Configs:

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 Output:

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 -

已采纳解答

原帖链接 · JumpAlways · CC BY-SA 3.0

SOLUTIONS

Edit /etc/default/lxc-net and comment or remove the LXC bridge name, if specified, and the dhcp options:

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=""


Edit /etc/network/interfaces and set static configurations:

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



OR

Set network configs in <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


And set manual interface configuration in /etc/network/interfaces:

auto eth0
iface eth0 inet manual

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。