简体   繁体   中英

Hyper-V changing Static MAC address on one of the adapters

I have an Ubuntu 18.06 VM with 2.network adapters connected, one internal and one external. However, I would like set the adapters which is using the internal switch "NATSwitch" to have a static MAC address while the other can have a dynamic one.

PS C:\> Get-VMNetworkAdapter -VMName "Docker_1806"

Name            IsManagementOs VMName               SwitchName   MacAddress   Status IPAddresses
----            -------------- ------               ----------   ----------   ------ -----------
Network Adapter False          Docker_1806          Robot Switch 001122334455 {Ok}   {169.254.74.100, fe80::215:5dff:feb2:1188}
Network Adapter False          Docker_1806          NATSwitch    554433221100 {Ok}   {192.168.137.100, fe80::a00:3cff:fea3:4209}

I have tried using this command:

PS C:\> Set-VMNetworkAdapter -VMName "Docker_1806" -StaticMacAddress "01-02-03-04-05"

But that seemed to have changed both of my adapter's MAC address to static.

I've tried:

PS C:\> $vmadapter = Get-VMNetworkAdapter -VMName "Docker_1806"
PS C:\> $vmadapter[1]

Name            IsManagementOs VMName        SwitchName MacAddress   Status IPAddresses
----            -------------- ------        ---------- ----------   ------ -----------
Network Adapter False          Docker_1806   NATSwitch  554433221100 {Ok}   {192.168.137.100, fe80::a00:3cff:fea3:4209}


PS C:\> Set-VMNetworkAdapter -VMName "Docker_1806" -VMNetworkAdapter $vmadapter[1] -StaticMacAddress "01-02-03-04-05"

Set-VMNetworkAdapter : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ set-vmnetworkadapter -vmname "Docker_V2_Dev" -VMNetworkAdapter $vmada ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-VMNetworkAdapter], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.HyperV.PowerShell.Commands.SetVMNetworkAdapter

Is there a way to change only one of them through Powershell on the host? I can't seem to find a way to set static MAC for a specific adapter for that VM.

On another note, the.network configurations for this VM is set using.netplan configurations inside the VM so that it can have static IP addresses.

Thanks in advance!

You should choose which of parameters sets you would like to use - searchinf by VMName or VMNetworkAdapter object.

More information about different parameter sets you could find in the doc: https://docs.microsoft.com/en-us/powershell/module/hyper-v/set-vmnetworkadapter?view=win10-ps

$vmadapter = Get-VMNetworkAdapter -VMName "Docker_1806"   
Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[1] -StaticMacAddress "01-02-03-04-05"

This one worked for me.

Change MAC address (Properties->Configure...->Network Address) in Default switch properties. In my case i see incorrectly set MAC address with dashes (maybe set while default Hyper-V installation).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM