码迷,mamicode.com
首页 > 其他好文 > 详细

HyperV创建NAT网络

时间:2018-03-27 14:41:08      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:xor   手动   inbound   pes   persist   http   soft   一个   nta   

创建NAT内部网络,使用PowerShell完成。
https://docs.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/user-guide/setup-nat-network

1.创建Internal网卡,名称为SwitchNAT
PS> New-VMSwitch -SwitchName "SwitchNAT" -SwitchType Internal

Name      SwitchType NetAdapterInterfaceDescription
----      ---------- ------------------------------
SwitchNAT Internal

2.获得SwitchNAT的ifIndex,此例子是45
PS> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
vEthernet (SwitchNAT)     Hyper-V Virtual Ethernet Adapter             45 Up           00-15-5D-CF-BD-05        10 Gbps
Bluetooth Network Conn... Bluetooth Device (Personal Area Netw...       4 Disconnected xx-xx-xx-xx-xx-xx         3 Mbps
Ethernet                  Intel(R) Ethernet Connection I219-LM         14 Disconnected xx-xx-xx-xx-xx-xx          0 bps
Wi-Fi                     Intel(R) Dual Band Wireless-AC 8260          12 Up           xx-xx-xx-xx-xx-xx     115.6 Mbps

3.创建NAT网关
PS> New-NetIPAddress -IPAddress 192.168.0.1 -PrefixLength 24 -InterfaceIndex 45


IPAddress         : 192.168.0.1
InterfaceIndex    : 45
InterfaceAlias    : vEthernet (SwitchNAT)
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Tentative
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

IPAddress         : 192.168.0.1
InterfaceIndex    : 45
InterfaceAlias    : vEthernet (SwitchNAT)
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Invalid
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : PersistentStore


4.创建一个NAT网络配置,名称为MyNAT4HyperV
PS> New-NetNat -Name MyNAT4HyperV -InternalIPInterfaceAddressPrefix 192.168.0.0/24


Name                             : MyNAT4HyperV
ExternalIPInterfaceAddressPrefix :
InternalIPInterfaceAddressPrefix : 192.168.0.0/24
IcmpQueryTimeout                 : 30
TcpEstablishedConnectionTimeout  : 1800
TcpTransientConnectionTimeout    : 120
TcpFilteringBehavior             : AddressDependentFiltering
UdpFilteringBehavior             : AddressDependentFiltering
UdpIdleSessionTimeout            : 120
UdpInboundRefresh                : False
Store                            : Local
Active                           : True


5.在HyperV的虚拟机网卡配置中选择SwitchNAT
6.启动虚拟机,手动配置
IP为192.168.0.x,
子网掩码255.255.255.0,
网关192.168.0.1,
DNS为8.8.8.8,8.8.4.4

-----
删除命令
先停止使用网卡(关闭虚拟机或服务)
PS> Get-NetNat "MyNAT4HyperV"| Remove-NetNat
PS> Remove-NetIPAddress -InterfaceAlias "vEthernet (SwitchNAT)" -IPAddress 192.168.0.1
PS> Remove-VMSwitch -SwitchName "SwitchNAT"

 

HyperV创建NAT网络

标签:xor   手动   inbound   pes   persist   http   soft   一个   nta   

原文地址:https://www.cnblogs.com/Bob-wei/p/8656656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!