1

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 -
  • Which lxc version do you use? – Tombart Feb 6 '17 at 8:28
  • @Tombart I'm using lxc 2.0.7-1. – JumpAlways Feb 6 '17 at 15:56
1

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
0

There's probably dnsmasq running for "dynamic" IP assignment, where you'll reserve certain IPs in /etc/lxc/dnsmasq.conf, like:

dhcp-host=web,10.0.3.2

After changing hosts mapping you need to reload dnsmasq:

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

The dnsmasq is dependent on lxc-net service, you should be able to see the configuration in service status:

systemctl status lxc-net
  • Yeah, it should be enough, but I should also be able to use a pre-set configuration in /etc/network/interfaces instead of manually modify an interface parameters using ifconfig. It seems interfaces is just ignored, because no up/down... conditions are triggered either. – JumpAlways Feb 6 '17 at 15:54
  • If I remove the ip settings from the lxc container config, lxc-net gives the container a random ip and then lxc-ls --fancy shows multiple ip, the random one and the one I specify in interfaces, which are pingable. – JumpAlways Feb 6 '17 at 16:00
  • @JumpAlways Yep, sorry. Static IP address was the easiest solution for LXC 1. Try setting IP in dnsmasq.conf instead. – Tombart Feb 6 '17 at 23:53
  • Do you mean outside the containers? Because I still can't understand why interfaces file seems to be ignored. I managed to assign a unique static ip to the containers limiting the range inside /etc/default/lxc-net, but I'd want to learn to use interfaces configs. – JumpAlways Feb 8 '17 at 4:17
  • Limiting DHCP range is not really a solution. Do you have /etc/lxc/dnsmasq.conf on your host? – Tombart Feb 8 '17 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.