First in a powershell create a new network switch
New-VMSwitch -SwitchName "Hyper-V [VM NAT]" -SwitchType Internal
Get-NetAdapter // (note down ifIndex of the newly created switch as INDEX)
New-NetIPAddress -IPAddress 192.168.0.1 -PrefixLength 24 -InterfaceIndex <INDEX>
New-NetNat -Name HyperV-NATnetwork -InternalIPInterfaceAddressPrefix 192.168.0.0/24
In your ubuntu server open your network netplan
cd /etc/netplan
sudo vi <your-net-plan>
Type the following into your netplan
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.0.2/24
gateway4: 192.168.0.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
dhcp4: no
Then
sudo netplan apply
To have an external access to vm, add dstNAT on the host machine
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=3022 connectaddress=192.168.0.2 connectport=22