[lxc-users] DHCP or static ip address?
Yuri Kanivetsky
yuri.kanivetsky at gmail.com
Sat Mar 4 11:07:29 UTC 2017
Okay, I've managed to make it work with static ip somehow. From what I
can tell, there are two ways to set it up, either in
/var/lib/lxc/NAME/config, or in
/var/lib/lxc/NAME/rootfs/etc/network/interfaces. If you adjust both
those files, you get the conflict:
Mar 04 04:40:58 cont1 ifup[158]: RTNETLINK answers: File exists
Mar 04 04:40:58 cont1 ifup[158]: Failed to bring up eth0.
Since first lxc sets up eth0. And then networking service tries to do
the same thing and fails therefore.
So, either you have
lxc.network.type = veth
lxc.network.link = br0 # bridge device's name
lxc.network.flags = up
lxc.network.ipv4 = 10.0.0.100 # desired static ip
lxc.network.ipv4.gateway = 10.0.0.1 # bridge's ip
in /var/lib/lxc/NAME/config and nothing in
/var/lib/lxc/NAME/rootfs/etc/network/interfaces. But then my
/var/lib/lxc/NAME/rootfs/etc/resolv.conf has no nameserver options,
even so it had one before starting the container. And name resolution
doesn't work. This can be remedied by puttiing nameserver option into
/var/lib/lxc/NAME/rootfs/etc/resolvconf/resolv.conf.d/tail.
The other way is to leave in /var/lib/lxc/NAME/config only
lxc.network.type = veth
lxc.network.link = br0 # bridge device's name
and have:
auto eth0
iface eth0 inet static
address 10.0.0.100 # desired static ip
dns-nameserver 8.8.8.8
gateway 10.0.0.1 # bridge's ip
in /var/lib/lxc/NAME/rootfs/etc/network/interfaces. Then everything works.
Which way is better? Can it be any simpler? Is there any better way?
Can you explain how to make use of dhcp? Without using lxd if possible.
Meanwhile, I'm going to look into making CentOS work.
Regards,
Yuri
More information about the lxc-users
mailing list