Remove and recreate Management Network VM Kernel interface [vmk0], using ESXi CLI
As you may know, ESXi Management interface (aka vmk0) is created during installation. By default that interface will inherit MAC address of one of the physical NIC cards. Now, this is not a problem at all in most cases, but sometimes it can create problems.
For example imagine a situation where you do an installation with a one 1G physical NIC, and then you want to do an upgrade. You take out 1G NIC and insert 10G one. After that you reuse 1G NIC in another server. This can lead to situation with duplicate MAC addresses on the network.
Update: <fc #cd5c5c>VMware KB 55626 – MAC Flapping observed in an NSX Environment</fc> covers a specific case when this can affect you. According to the KB there is no resolution for now, but the steps bellow can help you solve it.
Removing and re-creating management interface will create it with a VMware MAC address as any other VMkernel interface. So this can resolve duplicate issue.
And honestly, it doesn’t matter much what is the reason for you doing this, important is to know how-to.
If you are using Standard Switches, the procedure is pretty straight forward so i will not cover it. It becomes a bit complex in case your Management interface was migrated to Distributed Virtual Switch. And this is exactly the case I will cover here.
All these steps will need to be performed using direct console, as we will be deleting the interface. It is also a good idea to put the host into Maintenance Mode.
Collect configuration details
First of all you need to capture current IP configuration of your management interface. I mean IP, Netmask and Gateway. We will also need name of the dvswitch which has the vmk0 interface. All this info will be needed.
Find Port ID
Second, you will need to find a port number on dvswitch which is used by vmk0. To list Switch info you can use
esxcfg-vswitch -l
and then look for vmk0. The output of that command can be very long, so you can use grep and awk to filter out only the value you need.
esxcfg-vswitch -l |grep vmk0 |awk '{print $1}'
Remove vmk0
As third step, we need to remove current vmk0, thats easy, just run the command:
esxcli network ip interface remove --interface-name=vmk0
We can check if it was removed my running esxcfg-vmknic -l or we can check if the port was freed by running esxcfg-vswitch -l and looking for the port number we acquired in second step.
Re-Create vmk0
Now once we have old vmk0 removed, we can run following command to recreate it:
esxcli network ip interface add --interface-name=vmk0 --dvs-name=DVSWITCHNAME --dvport-id=PORT_ID_FROM_STEP_TWO
Of course you will need to replace DVSWITCHNAME with your Distributed Switch name and PORT_ID_FROM_STEP_TWO with the Port ID we acquired in step 2.
Again, we can check if port was created using
esxcfg-vmknic -l or esxcfg-vswitch -l
Configure IP settings
In step number 5 we need to assign IP configuration to the new vmk0 interface. Use the following command to do it. Replace IP and NETMASK with info captured in step 1.
esxcli network ip interface ipv4 set --interface-name=vmk0 --ipv4=IP --netmask=NETMASK --type=static
Set default Gateway
We also need to set the default GW back to its place, as it was removed once we removed vmk0.
esxcfg-route -a default IP_OF_GW
Mark vmk0 for Management traffic
It may happen that vmk0 will not be marked for Management traffic after recreation. You can use the following command to mark interface for management in CLI.
esxcli network ip interface tag add -i vmk0 -t Management