1

I have several lxc containers that need network access. At the moment I am manually allocating them IP addresses in the relevant config file as so:

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 

This works but does not scale and can conflict with my routers DHCP allocation. I try to use my router dhcp by leaving out the lxc.network.ipv4 lines (as described online elsewhere), and the container starts but dhcpcd reports no carrier. lxc-ls --fancy also does not show my container has an IP address. The bride is up and lxc.network.link set in the config file.

How can I use DHCP with my containers? Is it possible to use my routers DHCP, or do I need to run a server on my host? Some of my containers do need to be accessible from the outside, where as some only need to communicate to other containers/host.

I'm running arch linux, most of the help online seems ubuntu specific.

2 Answers 2

0

Make sure netctl and dhcpcd is installed inside the container (pacman -Q netctl dhcpcd) then run the following in the container:

cat > /etc/netctl/eth0 Connection=ethernet IP=dhcp Interface=eth0 

Press CTRL-D to write the file. Then enable the profile by running:

netctl enable eth0 

Finally restart the container and you should have a DHCP assigned IP address.

1
  • This is a very heavyweight solution for a LXC container even 10 years ago. Using busybox udhcpc would make more sense. Commented Nov 4, 2023 at 3:35
-1
cat <<\EOF >> /etc/netctl/eth Connection=ethernet IP=dhcp Interface=eth0 EOF 

I thought this would be a better way of creating the file.

1
  • 1
    Now that I've edited this, I see it's not really a full answer in context. The question asks about setting up DHCP for a container and the other answer covers that. It looks like this is just another option for part of the answer, and I don't see any real improvement over the other. Why are you appending to the file? Why quote the EOF marker? Commented Dec 15, 2021 at 1:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.