A Mutable Log

A blog by Devendra Tewari

Project maintained by tewarid Hosted on GitHub Pages — Theme by mattgraham

Port forwarding in Hyper-V

This post shows how to use port forwarding in Hyper-V (Windows Pro or Enterprise), to forward ssh requests to an Alpine Linux VM.

Enable Hyper-V using the Turn Windows features on or off Control Panel applet.

Configure a new virtual NAT switch using PowerShell (elevated privilege required)

New-VMSwitch -SwitchName "NATSwitch" -SwitchType Internal
New-NetIPAddress -IPAddress -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"
New-NetNAT -Name "NATNetwork" -InternalIPInterfaceAddressPrefix

Create a new 64-bit Linux VM and configure it to use the above network switch. Download and setup Alpine in the VM.

To be able to ssh into the VM from the host, you need to forward TCP port 22 to the same port number on the VM.

Using PowerShell

Add-NetNatStaticMapping -ExternalIPAddress "" -ExternalPort 22 -Protocol TCP -InternalIPAddress "" -InternalPort 22 -NatName NATNetwork

Finally, edit /etc/ssh/sshd_config in Alpine to enable login for root user

PermitRootLogin yes

Restart sshd service

service sshd restart

Now, you should be able to ssh into the VM from localhost or any host on the same network

ssh root@localhost