Assign VM own dedicated IP

Hello All,

Using Virtual Machine Manager on Ubuntu Mate. Using a full installation moving from Unraid. One item that was useful in Unraid, it had a dummy proof way to configure VM’s to have their own IP address on the local network. Can anyone ELI5 the way to do this?

P.S. I tried to do a search, I am sure this exists somewhere in the forum. Please bear with me.

Thank you
WWED

You have a few options:

  1. Set up a network bridge and assign the VM’s virtual NIC to the bridge
  2. Set up macvlan (or ipvlan), which is similar to a bridge but it bypasses a bunch of unnecessary stuff and tends to be faster (but requires more setup)
  3. Pass a dedicated physical interface through to the VM (PCIe passthrough), assuming you have or can add an extra PCIe or USB NIC
  4. Pass a virtual interface through to the VM (manually or allocated from a pool), assuming your NIC supports SR-IOV

Option 1 is definitely the easiest and most flexible; Option 3 is my go-to for “important” VMs, like an always-on Windows VM; Option 4 is my favorite and I would do it everywhere if not for the additional hardware requirements.

ETA: I jumped on one of my VFIO hosts to capture some snippets to give examples of options 1 and 4. I have some virtual NICs assigned to the bridge and others assigned to an SR-IOV pool. You can see that the host itself can access both networks directly, and it’s easy to mix in VLANs so let me know if you’d like to see examples of that.

Here’s a (slightly doctored) netplan:

network:
  version: 2
  renderer: networkd
  ethernets:
    if-1g:
      match:
        driver: igb
      set-name: if-1g
      optional: true
    if-10g:
      virtual-function-count: 4
      match:
        driver: ixgbe
      set-name: if-10g
      addresses:
        - 192.168.100.7/24
  bridges:
    br0:
      interfaces: [if-1g]
      parameters:
        forward-delay: 0
        stp: false
      addresses:
        - 192.168.1.7/24

Here’s the SR-IOV pool definition:

<network>
  <name>net-10g-0</name>
  <uuid>6ce15142-0901-433f-94f2-491c7189ccff</uuid>
  <forward mode='hostdev' managed='yes'>
    <pf dev='if-10g'/>
  </forward>
</network>

And an example of a domain with a virtual NIC on the above pool (you can optionally add a VLAN tag here if desired):

<interface type='network'>
  <mac address='52:54:00:3e:05:a5'/>
  <source network='net-10g-0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>

And an example of a domain with a virtual NIC on the bridge:

<interface type='bridge'>
  <mac address='52:54:00:64:74:0a'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
2 Likes

Like babinone mentioned, Bridge is probably what you want, so each VM can have a discreet IP without needing a dedicated nic.

You could check this out, for VMM specific details, but it might be an older version of the manager you use

1 Like

Shit thats right, I was able to do that in Unraid because my build at the time had 4 nics, now I am using 1. Will explore these options listed above.

Ah ok,

This is were my confusion started last time. Whether the creation of the network originates from the host or VMM.

If I use the Linux dot com guide and create a network I get an error saying the device is already in use.

If I create a bridge in network connections on the host, I am probably mis-configuring or not configuring enough. The VM never connects to the internet.

P.S. doing this via Wifi, if this throws the entire idea out the door.

Yes, it does. You will need to create a NAT-based network (or use the default network) and optionally set up port forwarding rules to expose virtualized services to your local network over the wireless connection.

a bridge nic does not care if it is wifi or cat6 or fiber, so long as it has a connection. the bridged nic does not even need an IP address itself necessarily.

as the host machine is ubuntu it probably will have a software firewall enabled, but NAT is probably still not needed here.

@wwed26 can you post your interfaces file and we can fix it for you.

It might be that wwed26 already has a bridge on the host, that he can use to connect to

1 Like

Typically you can only bridge a wireless interface when it’s in AP mode, not in station mode. Even if you could technically bridge a wireless interface in station mode, it’s highly probable that the AP it’s connected to will not allow traffic from any MAC addresses other than the one that originally authenticated. Ergo traffic from the virtual NICs on the bridge won’t get very far…

that is mostly true, and yet it is still possible to build out a functioning bridge over a wifi nic, with exceptions (and a lot of work).

it begs the question, why does OP only have wifi now if they had 4 nics available before? a hardware move may be easier.

If you’re referring to workarounds like parprouted, yes, quite a lot of work.

2 Likes

i have done USB passthrough and used a USB wifi dongle to get a VM to connect to a totally different network. it might be a possible solution.

or how about those Ethernet over coax adapters?

1 Like

I do, the default VMM bridge that is created, but fires up addresses in the 192.168.122.x range as opposed to 192.168.1.x

This is where I further noob. The interfaces file just contains source /etc/network/interfaces.d/* and that folder is empty.

you are going to need to come up with an alternative way of dealing with this. here are some options.

  1. figure out a way to get an ethernet cable to the HOST machine. (ethernet over COAX, run a real cable, or use a wireless BRIDGE device)
  2. USB passthrough of wireless NICs to each VM.
  3. relocate the host to somewhere with a network cable.

the software only options are not feasible in this install.

1 Like