LXD container set static ip

5,779

Solution 1

The solution is to create multiple bridged interfaces on your host machine and then assign one bridge to one container.

This is a perfect tutorial: https://wiki.hetzner.de/index.php/KVM_mit_Nutzung_aller_IPs_aus_Subnetz/en

Solution 2

  1. configure standard lxd bridge

  2. create file /etc/default/lxd-static-ip.conf with 1 line per host as:

    dhcp-host=<containername>,<static-ipaddress>
    
  3. edit /etc/default/lxd-bridge, set LXD_CONFILE variable to:

    LXD_CONFILE="/etc/default/lxd-static-ip.conf"
    
  4. restart lxd-bridge (e.g. systemctl restart lxd-bridge), restart your containers

Share:
5,779

Related videos on Youtube

SEUH
Author by

SEUH

~

Updated on September 18, 2022

Comments

  • SEUH
    SEUH over 1 year

    There've been a lot of questions and threads about this but none of them solves my problem.

    I want to assign a specific ip to a specific container WITHOUT configuring it inside the container. The goal is to BIND the container to a specific ip.

    • The containers CAN'T use the same bridge as interface due to ip/packet spoofing.

    • There are 2 public ip's pointing to my host server. The first one should stay to the host, the second to a specific container.

    1. Try: Using the lxd bridge

    If i use the lxd bridge, i can assign every container a fixed ip address from the lxd bridge network (meaning: the lxd bridge creates a private network with an ip range that is NOT public but can be accessed from the host server)

    My host system has access to the private lxd network and the public network. Now i could route (on the host system) a public ip to a private ip and therefore a specific container but i haven't found a way to do this since the incoming traffic from the public ip needs to be forwarded to the private ip und the outgoing traffic from the private ip to the public ip.

    2. Try: Creating a network interface for every ip and assign the specific interface to the container

    Since this is much more complicated (and i'm a newbie in linux) i've tried following the instructions from https://lists.linuxcontainers.org/pipermail/lxc-users/2016-March/011271.html

    But it didn't work out.

    I would go with the first attempt cause it should work if i can route the ip's to each other but i don't know how.

    EDIT

    Just saw this answer How can I restrict an LXD guest to using a single public IP address?

    Seems like this could work. Can'T test it at the moment because my home router can't assign free ip adresses to devices..

  • SEUH
    SEUH about 7 years
    Under 1. there is exactly explained what you say. The problem is solved, but thanks for the effort
  • 67hz
    67hz about 2 years
    Does anyone have this tutorial since the link no longer works? In the future please post the comments not just a link! :-) Thanks