Lan Ip And lxdbr0 Ip


(Najib Nour) #1

Good Morning, I am trying to find a way to have both MacVlan and the default bridge ip on one container so that it could be accessed from other hosts on the network but also be able to talk to private facing containers. Could anyone shine some light and let me know how to accomplish this.

Thanks.


LXD public facing ip access to private ip help
#2

Hi Najib!

You can create a LXD profile with two entries about networking (macvlan, and bridged), then create a container using that profile.
Here is how to do that:

  1. I suppose you already have a profile according to https://blog.simos.info/how-to-make-your-lxd-container-get-ip-addresses-from-your-lan/ Let’s call that profile lanprofile.

  2. Copy that profile into a new name, let’s say, macbridge (macvlan and bridge).

    lxc profile copy lanprofile macbridge
    
  3. Add a new eth1 network interface for the lxdbr0 bridge.

    lxc profile device add macbridge eth1 nic nictype=bridged parent=lxdbr0
    
  4. By doing so, the macbridge profile will look like:

    devices:
      eth0:
        nictype: macvlan
        parent: enp3s0
        type: nic
    eth1:
      nictype: bridged
      parent: lxdbr0
      type: nic
    
  5. And now you can launch the container with

    lxc launch ubuntu:18.04 --profile macbridge mycontainer
    

When you get a shell in mycontainer, you will notice that eth1 did not get an IP address automatically. It’s up to you to make the configuration to get the IP address automatically. The manual way, anyway, is sudo dhclient eth1.


(Najib Nour) #3

PERFECT!!! i have been using that same config over and over thinking i was doing something wrong as it was not getting an ip but looks like i was just missing that last command within the container. (sudo dhclient eth1)

Thank you so much!!!


#4

Nice!

The default container image for Ubuntu has instructions to automatically ask for an IP address for the eth0 network interface only.
You can see this configuration (for a Ubuntu 18.04 container) in the following netplan configuration file at /etc/netplan/50-cloud-init.yaml. Here are the contents:

ubuntu@macbridge:~$ cat /etc/netplan/50-cloud-init.yaml 
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
ubuntu@macbridge:~$ 

You can manually add in there an entry for eth1 as well and then restart the container. Both network interfaces should get automatically an IP address.

It is also possible to add these instructions into the LXD profile for macbridge so that a new such container will get the configuration automatically as soon as you launch it. See about cloud-init and https://blog.simos.info/how-to-preconfigure-lxd-containers-with-cloud-init/ for this.


(Najib Nour) #5

Thanks again man i am looking into cloud-init right now and am implementing it into the profile! Thanks once again!!