Skip to content

Instantly share code, notes, and snippets.

@AlexZ005
Created October 8, 2018 21:37
Show Gist options
  • Save AlexZ005/42ea1d3fd0cbe17d8c08dbc1108674bc to your computer and use it in GitHub Desktop.
Save AlexZ005/42ea1d3fd0cbe17d8c08dbc1108674bc to your computer and use it in GitHub Desktop.

Revisions

  1. AlexZ005 created this gist Oct 8, 2018.
    63 changes: 63 additions & 0 deletions Hyper-V NAT for Windows Server 2016
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    #1. Host machine

    # Create new switch
    New-VMSwitch -SwitchName NAT -SwitchType Internal
    # Check current VM network adapters
    Get-VMNetworkAdapter -VMName DC,FS
    # Connect current adapters to created NAT switch
    Connect-VMNetworkAdapter -VMName DC,FS -SwitchName NAT
    # Add network adapters for both VM's with selected virtual switch
    #Add-VMNetworkAdapter -VMName DC,FS -SwitchName NAT
    # Check adapter configuration
    Get-NetAdapter
    # Configure switch IP (gateway)
    New-NetIPAddress -InterfaceIndex 15 -IPAddress 192.168.1.1 -PrefixLength 24
    # Configure network address translation (NAT)
    New-NetNat -Name NAT -InternalIPInterfaceAddressPrefix 192.168.1.0/24
    # Start VM's
    Start-VM -name DC,FS

    #2. Connect to DC machine
    Enter-PSSession -VMName DC

    # Get adapters
    Get-NetAdapter
    # Check adapter configuration, APIPA address
    Get-NetIPAddress -InterfaceIndex 4
    # Configure network IP address and gateway
    New-NetIpAddress -InterfaceIndex 4 -IpAddress 192.168.1.2 -PrefixLength 24 -DefaultGateway 192.168.1.1
    # Check adapter configuration
    Get-NetIPAddress -InterfaceIndex 4

    # Check connection to Google DNS
    ping 8.8.8.8

    # Check connection to FS
    ping 192.168.1.3 -t

    # Adjust Firewall settings
    netsh advfirewall firewall add rule name="Allow inbound ICMPv4" protocol="icmpv4:8,any" remoteip=192.168.1.3 dir=in action=allow
    #New-NetFirewallRule -DisplayName "Allow inbound ICMPv4" -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -RemoteAddress 192.168.1.3 -Action Allow


    #3. Connect to FS machine
    Enter-PSSession -VMName FS

    # Get adapters
    Get-NetAdapter
    # Check adapter configuration, APIPA address
    Get-NetIPAddress -InterfaceIndex 4
    # Configure network IP address and gateway
    New-NetIpAddress -InterfaceIndex 4 -IpAddress 192.168.1.3 -PrefixLength 24 -DefaultGateway 192.168.1.1
    # Check adapter configuration
    Get-NetIPAddress -InterfaceIndex 4

    # Check connection to Google DNS
    ping 8.8.8.8

    # Check connection to DC
    ping 192.168.1.2 -t

    # Adjust Firewall settings
    #netsh advfirewall firewall add rule name="Allow inbound ICMPv4" protocol="icmpv4:8,any" remoteip=192.168.1.2 dir=in action=allow
    New-NetFirewallRule -DisplayName "Allow inbound ICMPv4" -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -RemoteAddress 192.168.1.2 -Action Allow