Azure: Serial Console and Using Powershell to Disable and Enable Network Adapters
From Rabbi Blog
Alt: How to reset network interface for Azure Windows VM
This stemmed from a classroom issue where a student accidentally disabled the network adapter (via RDP) on his Azure VM. I posted internally to the class, I'm not spending too much time formatting the items here, but the elements s/b all here to get things reconnected.
Disclaimers
- Disclaimer 1: I really should be finishing up the homework but troubleshooting this was interesting (and troubleshooting helps you learn)
- Disclaimer 2: You can do this all via the Azure Operations->Run Command interface, however command runs were super slow (five minutes for Output responses to complete). You should try to see if the serial cable console is active first and go that route (mine was, I'm assuming everyone's will be as we're all new to this environment).
Notes
- Commands are ">" below and expect a return after entering. Example: >Powershell
- Things in red are important references
- Turn on VM
- Off Topic: Save money to auto shutdown your VMs via Azure Portal->Virtual Machines->VM->Operations->Auto Shutdown
- What NIC(s) is installed?
- Azure Portal->Virtual Machines->VM->Support+Troubleshooting->Serial Console
- (You can try this through Operations->Run command, but it's SLOW)
- At serial console, type the following
>cmd >ch -si 1
- Note:CMD starts a channel for commands, ch -si # joins the channel. To find available channels, type "ch", then join the # you want
- Authenticate to your VM as an Admin
- You should have a command prompt. Enter powershell
>Powershell >Get-NetAdapter | format-table Name InterfaceDescription ifIndex Status ---- -------------------- ------- ----- Ethernet Microsoft Hyper-V Network Adapter 4 Up
Disclaimer 3: everything after this point =>>> RUN AT YOUR OWN RISK
- Verify you can remotely connect to your VM via RDP (prove it works)
Disable the adapter via Powershell
- (assuming Ethernet is the name of the adapter (from the output prior when you checked))
- From powershell
> Disable-NetAdapter -Name Ethernet -Confirm:$false As this executes have the RDP window in view and wait... RDP should lose connection. Verify the NetAdapter status (optional) > Get-NetAdapter | format-table Name InterfaceDescription ifIndex Status ---- -------------------- ------- ----- Ethernet Microsoft Hyper-V Network Adapter 4 Disabled
Enable the adapter via Powershell
> Enable-NetAdapter -Name Ethernet -Confirm:$false Try to restart the RDP connection (it took about two minutes). > Get-NetAdapter | format-table Name InterfaceDescription ifIndex Status ---- -------------------- ------- ----- Ethernet Microsoft Hyper-V Network Adapter 4 Up
- Alternatively if you have access to another VM on that same internal network, have a command prompt open on that VM and ping the other machine continuously to see when it comes up.
Ex: >ping 10.0.0.5 -t
- If the status is Up, attempt to connect via RDP (make sure the public IP hasn't changed, shouldn't but double check if issues).
Troubleshooting Thoughts
I knew that if I could get a CMD> prompt, I could get into Powershell and from there I'd have to look up specific commands to do things, but I'd have control over the machine to do what would be needed. I started figuring this out by Googling "remotely access command prompt azure" and in my search, the 4th item returned got me pointed in the right direction.
https://docs.microsoft.com/en-us/azure/virtual-machines/troubleshooting/serial-console-windows
There was a bunch of info on that page, but the most important thing was "getting started with the serial console" and I gave it a try.
Further down on the same page was "Use serial console" and then I was in