Today I had the need to be able to connect to my Ubuntu VM on Hyper-V without having to specify the randomly generated IP address and also be able to continue to use it for development while Cisco AnyConnect was redirecting all traffic for my computer.
I happened across a pretty great command called “hvc.exe” that can be used in Powershell which allows you to interact with a Virtual Machine using native Windows networking socks – thus eliminating the need for IP addresses.
- SSH to a Hyper-V Virtual Machine without IP Address
The resulting command I came up with allows me to connect and use these native networking socks and bind the port to localhost at port 2222 – which is not hijacked by Cisco AnyConnect – so that was a win there!
- hvc.exe ssh -L 2222:localhost:22 cody@UbuntuVM
The only hiccup I had was that I needed to install the official virtualization packages for Hyper-V via Ubuntu using their package manager.
- Enabling full Hyper-V support for Ubuntu
The resulting command sequence that worked out for me was:
- sudo apt-get update
- sudo apt-get install linux-image-virtual linux-tools-virtual linux-cloud-tools-virtual
- sudo reboot
All in all – I was pleasantly surprised that Hyper-V now has this capability as it reduces the manual steps I have to work through if my computer ends up rebooting or otherwise.