Public IP in the CT

Well LXD can only help with getting the public IP into your container if the public IP is already routed to your LXD host. If you only have a single IP and it is bound on your externally facing router then you cannot have it also inside your container.

Perhaps what you’re looking for instead is to have one or more ports on your external router (and thus your public IP) forwarded into your container?

What is it that you’re trying to achieve, beyond getting the public IP into the container that is?

I want for example my containers to have IPs like , for example , a new device which has connected to my home wlan. Meaning an IP like 192.168.2.X . I want the containers to be servers. In fact it doesn’t bother me to ping google for example . I want if for example i have a desktopA with 192.168.2.20 and desktopB with 192.168.2.15 , the i want to create at desktopB a container with name ImageSvc and ip 192.168.2.X so i can directly communicate with desktopA with anything else ( i have used proxy device which matches the ports and forwards the request).

Ah, so you don’t want your public IP in your container, but you want to bridge your containers onto your internal LAN.

(192.168.2.0/24 is a non-routable private IP range, not a public range, hence the confusion).

In that case you could either use the routed NIC type as per the link you originally sent, or you could setup a new bridge on your LXD host and use that as the parent device with the bridged NIC type.

Yes, I am sorry.
Any help/guide about how i am supposed to doing that ? :slight_smile:

So first you would want to convert your LAN interface on your laptop to a bridge:

See https://netplan.io/examples#configuring-network-bridges

Then once you have a network bridge, you can replace the existing NIC in your container with one connected to your bridge using:

lxc config device add <container> eth0 nic nictype=bridged parent=<bridge interface name>

Note: You said you were on wifi, I am not certain, but there may be issues with bridging onto a wifi network due to the way wifi uses additional MAC addresses. If that doesn’t work then try using the routed network as per the guide you originally linked to.

Yes that may be an issue with the mac addresses.

My first problem with routed was that i didn’t know what i changes should make to the routed profile that i was creating.

You don’t have to use a profile you can just do:

lxc config device add <container> eth0 nic nictype=routed parent=<lan interface> ipv4.address=<static lan address>

Then ensure that inside your container you remove the netplan config file in /etc/netplan to prevent eth0 from being reconfigured for DHCP, and restart your container.

If your solution doesn’t work with WiFi i am going to use routed from simos guide.

I understand everything simos has at his blog except from what changes i should make to the routed profile.

========================================================
You can create an empty profile, then edit it and replace the existing content with the following (lxc profile create routed, lxc profile edit routed).

config:
user.network-config: |
version: 2
ethernets:
eth0:
addresses:

  • 192.168.1.200/32
    nameservers:
    addresses:
  • 8.8.8.8
    search: []
    routes:
  • to: 0.0.0.0/0
    via: 169.254.0.1
    description: Default LXD profile
    devices:
    eth0:
    ipv4.address: 192.168.1.200
    nictype: routed
    parent: enp6s0
    type: nic
    name: routed_192.168.1.200
    used_by:

==============================================================

Simos says this.

Which fields i should change so it can work to my computer .?

Any references to 192.168.1... should be your LAN subnet instead.

1 Like

So i leave everything else as it is ?
to: 0.0.0.0/0
via: 169.254.0.1 (what about this ?)

----> parent: enp6s0 (should i change this with my wirelles interface ? )

Ah yes change parent too. Everything else leave as is.

1 Like

Ok ok . Thanks a lot Thomas.

I would try both of them and i will post here for the results.

Again many thanks to all who help :slight_smile: :slight_smile:

It worked. As Thomas mentioned following simos guide (https://blog.simos.info/how-to-get-lxd-containers-get-ip-from-the-lan-with-routed-network/) you can do exactly what simos is saying except for making some changes to the configuration file of the routed profile.

  1. Change parent and put there the name of the interface which has the ip of your lan.
    For example, I put wlo1 because i am connected to a wlan
  2. Instead of 192.168.1.200 , put your lan subnet instead.

Ping www.google.com and all the other devices in wlan worked perfectly :slight_smile:

1 Like