A great question that was brought up on Twitter yesterday by Andreas Peetz who asked the following:
Is there a way to restart the mgmt network in ESXi via a cmd line? You can do this from the DCUI, but I want a script!
There are a variety of reasons why you would want to restart the Management Network on your ESXi host and usually it is related to troubleshooting or configurations such as renewing the DHCP lease on a particular VMkernel interface. For Andreas, it was renewing the DHCP lease and this is actually a use case I have heard from others before. Currently, the only way to restart the Management Network for your ESXi host is using the DCUI (Direct Console User Interface) either through the console using iLO/iDRAC/etc. or remotely over SSH.
Andreas' question is not a new one and I have heard this ask in the past. I have even inquired about it when I was a customer but was told it was not possible and had to use the DCUI. I was not really satisfied with the answer I provided to Andreas, so I decided to do a bit of digging myself and ping some engineers. Apparently this functionality is actually exposed through a legacy command-line utility called esxcfg-vmknic in the ESXi Shell as well as locally/remotely via the ESXCLI network namespace which is used to manage the VMkernel interface (Thanks to Andres for mentioning ESXCLI method).
There are two flags that this command supports which is to enable and disable a VMkernel interface. This is actually what the DCUI is doing when you ask it to restart the Management Network and is very similar to restarting a service on a UNIX/Linux system, it first shutdowns the service and then starts it back up. Given this information, if you wish to restart the Management Network of your ESXi host you can specify the name of the Management Network portgroup and execute the enable operation immediately after performing the disable operation.
To do this from the command-line, you would add a ; (semi-colon) between the two commands so they are executed one after another to ensure your VMkernel interface is enabled after you have disabled it. Here is an example of the command:
esxcli network ip interface set -e false -i vmk0; esxcli network ip interface set -e true -i vmk0
Andreas Peetz says
Great, William! Exactly what I was looking, thanks for digging this out.
I only wonder why do you not recommend using the corresponding esxcli commands?:
esxcli network ip interface set -e false -i vmk0; esxcli network ip interface set -e true -i vmk0
Andreas
William Lam says
Andreas,
It's actually not performing the same operation. The way you can tell is by watching /var/log/syslog.log between these two operations and comparing it to when you perform it via DCUI
Andreas Peetz says
Yes, I noticed the differences in the log file, but maybe it's only a difference in logging. At least it will also restart the DHCP clients (see /var/log/dhclient.log), so it's good for me.
William Lam says
I've checked with engineering and looks like both commands produces the same outcome but are different applications, hence they're logged differently as you mentioned. I've updated my article to reference the ESXCLI command which is definitely the recommended way and you can perform this operation locally or remotely
rnelson0 says
What about "services.sh restart"? Recommended to restart he management agent in numerous KB articles, but not sure it mentions the networking components.
lamw says
services.sh restarts a bunch of other things as the name implies. I prefer to issue a specific command for a particular operation
Kaisar says
my DNS DHCP cannot true after this command. And host ip not ping.
help me please.
before this operation i created second vmkernel network interface and deleted.
Noor says
Can we restart the management agent of ESXi host using vMA
Zuss McLany says
Hi, can we restart the management network using PowerCLI?
abhishek says
How to restart dhcp service in esxi because my vm's are not getting the dhcp ip address.
What I should do ?