Score:-1

Making all Linux network interface (bridged) in a qemu VM use dhcp

ec flag

I have a small application which takes in kernel code, and spins up VMs. I've been using this for kernel development. It is helpful and very fast when I want to spin up VMs with different kernel codes. The application uses qemu, and generates the qemu command on the fly based on the given options. The problem I am facing is ever changing network interface names.

The initial setup was such, that the interface names were ens*, and I had the following configuration in the /etc/network/interfaces to configure them to dhcp

allow-hotplug ens3
iface ens3 inet dhcp

I had a number of them, to make sure if the names gets pushed from ens3 to ens7 (maybe due to added qcow as scsi devices), the network interface ens7 still gets configured. It was working fine.

Now with the new Linux kernel 6.4-rc, I observe that the names of the interfaces are coming up as enp0s*. Now my /etc/network/interfaces configuration is not working. I can't keep changing the /etc/network/interfaces file according to kernel, cause that defeats the purpose of simply changing kernel code path and spinning up VMs. Btw, this was working fine for 2 years, and for kernel ranging from 4.19 to 6.1 (havent tested 6.2 and 6.3)

My question is, is there a default way to configure the network, such that any and all network interfaces come up with dhcp. Basically, something like

allow-hotplug all
iface all inet dhcp
Score:2
ws flag

There's several ways of doing this.

You could

  • generate /etc/network/interfaces during the boot process, using the names assigned
  • disable the renaming of devices (initially assigned eth0, eth1 ... will still be available by speciftying net.ifnames=0 on the kernel command line
  • Use udev rules to assign a name based on the MAC address
Haris avatar
ec flag
The second one changes it to older `eth` format. I like the first one. Can you point out how to do this? Maybe yourself, or a link which describes this clearly.
ws flag
You'll find a list of the devices in /sys/class/net - just exclude 'lo' and mailemerge your config.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.