Proper NIC name to Set a Static IP for a Virtual Machine

I am trying to port forward for an Ubuntu Focal VM (sourced from ubuntu:) on the current/latest version of LXD. It requires a static IP (simple to do for containers). But for VMs, two things differ:

  1. I set it using lxc config device override <instance> <nic> ipv4.address=a.b.c.d. But the fact that in lxc list NIC is called eth0 when the VM starts then changes to enp5s0, it seems to have worked using eth0. Is it proper to setup using eth0? Or should I wait for it to finish booting and use enp5s0?

  2. I will leave this here as a reference (not a question), since it is explained in Virtual machine proxy devices - #2 by tomp and Instance configuration - LXD documentation that the only way port fwd VMs is with nat=true (after assigning a static IP to the VM). The actual cmd sequence is (note the nat=true part, it is mentioned but the cmd not shown). For the sake of completeness I am listing the entire sequence here:

lxc profile create $instance-$name-$port-$tcpudp
lxc profile add $instance $instance-$name-$port-$tcpudp
lxc profile device add $instance-$name-$port-$tcpudp hostport-$ct-$name-$port-$tcpudp proxy connect="$tcpudp:$ip:$port" listen="$tcpudp:<HostStaticIP>:$port" **nat="true"**
... you might want to add cmds to open up the host's firewall also in this routine.

where $name is the name of the rule/profile, $ip is the static IP of the container, $port is the port and $tcpudp is one or the other.

The LXD interface name is the one you see in lxc config show and so will always be eth0 in your case.

The name you see in lxc list is the one reported by the VM. Until the agent is up, LXD assumes it’s named after the LXD device so will show eth0. Once the agent is functional, this changes to the real name which for VMs is typically enp5s0.

1 Like