VMware {code} Community
paul_xedos
Enthusiast
Enthusiast
Jump to solution

Command line method of specifying the MAC address for a guest

Can anyone tell me if it is possible to set the mac address for a guest manually from the cli? I was hoping vicfg-vmknic might have an option to statically assign an address but it appears not. According to the Server Configuration guide you can set this via the VI client but the cli method is eluding me. Reason for wanting to do this is for static dhcp address assignment

Thanks

Paul

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

One other possibility -- you can try VI Toolkit 1.5 which has a command called Set-NetworkAdapter which lets you set the MAC address.

View solution in original post

0 Kudos
5 Replies
mcowger
Immortal
Immortal
Jump to solution

You'll need to write a script against he API for this - you probably want to ReconfigureVM() or CreateVM() tasks with a ReconfigurationSpecification().






--Matt

VCP, vExpert, Unix Geek

--Matt VCDX #52 blog.cowger.us
paul_xedos
Enthusiast
Enthusiast
Jump to solution

Thanks Matt. As I'm not too sure where to start with an API script I'd like to offer anyone who is interested $50 if they are able to write this script that provides this functionality. As it would be run remotely I'm guessing the input parameters would be of the form --server $server --username $user --password $password --vmid $vmid --mac-address $mac-address

If you're able to do this then I'll post the output on this page as I'm sure it could be of use to others

Thanks

Paul

0 Kudos
admin
Immortal
Immortal
Jump to solution

You can set macaddress while creating a Virtual Machine, by adding a VirtualEthernetCard or edit an existing VirtualEthernetCard by specifying addressType as manual and macAddress of your interest. Refer below code snippet for reference.

VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec();

if(networkName != null) {

nicSpec.operation=VirtualDeviceConfigSpecOperation.add;

nicSpec.operationSpecified = true;

VirtualEthernetCard nic = new VirtualPCNet32();

VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();

nicBacking.deviceName=networkName;

nic.addressType="manual";

nic.macAddress="00:50:56:9b:1c:d0"; //VMware uses this OUI for manually generated addresses: 00:50:56.

nic.backing=nicBacking;

nic.key=4;

nicSpec.device=nic;

}

You can refer vmreconfig.pl utility shipped along VI PerlToolKit and modify it a bit based on above shared code snippet to get your task done.

paul_xedos
Enthusiast
Enthusiast
Jump to solution

Superb, thanks for that - I'll give it a go and if I get it working which hopefully shouldn't be too tricky now, I'll post back

Rgds

Paul

0 Kudos
admin
Immortal
Immortal
Jump to solution

One other possibility -- you can try VI Toolkit 1.5 which has a command called Set-NetworkAdapter which lets you set the MAC address.

0 Kudos