[lxc-users] How to setup a static IP in a container with LX[C|D] 2.0.0.*

Mahesh Patade patademahesh at gmail.com
Mon Mar 21 04:14:20 UTC 2016


Hi,

here is simple and sweet howto on bridge networking.

https://insights.ubuntu.com/2015/11/10/converting-eth0-to-br0-and-getting-all-your-lxc-or-lxd-onto-your-lan/

Google is your friend.  ;)
On 21 Mar 2016 3:31 am, "Hans Deragon" <hans at deragon.biz> wrote:

> Greetings,
>
> I solved my issue. Sean Mcnamara opened my eyes he wrote "First of all,
> there's no such thing as LX[C|D]. You're either using LXC or LXD.".
> This brought a paradigm shift where I though I use 'lxc' as the command,
> now I search the web for "LXD 2.0 <keywords>".  I then found
> instructions for the version of LXD I used, filtering many now useless
> web pages.  Following instructions found, I created the
> following profile:
>
>   lxc profile create bridged
>   lxc profile device add bridged eth0 nic nictype=bridged parent=br0
>
> And then, I ran:
>
>   lxc config edit <container name>
>
> Where I found "default", I replaced with "bridged".  Restarted the
> container with:
>
>   lxc restart <container name>
>
> and voilĂ , now I have my container working with a static IP (static IP
> configuration per se is the same as for any VM images;
> /etc/network/interfaces of container needs to be configured and on the
> host, a bridged network usually named br0)
>
> Best regards and thanks to all, particularly Sean, for the help.
> Hans Deragon
>
> On 2016-03-18 16:08, Hans Deragon wrote:
> > Greetings,
> >
> >> The recommended way to manage IPs with LXD is to do it
> >> exactly the same way you would do it for your VMs or
> >> physical machines, so either configure your DHCP server to
> >> give a static lease or configure the container to use a
> >> static IP (you can use lxc file pull/push/edit to do it on
> >> a stopped container).
> >
> > I have this in my container:
> >
> >   root at server2:/etc/network# cat interfaces
> >   auto lo
> >   iface lo inet loopback
> >
> >   auto eth0
> >   iface eth0 inet static
> >    address 192.168.1.5
> >    network 192.168.1.0
> >    netmask 255.255.255.0
> >    broadcast 192.168.1.255
> >
> > Same configuration as my KVM image (different IP, of course). Within the
> > container, it seams to work fine:
> >
> >   root at server2:/etc/network# ping 192.168.1.5
> >   PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data.
> >   64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=0.044 ms
> >
> > Now I need clear instructions on how to tell LDX that my container
> > needs to connect to the bridge (br0) device on the host.  I fail
> > to find such instructions on the web for the version I am running:
> >
> > LXD:        2.0.0~rc3-0ubuntu4~ubuntu14.04.1~ppa1
> > LXC:        2.0.0~rc10-0ubuntu2~ubuntu14.04.1~ppa1
> >
> > Best regards,
> > Hans Deragon
> >
> > On 2016-03-18 11:43, Stéphane Graber wrote:
> >> Our stance hasn't changed. LXD doesn't know nor care about layer-3
> >> networking, all it does is setup your layer-2.
> >>
> >> Having LXD pre-initialize your network namespace confuses the heck out
> >> of a bunch of distros which expect all network to be unconfigured by the
> >> time they apply their own config (they don't clean things up so
> >> duplicate entries lead to failure).
> >>
> >>
> >> Nevertheless, we have recently allowed the following key through
> raw.lxc:
> >>  - lxc.network.X.ipv4
> >>  - lxc.network.X.ipv4.gateway
> >>  - lxc.network.X.ipv6
> >>  - lxc.network.X.ipv6.gateway
> >>
> >> Note that we require you set the interface index (X above) as mixing
> >> those raw entris with the LXD generated config would otherwise randomly
> >> cause an invalid config and container startup failure.
> >>
> >>
> >> The recommended way to manage IPs with LXD is to do it exactly the same
> >> way you would do it for your VMs or physical machines, so either
> >> configure your DHCP server to give a static lease or configure the
> >> container to use a static IP (you can use lxc file pull/push/edit to do
> >> it on a stopped container).
> >>
> >> On Fri, Mar 18, 2016 at 10:18:33AM -0400, Sean McNamara wrote:
> >>> First of all, there's no such thing as LX[C|D]. You're either using
> >>> LXC or LXD. They're different enough in their configuration and
> >>> operation that you can't ask an "either-or" question. Pick one
> >>> solution and focus on that.
> >>>
> >>> I just wanted to chime in to say that I have this same question. I'm
> >>> stuck using a pre-2.0 release of LXD because it allows me to use the
> >>> "raw.lxc" config parameter to specify the IP settings for the guest.
> >>> This configuration parameter was removed at some point prior to the
> >>> 2.0 RC, so I ended up editing the source code of LXD to bring it back.
> >>> I haven't found any equivalent configuration that works without using
> >>> raw.lxc.
> >>>
> >>> raw.lxc: "lxc.network.ipv4=
> 1.2.3.4/32\nlxc.network.ipv4.gateway=5.6.7.8\nlxc.network.hwaddr=00:11:22:33:44:55\nlxc.network.flags=up
> >>>     \ \nlxc.network.mtu=1500\n"
> >>>   volatile.eth0.hwaddr: 00:11:22:33:44:55
> >>>   volatile.eth0.name: eth1
> >>> devices:
> >>>   eth0:
> >>>     hwaddr: 00:11:22:33:44:55
> >>>     nictype: bridged
> >>>     parent: br0
> >>>
> >>> On Ubuntu, you can then set up your bridge as follows in
> >>> /etc/network/interfaces:
> >>>
> >>> auto br0
> >>> iface br0 inet static
> >>>         address 1.2.3.4
> >>>         netmask 255.255.255.0
> >>>         broadcast 5.6.7.8
> >>>         gateway 9.10.11.12
> >>>         bridge_ports eth0
> >>>         bridge_stp off
> >>>
> >>>
> >>> This is fine with LXD 0.24 that was built about a month before the 2.0
> >>> release candidates started hitting (and with edited source code to
> >>> un-block the raw.lxc param) but I'm afraid to upgrade to LXD 2.0
> >>> because I don't know the way forward.
> >>>
> >>> It seems like support for certain basic network topologies are still
> >>> being worked out with LXD. It should be easy, well-documented and
> >>> flexible a la OpenVZ, but it's really not, as far as I have seen. The
> >>> best way to make any progress that I've found thus far is to start
> >>> learning Google Go and reading the source code.
> >>>
> >>> Thanks,
> >>>
> >>> Sean
> >>>
> >>>
> >>>
> >>> On Fri, Mar 18, 2016 at 9:10 AM, Hans Deragon <hans at deragon.biz>
> wrote:
> >>>> Greetings,
> >>>>
> >>>> Ok, this is ridiculous and I apologize for asking help for such a
> simple
> >>>> task, but I fail to find the answers by myself.  I fail to find proper
> >>>> documentation to setup bridge networking and static IP.  Newbie here
> btw and
> >>>> setup details at the end of this email.
> >>>>
> >>>> I got the container running and with DHCP configured, it has its own
> IP
> >>>> which the host can address with.
> >>>>
> >>>> Obviously, I attempted to setup the static IP many times following
> >>>> instructions found on many web pages, to no vail.  For example, I
> followed
> >>>> instructions from https://wiki.debian.org/LXC/SimpleBridge.  But
> turns out
> >>>> that I am probably running a different version of LXC and that this
> page is
> >>>> now obsolete.
> >>>>
> >>>> I went so far to run 'strace lxc restart server2' to realize that
> >>>> /var/lib/lxc/server2/config is not read (server2 is the container).
> This
> >>>> seams to be confirmed by the post at
> >>>> http://ubuntuforums.org/showthread.php?t=2275372.
> >>>>
> >>>> I found 'man lxc.container.conf'.  Seams promising.  However, I fail
> to find
> >>>> within the manual the path where this file should be saved!  If you
> write
> >>>> documentation, please always provide the path where configuration
> files are
> >>>> supposed to be stored.
> >>>>
> >>>> I created a profile named 'bridged' using commands, but I have not
> found any
> >>>> option/instruction on how to apply that profile on my existing
> image.  'lxc
> >>>> start server2' does not provide any option to start the container
> with a
> >>>> particular profile.  BTW, where are profile configuration files
> stored?
> >>>>
> >>>> I need clear step by step instructions, with full paths on how to set
> things
> >>>> up and I fail to find any on the web.  Anybody has a useful link to
> suggest?
> >>>>
> >>>> I have a KVM image running (server1) and it works flawlessly with a
> static
> >>>> IP on my bridge.  And it wasn't hard to find instructions on how to
> set it
> >>>> up.  But LXD/LXc is another story.
> >>>>
> >>>> The setup:
> >>>>
> >>>> Host:       Ubuntu 14.04 LTS.
> >>>> Container:  Ubuntu 14.04 LTS.
> >>>> LXD:        2.0.0~rc3-0ubuntu4~ubuntu14.04.1~ppa1
> >>>> LXC:        2.0.0~rc10-0ubuntu2~ubuntu14.04.1~ppa1
> >>>>
> >>>> Best regards and thanks in advance,
> >>>> Hans Deragon
> >>>> _______________________________________________
> >>>> lxc-users mailing list
> >>>> lxc-users at lists.linuxcontainers.org
> >>>> http://lists.linuxcontainers.org/listinfo/lxc-users
> >>> _______________________________________________
> >>> lxc-users mailing list
> >>> lxc-users at lists.linuxcontainers.org
> >>> http://lists.linuxcontainers.org/listinfo/lxc-users
> >>
> >>
> >>
> >> _______________________________________________
> >> lxc-users mailing list
> >> lxc-users at lists.linuxcontainers.org
> >> http://lists.linuxcontainers.org/listinfo/lxc-users
> >>
> > _______________________________________________
> > lxc-users mailing list
> > lxc-users at lists.linuxcontainers.org
> > http://lists.linuxcontainers.org/listinfo/lxc-users
> >
> _______________________________________________
> lxc-users mailing list
> lxc-users at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20160321/6e01df20/attachment-0001.html>


More information about the lxc-users mailing list