Ubuntu 18.04 ships with netplan as new network interface configuration tool, aiming to replace the previous (but highly stable) /etc/network/interface method with yaml-based configuration files in /etc/netplan/.
However netplan is pretty new and it can cause some weird behavior in certain setups. This lesson was also learned today using a LXC 3.0 container.
On the LXC host (also running Ubuntu 18.04), the LXC's config contained the static ip address configuration in its config file:
root@host:~# grep lxc.net /var/lib/lxc/container1/config
lxc.net.0.type = macvlan
lxc.net.0.macvlan.mode = bridge
lxc.net.0.flags = up
lxc.net.0.link = virbr2
lxc.net.0.ipv4.address = 10.15.100.139/25
lxc.net.0.ipv4.gateway = 10.15.100.129
But when the container was started, no IP address was shown for it (but it did for another container):
root@host:~# lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED
container1 RUNNING 1 - - - false
container2 RUNNING 1 - 10.150.66.146 - false
Even starting the container with debug log enabled (lxc-start -n container1 -o /var/lib/lxc/container1/output.log -l DEBUG) did not show a reason why the IP address was not configured within the container.
On the other hand, container2 on the same system, running Ubuntu 18.04 as well, had no issues getting the IP address from the LXC host and running it in its OS. What's the difference between these two? Then I remembered.
In a default container setup, the container will run dhcpd at the begin to try to obtain an IP address, even though an address was configured in the container's config file. In the past years I used automation to disable the dhcp requests by removing eth0 from /etc/network/interface. But now with netplan this is a bit different. The default config in a LXC container looks like this:
root@container2:~# cat /etc/netplan/10-lxc.yaml
network:
version: 2
ethernets:
eth0: {dhcp4: true}
In an attempt to solve the container running dhcp during boot, I set dhcp4 to false in container1:
root@container1:~# cat /etc/netplan/10-lxc.yaml
network:
version: 2
ethernets:
eth0: {dhcp4: false}
I thought this would lead to prevent dhcp being run inside the container. Well, dhcp indeed did not run during boot anymore, however this also prevented the eth0 interface from getting any ip address.
So what's the lesson here? Basically the original configuration (with dhcp enabled on eth0) could be left untouched but it will slow down the container's boot time because of dhcp trying to find an (additional) ip address for eth0. Removing the netplan yaml's in the container might help, too, but I didn't try that. I went one step further and completely removed netplan from the container's OS:
root@container1:~# apt-get remove netplan.io
Afterall, netplan is not needed inside the containers as they all get their (static) IP addresses from the LXC host. At least in my setups.
As soon as netplan was removed and the container in question (container1) was rebooted, the address configured in /var/lib/lxc/container1/config was immediately used and network worked again.
Igor from wrote on Sep 2nd, 2021:
I spent a lot of hours struggling with no ip address assigning for Ubuntu running inside lxc container.
But this remedy was so simple and effective :)
Thank you very much for this post!
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office OpenSearch PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder