First in a powershell create a new network switch
New-VMSwitch -SwitchName "SwitchName" -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 MyNATnetwork -InternalIPInterfaceAddressPrefix 192.168.0.0/24
In your ubuntu server open your network netplan
cd /etc/netplan
sudo nano <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
What makes me confused is the IP address of 192.168.0.1 as stated here: https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/setup-nat-network (this is similar to your example).
It says, that the example IP "192.168.0.1" acts like a gateway to the host (eg: my computer that hosting a virtual machine). They came out with a confusing example of an IP address, as that IP is too common for a physical router gateway.
Instead of creating an internal switch, I end up creating an external switch that works perfectly fine.