If you haven’t specified an IP while creating an
LXCinstance, you might end up with an IP that doesn’t suit your needs. There’s a quick and easy way of setting IP addresses for LXC containers. It is faster and less requires less tinkgering than trying to fix the IP either on the host dhcp side or the guest dhclient side.
In the below example we’re changing the IP address for the container called
grafana. We will have to stop the container before we can do it. The IP we’re setting for this example is
10.0.0.30. The bridge interface on the host is
lxdbr0 and the interface name inside the container is
eth0. Change these parameters for your environment.
lxc stop grafana lxc network attach lxdbr0 grafana eth0 eth0 lxc config device set grafana eth0 ipv4.address 10.0.0.30 lxc start grafana
You can check the change using
In my case the IPs come from
dnsmasq on the host. I believe this is the default setting. The above method should work for static IPs (without DHCP) as well.