Hyper-V Network Configuration

I will give an example of creating virtual switches, configuring network and NAT in Hyper-V.

Open PowerShell from the menu or by running the command in the command line (as administrator):

powershell

Let’s see a list of existing network adapters:

Get-NetAdapter

Let’s see the existing NAT networks:

Get-NetNat

Let’s see the existing IP addresses:

Get-NetIPAddress

I will give examples of creating new switches with the network type “Internal”, “Private”, “External”:

New-VMSwitch -SwitchName "IXNFO_COM_Switch" -SwitchType Internal
New-VMSwitch -name PrivateSwitch -SwitchType Private
New-VMSwitch -name ExternalSwitch -NetAdapterName Ethernet -AllowManagementOS $true

Examples of adding a gateway to a new switch:

New-NetIPAddress -IPAddress 192.168.5.1 -PrefixLength 24 -InterfaceIndex 38
New-NetIPAddress -IPAddress 192.168.5.1 -PrefixLength 24 -InterfaceAlias "vEthernet (IXNFO_COM_Switch)"

NAT setup:

New-NetNat -Name "vNAT" -InternalIPInterfaceAddressPrefix 192.168.5.0/24

Example for removing NAT network and gateway:

Get-NetNat | Remove-NetNat
Get-NetIPAddress
Remove-NetIPAddress -IPAddress 192.168.5.1 -InterfaceIndex 44
Remove-NetIPAddress -IPAddress 192.168.5.1 -InterfaceAlias "vEthernet (IXNFO_COM_Switch)"

Example of removing a virtual switch:

Remove-VMSwitch -SwitchName "IXNFO_COM_Switch"

You can also manage virtual switches through Hyper-V Manager > Virtual Switch Manager.

See also my articles:

Leave a comment

Leave a Reply