Skip to content

Instantly share code, notes, and snippets.

@mzaglia
Last active March 7, 2024 09:02
Show Gist options
  • Save mzaglia/d51893ec08937d15c83660e028c1edee to your computer and use it in GitHub Desktop.
Save mzaglia/d51893ec08937d15c83660e028c1edee to your computer and use it in GitHub Desktop.
Static IP Hyper-V Ubuntu VM

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

Source

@juvuorin
Copy link

juvuorin commented Mar 7, 2024

Does dns work also with this setup? Assuming that host is utilizing DCHP to get DNS and IP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment