I was building out my virtualized lab and instead of re-installing ESXi over and over again I figured I would just quickly clone them. Now of course this leads to a “minor” problem as the virtualized ESXi hosts will all boot with the same IP-Address. As I don’t have DHCP to my disposal I needed to change them manually, so how do you change the IP address of ESXi through the commandline?
It is actually pretty straight forward with esxcli these days. First thing I did was listing all VMkernel NICs:
esxcli network ip interface ipv4 get
This will give you the list of all VMkernel interfaces with their details (See screenshot below). Changing the IP address is just a matter of adding some parameters:
esxcli network ip interface
ipv4
set -i vmk1 -I 10.27.51.143 -N 255.255.255.0 -t static
In your situation you will need to replace “vmk1” with the appropriate VMkernel NIC of course and change the IP details.
Cleriston says
very useful article. moreover is very cool accumulate knowledge about command line.
Fabian Casanova says
Hi Duncan!
In your second exemple, you forgot “ipv4” after interface. Without this, it shows a message “Error: Invalid option -I”. In the screenshot its ok! By the way, great post!!!!
Cheers!
Duncan Epping says
thanks, fixed
KFM says
Hi Duncan!
I had a problem with cloning (virtual) ESXi servers in my lab that had existing NICs attached to it. Even though vCenter would give them new MAC addresses, the old MAC addresses were still stored in esx.conf. So even though I gave them new IP addresses the underlying MAC addresses were still the same. This caused all sorts of problems – I couldn’t ping the ESXi hosts from each other and when enabling HA vCenter thinks the cloned ESXi hosts are partitioned.
There are other people who have also run into this problem and they have scripts that will remove the old MAC addresses from esx.conf and that clears it up. Me, I just have a template “shell” ready for the lab user to install ESXi into – they can then add as many NICs as they require. More fiddly but at least I don’t have duplicate MAC addresses on the network.
How did you solve the duplicate MAC address in esx.conf problem?
Cheers,
KFM
Duncan Epping says
I remove the MAC addresses after booting them the first time without network.
Phil says
I might be stupid in this situation, but why couldn’t you use the DCUI? How did you connect to the VM with esxcli if you had to change the IP first? Or are you saying you got each one on the network one by one and then changed the IP afterwards?
Duncan Epping says
I don’t have access to iLO in this case, I had access to the various VMkernel’s NICs though. So I change one by one,
Hemanth says
Hi Duncan,
Want to restart the Management network from command line all, only able to find command for how to restart the Management agent.
We had network changed from switch, after that all our ESXI hosts were showing disconnected, we restarted Management network from DCUI & all ESXI hosts got connected.
But was not able to find command for restart Management network.
Thanks
Hemanth
Jon Lundfelt says
What about changing the gateway? I am running into an issue where that’s a separate cmdlet in Powershell, so my scriptblock won’t work, since I get disconnected as soon as I change the IP-
$scriptblock = {
Get-VMHostNetworkAdapter -VMHost $vmhost | ? {$_.ip -like “10.1.226.*”} | Set-VMHostNetworkAdapter -IP $NewIP -SubnetMask $subnetmask -ManagementTrafficEnabled $true -verbose -Confirm:$false
Get-VMHostNetworkAdapter -VMHost $vmhost | Set-VMHostNetwork -ConsoleGateway 10.228.42.1 -Confirm:$false
#Restart Management Service
Log “$vmhost, Restarting vnware-vpxa service”
Get-VMHostService -VMHost $vmhost | ? {$_.key -eq “vmware-vpxa”} | Restart-VMHostService -verbose -Confirm:$false
}
Kman says
Are you kidding me? How about the gateway?
If you follow the instructions above and gateway gonna be different…. then you are in deep trouble. You will lose connection completely
Duncan Epping says
Did you try this? http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2043784
Abhinav Srivastava says
Hi Duncan,
Is there a way through which we can assign the IP to an existing VM in the ESXi using the commandline?