Just after that reply by @tomp was a post (now withdrawn) by @MSTY that still, these instructions still do not work on Ubuntu container images. Then, @tomp replies, but the withdrawn post makes the conversation difficult to follow. In effect, the issue is that netplan on Ubuntu container images really tries to do the default, which is DHCP on the interface. You need to replace (in the container) the file /etc/netplan/* to the version found in that thread. You can do that either manually (lxc file push), or you can pass the information to the container through cloud-init.
But on Ubuntu container images (ubuntu:) you would need to use cloud-init in the LXD profile if you want to do something like the following (i.e. launch the container in a single line).
where test995 is the name of my test conatiner and network is working now. So, may be it’s error in some template? Does this file generates automatically when I’m adding routed network?
btw, is there a way to set default nameserver (8.8.8.8) both for ubuntu and centos? Or should I do it manually?
So this comes down to the difference in behaviour of DHCP client process inside distributions.
In CentOS 7, the dhclient process is still running, but it seemingly does not remove preconfigured addresses from the interface until it actually gets a lease (which it won’t). So the LXD configured IP remains.
In Ubuntu 18.04 however, it uses netplan which in turn uses systemd-networkd. I’m not sure which one of those clears the existing interface config, but it does happen.
The reason adding eth0: {dhcp4: true; hostname: test995} “fixes” the problem is because that is an invalid netplan config, and using netplan apply command will show this. Because this is invalid, netplan fails to start, and this leaves the LXD configured IP in place.
You can configure nameservers using cloud-init, see
Unfortunately there doesn’t appear to be a way I can find in netplan of telling it to just configure nameservers and leave the rest of the IP configuration alone. If you just set nameservers in netplan it still wipes out the LXD configured IPs on the interface.