[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

how to set fixed virtual-ethernet MAC address in VM while still doing DHCP?



I have a virtual machine (VM) running Debian 10.10.0 ("Buster") x86-64,
running in an OpenBSD 7.0 host (using the OpenBSD 'vmm' VM monitor).
The Debian VM's (IPv4) network connectivity to the host (which is configured
to forward selected network traffic to/from the outside world as appropriate)
is configured via the VM's /etc/network/interfaces:

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).

    source /etc/network/interfaces.d/*

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    allow-hotplug enp0s2
    iface enp0s2 inet dhcp

This works fine: the VM has a (virtual) network interface enp0s2 whose
IP address is assigned by the host via DHCP.  (The host OpenBSD vmm provides
a DHCP server for this purpose, and the hosts's networking configuration
uses the DHCP-assigned IP addresses to keep track of different VMs.)
The resulting network configuration is this:

    tux# ifconfig enp0s2
    enp0s2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 100.64.2.3  netmask 255.255.255.254  broadcast 100.64.2.3
            inet6 fe80::fce1:bbff:fed1:5246  prefixlen 64  scopeid 0x20<link>
            ether fe:e1:bb:d1:52:46  txqueuelen 1000  (Ethernet)
            RX packets 2  bytes 684 (684.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 9  bytes 1292 (1.2 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    tux#

(As is evident from the ifconfig output, there is also an IPv6 address
assigned to the interface, but I'm not using IPv6 here.)

My problem is that by default, Debian randomizes the (virtual) ethernet
MAC address of enp0s2 each time I reboot the virtual machine, and this
breaks the license manager for some commercial site-licensed software
(Maple) I'm running in the virtual machine.

So, I'd like to disable Debian's virtual-ethernet MAC address randomization
and set a fixed virtual-ethernet MAC address for enp0s2, while still using
DHCP to configure Debian's IPv4 networking.  (I emphasize that the fixed
ethernet MAC address I want to set is that of the Debian enp0s2
virtual-interface, NOT that of the OpenBSD host's virtual-interface.)

According to Debian's man 5 interfaces, what I want should be be easy:
just append the line

    hwaddress ether fe:e1:01:02:03:04

at the end of /etc/network/interfaces. If I do this I do indeed get
enp0s2's (virtual) ethernet MAC address set as I desire... *but* Debian
doesn't configure IPv4 networking on this interface:

    tux# ifconfig enp0s2
    enp0s2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet6 fe80::fce1:bbff:fed1:283  prefixlen 64  scopeid 0x20<link>
            ether fe:e1:bb:d1:02:83  txqueuelen 1000  (Ethernet)
            RX packets 4  bytes 168 (168.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 107  bytes 32568 (31.8 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    tux# 

I have also tried changing the last line of /etc/network/interfaces to

    iface enp0s2 inet dhcp hwaddress fe:e1:bb:d1:02:83

but this gets me a DHCP-configured network interface with a randomized
virtual-ethernet MAC address, i.e., Debian ignores my attempt to set a
fixed virtual-ethernet MAC address is ignored.

I have also tried appending the line

    pre-up ifconfig enp0s2 hw ether f1:e1:01:02:03:04

to /etc/network/interfaces. This sets the virtual-ethernet MAC address
ok, but once again enp0s2 doesn't get an IP address.

So, my question is, how can I set a fixed virtual-ethernet MAC address
in Debian and still have the system use DHCP for IPv4 network configuration?

I would strongly prefer a command-line (non-GUI) solution, as running
anything GUI on the VM would require ssh over a working network to the
VM, and right now that's somewhat lacking.

Thanks,
--
-- "Jonathan Thornburg [remove color- to reply]" <jthorn4242@pink-gmail.com>
   on the west coast of Canada, eh?
   "There was of course no way of knowing whether you were being watched
    at any given moment.  How often, or on what system, the Thought Police
    plugged in on any individual wire was guesswork.  It was even conceivable
    that they watched everybody all the time."  -- George Orwell, "1984"


Reply to: