niedziela, 12 sierpnia 2018

create NAT switch for hyper-v

Get adapters to find current list of adapters before any changes - just to notice changes.

PS C:\WINDOWS\system32> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet                  Intel(R) 82579LM Gigabit Network Con...      20 Disconnected F0-DE-F1-8A-12-5C          0 bps
Bluetooth Network Conn... Bluetooth Device (Personal Area Netw...      19 Disconnected 94-39-E5-8F-C1-79         3 Mbps
WiFi                      Intel(R) Centrino(R) Ultimate-N 6300...      13 Up           24-77-03-19-4A-08       144 Mbps
vEthernet (Default Swi... Hyper-V Virtual Ethernet Adapter              8 Up           1A-15-25-D5-36-C5        10 Gbps

Create new VMSwitch - name is custom - You should use something noticable - with NAT phrase, but it is of course optional, switch type is important - You can choose from Internal, External and Private - choose Internal.

PS C:\WINDOWS\system32> New-VMSwitch -SwitchName "NATSwitch" -SwitchType Internal

Name      SwitchType NetAdapterInterfaceDescription
----      ---------- ------------------------------
NATSwitch Internal


PS C:\WINDOWS\system32> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet                  Intel(R) 82579LM Gigabit Network Con...      20 Disconnected F0-DE-F1-8A-12-5C          0 bps
Bluetooth Network Conn... Bluetooth Device (Personal Area Netw...      19 Disconnected 94-39-E5-8F-C1-79         3 Mbps
vEthernet (NATSwitch)     Hyper-V Virtual Ethernet Adapter #2          50 Up           00-15-5D-04-20-06        10 Gbps
WiFi                      Intel(R) Centrino(R) Ultimate-N 6300...      13 Up           24-77-03-19-4A-08       144 Mbps
vEthernet (Default Swi... Hyper-V Virtual Ethernet Adapter              8 Up           1A-15-25-D5-36-C5        10 Gbps

New adapter connected to the new switch has interface index (ifIndex) 50 - we will assign other components to this interface. Let's create IP address - it will be default gateway for our NAT network.

PS C:\WINDOWS\system32> New-NetIPAddress -IPAddress 192.168.254.254 -PrefixLength 24 -InterfaceIndex 50


IPAddress         : 192.168.254.254
InterfaceIndex    : 50
InterfaceAlias    : vEthernet (NATSwitch)
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.254.254
InterfaceIndex    : 50
InterfaceAlias    : vEthernet (NATSwitch)
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Invalid
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : PersistentStore

So we have switch, we have ip address connected with interface in this switch and now - we must inform system - that we have network behind NAT. We can have only ONE network behind NAT, so let's inform system about it.

PS C:\WINDOWS\system32> New-NetNat -Name NATnetwork -InternalIPInterfaceAddressPrefix 192.168.254.0/24


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


Now we can reconnect our virtual machines to the new switch and reconfigure them:
- network addresses from 192.168.254.0/24 network;
- default gateway 192.168.254.254;
- DNS server - depends on configuration, for example 8.8.8.8.
Our NAT network:

PS C:\WINDOWS\system32> Get-NetNat


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

Our NAT Switch:

PS C:\WINDOWS\system32> Get-VMSwitch

Name           SwitchType NetAdapterInterfaceDescription
----           ---------- ------------------------------
Default Switch Internal   Teamed-Interface
NATSwitch      Internal

Brak komentarzy:

Prześlij komentarz