You are not logged in.

#1 2016-06-03 21:37:27

clanger
Member
Registered: 2010-01-04
Posts: 33

allocating IPs to LXC containers

Hey, I have several LXC containers that need network access.

At the moment I am manually assigning the IPs in the the relevant config file and everything works:

lxc.network.type = veth
lxc.network.flags = up
lxc.network.name = eth0
lxc.network.link = br0
lxc.network.ipv4 = 192.168.1.6/24
lxc.network.ipv4.gateway = 192.168.1.1


However I would like for my LXC containers to be allocated IPs using DHCP, preferably from my router, but from a DHCP server on the host if necessary.
I tried using gateway=auto and leaving out the ipv4 address, which according to some sources allows the container to establish a link (presumably with dhcpcd),  but dhcpcd within the container reports no carrier.

How can I automatically allocate IP address to my lxc containers? Some of them run services that need to be accessible from the internet if that makes any difference.

Thanks

Edit:

My bridge is created using ip as described on the Network Bridge wiki
e.g.
ip link add br0 type bridge
ip link set enp3s0 master br0

Last edited by clanger (2016-06-03 23:13:46)

Offline

#2 2016-08-18 12:02:16

Jeroen)Mathon
Member
From: Netherlands
Registered: 2013-08-29
Posts: 82

Re: allocating IPs to LXC containers

Hey clanger,

You don't need to use bridges that way simply do the following.
Open your /etc/network/interfaces file and do the following.

iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast BROADCAST
        gateway 192.168.1.1

auto eth0:1
iface eth0:1 inet dhcpc
        netmask 255.255.255.0

This will allow you to allocate more ip's to network interfaces by linking them together.

Offline

#3 2016-08-18 12:03:46

Jeroen)Mathon
Member
From: Netherlands
Registered: 2013-08-29
Posts: 82

Re: allocating IPs to LXC containers

A little extra info, broadcast BROADCAST=Your broadcast ip

Offline

#4 2016-09-03 08:55:40

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: allocating IPs to LXC containers

Jeroen)Mathon, /etc/network/interfaces belongs to ifupdown, which is Debian's network management tool. Why would you propose such a thing here?


pkgshackscfgblag

Offline

Board footer

Powered by FluxBB