Hyper-V添加內部NAT網路
使用powershell (管理員權限)執行
1、創建虛擬交換機,等同于在Hyper-V管理器界面中新建虛擬網路交換機
<#
說明:
New-VMSwitch 是創建虛擬交換機的指令
-SwitchName 是指定創建交換機的名字
"NAT-VM" 是交換機的名字 (名字可以隨意起,但是需要能看懂和記住)
-SwitchType 指定虛擬交換機的型別(內部,專用)
Internal 交換機的型別,分別有(Internal,Private)
#>
<#
-SwitchType說明:
Specifies the type of the switch to be created. Allowed values are Internal and Private. To create an External virtual switch, specify either the NetAdapterInterfaceDescription or the NetAdapterName parameter, which implicitly set the type of the virtual switch to External.
#>
PS C:\Windows\system32>New-VMSwitch -SwitchName "NAT-VM" -SwitchType Internal
2、查看 NAT-VM 的 ifindex
<#
說明:
獲取網卡資訊, 然后關注ifindex 列的值(取-SwitchName的名字"NAT-VM"行的值 )
#>
PS C:\Windows\system32>Get-NetAdapter
3、創建ip,InterfaceIndex引數自行調整為上一步獲取到的ifindex,這一步等同于在 控制面版-網卡屬性 中設定ip
<#
說明:
New-NetIPAddress 設定IP地址命令
-IPAddress 指定IP
-PrefixLength 指定子網掩碼長度;比如:255.255.255.0=24
-InterfaceIndex 配置第二步獲取到的"NAT-VM"行Ifindex值
#>
PS C:\Windows\system32>New-NetIPAddress -IPAddress 192.168.1.1 -PrefixLength 24 -InterfaceIndex 27
4、創建NAT網路,允許訪問外部網路,24為子網掩碼位數,即:255.255.255.0
<#
New-NetNat 創建nat網路命令
-Name 指定剛才創建取"NAT-VM"(按自己創建的來)的名字
-InternalIPInterfaceAddressPrefix 配置允許訪問外部的網路
192.168.1.0/24 指定IP段,并配置子網長度 24=255.255.255.0
#>
PS C:\Windows\system32>New-NetNat -Name NAT-VM -InternalIPInterfaceAddressPrefix 192.168.1.1/24
5、在Hyper V管理器中設定該虛擬機的網路配接器為 NAT-VM(按自己創建的選擇)
6、Hyper-V除Default-Switch,其他都沒有dhcp服務,所以需要自己手動進虛擬機進行填寫相應網段的IP地址(在系統中設定好ip、網關、dns即可),進行使用!!!
dhcp服務推薦 dhcpsrv
官網地址:dhcpserver.de/cms/download/
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/543833.html
上一篇:STM32 SPI硬體NSS
