Skip to content

Instantly share code, notes, and snippets.

@dominickpastore
Last active March 5, 2024 00:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominickpastore/220e46df2ffd394f1f3903024d732326 to your computer and use it in GitHub Desktop.
Save dominickpastore/220e46df2ffd394f1f3903024d732326 to your computer and use it in GitHub Desktop.
  • Container is named "guest"
  • Bridge is named lbr0
  • Bridged interfaces are enp1s2 on the host and eth1 in the container
  • According to the docs, the host interface enp1s2 is expected to be unconfigured before starting, but I'm not sure if that's a strict requirement.

Commands:

sudo ip link set up enp1s2
# Stopping the guest first probably isn't necessary, but I didn't test without it.
lxc stop guest
lxc network create lbr0 bridge.external_interfaces=enp1s2 ipv4.address=none ipv4.dhcp=false ipv4.nat=false ipv6.address=none ipv6.dhcp=false ipv6.nat=false
lxc network attach lbr0 guest eth1
lxc start guest
lxc exec guest -- /bin/bash

Then configure eth1 for DHCP in the container using whatever network configuration tools are present.

Alternatively:

I believe it's possible to modify the existing default bridge, lxdbr0:

lxc network set lxdbr0 bridge.external_interfaces=enp1s2
lxc network set lxdbr0 ipv4.address=none
lxc network set lxdbr0 ipv4.dhcp=false
lxc network set lxdbr0 ipv4.nat=false
lxc network set lxdbr0 ipv6.address=none
lxc network set lxdbr0 ipv6.dhcp=false
lxc network set lxdbr0 ipv6.nat=false
@EMCP
Copy link

EMCP commented May 30, 2021

according to my quick attempt, you cannot bridge configured network interfaces.. so be sure to drop those first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment