Create a container with IP from the wlan subnet via a remote lxd client

With

sudo lxc remote add device2 192.168.2.10

we have connection with the lxd at the above IP.

So if we do

sudo lxc launch ubuntu:18.04 device2:cont1

we will create to device2 a container with name cont1.

Is possible to do something like the command below ?

sudo lxc launch ubuntu:18.04 device2:myrouted --profile default --profile routed_192.168.2.200

If this is possible , the routed profile should be loacally or remotely to device2(192.168.2.10) host ?

Expecting after that to see at 192.168.2.10 a container with ip = 192.168.2.200.

Generally , is this possible localy or remotely ?

The command above should work and will use the profiles from device2.

Ok Stephane i will test it and i will inform here for the results here.

Thanks !!

It didn’t work. The container started but it hadn’t an ip address.

The profiles were created at device2. I tested locally executing

sudo lxc launch ubuntu:18.04 myrouted --profile default --profile routed_192.168.2.200

and the container with name myrouted had 192.168.2.200 as an ip

Edit : It seems that when i am using a custom image ( imported from a tar.gz ) my container does not take 192.168.2.200 as an IP ( either doing this localy or remotely ).

Any help ???

Yes the problem is that i create a container with a custom image which has been imported from a tarball and i use these profile settings for getting a subnet ip.

From the other hand when i am doing

sudo lxc launch custom_image_name cont1

cont1 has for example 10.48.91.36.

Thanks in advance for the help.

Anyone?

Your custom image may be containing some DHCP client state in /var which makes it not fully acquire a new address on boot.

Is there a way to overcome this?
For example, starting the container with the custom image and after that, setting up the wlan ip?

As @stgraber suggested you should ensure your container image doesn’t have any network config inside it that tries to get its IP configuration via DHCP. Often this causes the static IP added by the routed NIC to be removed as it tries to allocate one via DHCP (which will fail).

Take a look at /etc/network/interfaces file as it may be in there.

Thanks Thomas. I am inside the container which i have created from this custom image.
I am at /etc/network and i have found the file interfaces along with if-pre-up.d and if-up.d.

What am i suppose to doing know ? i did

cat interfaces

but i took a message which says that ifupdown has been replaced by netplan(5)

If you remove the netplan config file /etc/netplan/50-cloud-init.yaml as this by default contains config to use DHCP e.g.:

network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true

I found this file. So if i understand correctly i must delete this file from the container and then export the image as a tar.gz and after that doing the above procedure will have as a result tha wlan ip from the local subnet , right ?

I figured it out.

  1. Delete /etc/netplan/50-cloud-init.yaml from the container.
  2. Publich the container as an image ( with alias for example CustomImage)

sudo lxc launch CustomImage myrouted --profile default --profile routed_192.168.2.200

has a result to create a container with image CustomImage and ip 192.168.2.200 which can ping everything in the same wlan subnet and www.google.com for example.

Cheers !!! :slight_smile: :see_no_evil: :fist_right: :fist_left:

1 Like