2

I have a virtualization host (could be either VSphere or SCVVM) that has four NICs, two 1 gbps and two 10 gbps. This machine hosts a VM on two vSwitches with unique names (such as vSwitch0 and vSwitch1), one is on a 1 gbps NIC and the other on a 10 gbps NIC.

This VM is generated automatically through a long powershell process that creates the imports vm definition & empty virtual disk, installs the OS, installs other software, etc.

My problem is that in the guest OS (Server 2012 R2) the network adapters are simply labeled 'Ethernet Adapter' and 'Ethernet Adapter 1'. I cannot tell which is on 'vSwitch0' or 'vSwitch1'. I need each adapter to have a very specific IP based upon which virtual switch it is connected to.

Any ideas? I need to somehow configure this in the powershell script that configures the guest OS.

Thanks in advance!

  • 1
    `1.` SCVVM isn't a virtualization host. SCVMM is a management server, just as vCenter Server is a management server. `2.` Do you have a DHCP server on either network? – joeqwerty Oct 01 '15 at 22:48
  • Right, it is Hyper-V. Sorry for that. At this point, no it does not have DHCP. Each adapter will be assigned a static IP, but that IP is dependent upon which virtual switch the adapter is using. – Mike Baldini Oct 01 '15 at 23:34

2 Answers2

1

The easiest way I can think of to do this is to somehow extract the MAC address of each network adapter from the VM configuration and check it against the NICs within the VM.

You wouldn't necessarily need to set the MAC addresses - vSphere will automatically assign a MAC for you if you don't specify a custom one (the assignment is intelligent enough to know not to reassign already-used addresses, so you don't need to worry about conflicts). You can then query the VM's configuration after it has been created, and match this against the NICs as they appear in the OS. For example:

First, you query the VM configuration via vSphere:

  • NIC A is attached to vSwitch0 and has MAC address 00:56:3f:00:21:12
  • NIC B is attached to vSwitch1 and has MAC address 00:56:3f:12:32:4a

Then, you query the NICs present within the guest OS after creation:

  • Ethernet Adapter has MAC address 00:56:3f:12:32:4a and is therefore NIC B and is attached to vSwitch1
  • Ethernet Adapter 1 has MAC address 00:56:3f:00:21:12 and is therefore NIC A and is attached to vSwitch0

You may be able to do this programatically, however I'm not proficient enough with the vSphere PowerShell CLI to know for sure.

Craig Watson
  • 9,575
  • 3
  • 32
  • 47
  • I thought about doing this, but I was thinking in order to accomplish it successfully, I would have to set a dedicated MAC address for each adapter. In our environments, we may have to spin up two or more of these VMs, which would cause issues. In 95% of cases, we only have one instance. But for that 5% of edge cases it would not work. – Mike Baldini Oct 01 '15 at 23:39
  • @MikeBaldini I think you misunderstood, my apologies, see my edited answer. – Craig Watson Oct 01 '15 at 23:41
  • Ah yes. I will have to try that out. That would be easily modified to work with Hyper-V as well. I know I can do that with Hyper-V in PowerShell. Looking up the CLI for vSphere won't be a problem. Thanks for the idea! I will try it out and mark it as the answer if it works! – Mike Baldini Oct 01 '15 at 23:48
0

The way I've dealt with this for my dual homed virtual machines is that I have a DHCP server on one network so I know the vNIC that gets a DHCP assigned ip address is connected to the network where the DHCP server is. The NIC that assigns itself an APIPA address is connected to the other network. It's crude but it works. You may not want to set up a DHCP server just for this purpose but in my case I use the DHCP server so I'm lucky in that I can use it to identify which network each vNIC is connected to.

joeqwerty
  • 109,901
  • 6
  • 81
  • 172
  • It would be a lot easier if we could use DHCP at this point. This VM is very specific and it does actually end up running a lightweight DHCP server for further configuration of the other VMs and components that are added later in the automation process. But at this point in the process, it gets setup with a specific IP for the 1Gbps and another specific one for the 10Gbps. The 10Gbps adapter gets nearly saturated during this process, and having it 'accidentally' use the wrong adapter increases deploy time by an order of magnitude. – Mike Baldini Oct 02 '15 at 00:35