You are not logged in.

#1 2016-12-12 16:28:03

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

How to get a Linux container to use dhcp

Our wiki (lxc page) details setting up a static IP address for containers in /var/lib/lxc/xxx/config but I'm wanting to have the container use dhcp.  Many of the hits I am finding via googling seem specific to debian referencing files we do not ship (/etc/default/lxc-net and /etc/lxc/dnsmasq.conf for example).  So, is anyone running a dhcp assigned container on Arch and if so, what is the trick to configure it as such?  Thanks.

One reference suggests omitting the lxc.network.ipv4 = line as well as the lxc.network.ipv4.gateway = line from /var/lib/lxc/rhea/config (and assigning the nwaddr therein) and then using netctl WITHIN the lxc to get an IP address, but that is ineffective leaving me with a container without a network at all.

For reference, here is my config that works for a static setup just fine:

lxc.utsname = rhea
lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.ipv4 = 10.1.8.101/24
lxc.network.ipv4.gateway = 10.1.8.1
lxc.network.name = eth0
lxc.network.hwaddr = bc:b1:21:11:1b:2a

My host NIC is setup on a netctl bridge:

% cat /etc/netctl/lxcbridge
Description='lxc bridge'
Interface=br0
Connection=bridge
BindsToInterfaces=('eth0')
IP=static
SkipForwardingDelay=yes
Address='10.1.8.2/24'
Gateway='10.1.8.1'
DNS=('10.1.8.1')

Last edited by graysky (2016-12-12 17:00:41)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2016-12-12 21:13:03

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: How to get a Linux container to use dhcp

I don't know what you are doing, but this works for me

$ cat /var/lib/lxc/common/lxc-config
# generic
lxc.autodev = 1
lxc.tty = 0
lxc.pts = 1024
lxc.mount.auto = proc sys:ro
lxc.cap.drop = mknod sys_module mac_admin mac_override sys_time sys_rawio sys_pacct setfcap
lxc.kmsg = 0
lxc.stopsignal = SIGRTMIN+14
lxc.haltsignal = SIGRTMIN+4
lxc.seccomp = /usr/share/lxc/config/common.seccomp

# networking
lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.name = eth0
lxc.network.mtu = 1500

# cgroups
lxc.cgroup.devices.deny = a
lxc.cgroup.devices.allow = c 1:3 rwm
lxc.cgroup.devices.allow = c 1:5 rwm
lxc.cgroup.devices.allow = c 1:7 rwm
lxc.cgroup.devices.allow = c 1:8 rwm
lxc.cgroup.devices.allow = c 1:9 rwm
lxc.cgroup.devices.allow = c 5:0 rwm
lxc.cgroup.devices.allow = c 5:1 rwm
lxc.cgroup.devices.allow = c 5:2 rwm
lxc.cgroup.devices.allow = c 136:* rwm
$ cat /var/lib/lxc/arch1/config
lxc.include=/var/lib/lxc/common/lxc-config
lxc.utsname=arch1
lxc.rootfs=/var/lib/lxc/arch1/rootfs

Notice, no ipv4 or gateway. Also, check lxc.cap.drop and lxc.mount.auto.

Now, on br0 I run dnsmasq and forward traffic to an external NIC -- your setup varies, so adjust accordingly. Then, running dhcpcd inside the container gives me a functional network...

Last edited by Leonid.I (2016-12-12 21:14:05)


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

Board footer

Powered by FluxBB