I have LXD container running the official fedora 33 image, and I am trying to add a routed nictype to it. I have LXD installed on Debian 10 machine via snap.
I have successfully setup routed nics on Debian, Devuan and CentoS however the behavior on fedora container is different.
After executing: lxc config device add c1 eth0 nic nictype=routed parent=eth0 ipv4.address=$ip
lxc list command shows that the container does not have any IPv4 at all
lxc list
+------+---------+------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+------+------+-----------+-----------+
| c1 | RUNNING | | | CONTAINER | 2 |
+------+---------+------+------+-----------+-----------+
eth0 interface appears disconnected inside the container:
nmcli device
DEVICE TYPE STATE CONNECTION
eth0 ethernet disconnected --
lo loopback unmanaged --
and when I try to change the IP address of that interface it says:
I think the issue is with nictype=routed parent=eth0. That is, it says that the host has an interface called eth0. Most hosts have interfaces named something like enp3s0. Can you verify that the network interface on the host is indeed eth0?
Hi, yes, the interface on the host is indeed eth0, since it is old debian 7 upgraded as the time went to debian 10, so the interface name did not changed.
As I stated above, using this method I was able to set routed nic on my debian and centos containers without any problem. But fedora somehow refuses this method.
You manage to get routed to work without a LXD profile with Debian, Devuan and CentOS? When you use routed, you need to touch a bit the networking configuration of the container so that works fine once it boots up. Because with routed, the container does not receive any network configuration over DHCP.
In debian I had to set the static ip inside /etc/networking/interfaces, but even before that lxc list already showed that the container has the given routed IP. However in fedora I cannot even execute a command to set the static IP because the interface somehow does not event exists (see in my first post).
There may be a udev issue in the image we saw similar issues with centos 8, network manager is rather picky up which devices it will manage. Will take a look.
I used the image images:fedora/33/cloud instead, which is like the images:fedora/33 but has cloud-init preinstalled and configured for you. I suppose the /cloud variant has ifconfig preinstalled.
Admittedly, you do not need to use ifconfig. I just used it for demonstration purposes. Newer versions of Linux distributions have by default the ip package. Therefore, per this guide, the equivalent command is
Here is my try. Note that I am using LXD profiles for this.
$ lxc launch images:fedora/33/cloud fedora --profile default --profile routed_fedora
Creating fedora
Starting fedora
$ lxc list fedora
+--------+---------+----------------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------+---------+----------------------+------+-----------+-----------+
| fedora | RUNNING | 192.168.1.201 (eth0) | | CONTAINER | 0 |
+--------+---------+----------------------+------+-----------+-----------+
$ lxc shell fedora
[root@fedora ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0@if40: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether d2:4d:3d:1d:55:be brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.1.201/32 brd 255.255.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@fedora ~]#
As I said earlier, there is need for extra work to make this all work. It does not work yet.
First, you need to use a LXD profile with the appropriate configuration.
Then, you need to manually complete the setup of the networking in the container.
Finally, touch up the LXD profile again so that it performs automatically for you that manual configuration you just did earlier.
It is great that you managed to get it working manually. If you are comfortable with that, then all is good.
If you would like to automate the process, then you can use cloud-init to do so. For that read carefully https://blog.simos.info/how-to-get-lxd-containers-get-ip-from-the-lan-with-routed-network/
As I said earlier, you can insert the manual instructions in an LXD profile. The profile default is the default profile, and is applied anyway. When you want to add another profile, then you need to specify both the default and you additional profile.
I found that the Fedora cloud-init wasn’t applying the network config from @simos blog post.
It may be that because the interface already has an address, the NetworkManager is leaving it alone (the connection in nmcli showed it as being configured externally).
However you can automate the steps you documented above using a cloud-init profile as follows: