User Tools

Site Tools


lxcmanualip

LXC – Disable DHCP

With regular LXC, I wasn't able to set the IP in the container config. The networking config format seems to have changed a few times, or across distros, and a lot of the solutions seem to refer to wrappers like LXD.

So instead, here's just the default way to manually configure the IPs within the container – it doesn't necessarily work that way in a distro from an ISO, but in the versions you'd get with lxc-create -t download.

netplan (Ubuntu)

/etc/netplan/10-lxc.yaml
  1. network:
  2.   version: 2
  3.   ethernets:
  4.   eth0:
  5.   dhcp4: false
  6.   addresses:
  7. - 192.168.122.114/24
  8.   routes:
  9.   - to: default
  10.   via: 192.168.122.1
  11.   dhcp-identifier: mac
  12.   nameservers:
  13.   addresses:
  14. - 192.168.122.31
  15. - 9.9.9.9

Apply with netplan apply.

systemd-networkd (Debian)

Debian uses systemd-networkd. This will also work on Ubuntu (and others, of course), if you disable or uninstall netplan.

/etc/systemd/network/eth0.network
  1. [Match]
  2. Name=eth0
  3.  
  4. [Network]
  5. Address=192.168.122.57/24
  6. Gateway=192.168.122.1
  7. DNS=192.168.122.31
lxcmanualip.txt · Last modified: by wolfo

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki