My Azure VM won’t boot: switch Serial Console mode

Sometimes you try to do stuff remotely, and unfortunately, it generates some very bad effects that you did not expect at all. As a result of this, you have problems to reach the machine and get stuck.

Today this is what happened to me, changing the IP config in a way that it was impossible to RDP anymore.

How can we fix this?

Well, the first thing is to connect the machine “locally”. How is it possible to do this with VMs? : Serial Console mode

  • In my case, I was running Windows Datacenter, with HyperV, and misconfigured a new network. It broke the connection.

So to reach this local console, go in Azure Portal, select your VM, go down to Help and select Serial Console.

After a few seconds you get a prompt:

  • Type cmd (lower case)
  • Then ch -si 1

You will be asked to enter your login and password (domain can be set to “.” which means local) … and you are now connected locally on you windows machine in command line.

Now it is time for you to use command lines and PowerShell, to adapt the bogus configuration.

Here is an example of how you can switch from a physical IP to DHCP.

To check the config

$IPType = “IPv4”

$adapter = Get-NetAdapter | ? {$_.Status -eq “up”}

$interface = $adapter | Get-NetIPInterface -AddressFamily $IPType

#check DHCP status

$ $interface.Dhcp

 

And now how to activate DHCP

 

$interface | Remove-NetRoute -Confirm:$false

# Enable DHCP

$interface | Set-NetIPInterface -DHCP Enabled

# Configure the DNS Servers automatically

$interface | Set-DnsClientServerAddress -ResetServerAddresses

 

Et voila: my NIC went back to the good config (no hard config, DHCP).

This is a very basic example of how Serial Console can help a lot when we lose connection with the remote machine.

 

Version 1.0