Hey guys,
I dug through a lot of posts and forums today trying to figure out how to setup my containers so they are reachable from the outside like a physical machine would. I read Simos’ great writeups and tried to “translate” his LXD setup but failed unfortunately. Over on reddit I got told that I might have better luck here…
My desktop runs VoidLinux x86_64, this is what I did after reading dozens of posts about bridge networking:
First I created the network bridge:
> ip link add name br0 type bridge
> ip link set dev br0 up
> ip link set dev enp2s0 master br0
When I ran ip a
I could see that my DHCP server had given the IP address which was usually given to enp2so
to br0
.
> ip a
enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
link/ether 50:e5:49:5a:bb:74 brd ff:ff:ff:ff:ff:ff
inet6 fe80::52e5:49ff:fe5a:bb74/64 scope link
valid_lft forever preferred_lft forever
br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 50:e5:49:5a:bb:74 brd ff:ff:ff:ff:ff:ff
inet 10.1.0.2/16 brd 10.1.255.255 scope global dynamic noprefixroute br0
valid_lft 41997sec preferred_lft 34843sec
inet6 fd07:ca45:2468::851/128 scope global noprefixroute
valid_lft forever preferred_lft forever
inet6 fd07:ca45:2468:0:d4c7:eea1:eff5:b69a/64 scope global mngtmpaddr noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::3043:61ff:fe8a:170/64 scope link
valid_lft forever preferred_lft forever
After this I created the container:
> lxc-create -t download -n test
I selected a VoidLinux container so there was no “switching” between tools for me.
> cat /var/lib/lxc/test/config
# Template used to create this container: /usr/share/lxc/templates/lxc-download
# Parameters passed to the template:
# Template script checksum (SHA-1): 9893b2e0dba7be0d74cf38537bebe0af939c269c
# For additional config options, please look at lxc.container.conf(5)
# Uncomment the following line to support nesting containers:
#lxc.include = /usr/share/lxc/config/nesting.conf
# (Be aware this has security implications)
# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.arch = linux64
# Container specific configuration
lxc.rootfs.path = dir:/var/lib/lxc/test/rootfs
lxc.uts.name = test
# Network configuration
lxc.net.0.type = empty
Which I changed to this:
> cat /var/lib/lxc/test/config
...
# Network configuration
lxc.net.0.type = veth
lxc.net.0.link = br0
lxc.net.0.flags = up
lxc.net.0.veth.pair = test
When I start this container I do not get a IPv4 from my DHCP server, but I can ping its IPv6 address from my router:
> ip a # on host machine
test@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br0 state UP group default qlen 1000
link/ether fe:cb:01:72:6d:5c brd ff:ff:ff:ff:ff:ff link-netnsid 2
inet6 fe80::fccb:1ff:fe72:6d5c/64 scope link
valid_lft forever preferred_lft forever
> lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED
test RUNNING 0 - - fd07:ca45:2468:0:1c5b:e5ff:fe48:ed04 false
I think I missed something here but since I just started with LXC I can not figure out where I messed up.
Any help would be very much appreciated, thanks in advance.