1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# 仮想スイッチを内部用で作成 PS C:\Users\Administrator> New-VMSwitch -SwitchName Nat-switch -SwitchType Internal Name SwitchType NetAdapterInterfaceDescription ---- ---------- ------------------------------ Nat-switch Internal # ネットワークアダプターのifIndexを確認 PS C:\Users\Administrator> Get-NetAdapter Name InterfaceDescription ifIndex Status MacAddress LinkSpeed ---- -------------------- ------- ------ ---------- --------- イーサネット Intel(R) Ethernet Connection (2) I21... 6 Up 6C-0B-84-0C-A7-CD 1 Gbps vEthernet (Intel(R) Et... Hyper-V Virtual Ethernet Adapter 8 Up 6C-0B-84-0C-A7-CD 10 Gbps vEthernet (nat-switch) Hyper-V Virtual Ethernet Adapter #2 20 Up 00-15-5D-0B-A0-03 10 Gbps ネットワーク ブリッジ Microsoft Network Adapter Multiplexo... 12 Up 6C-0B-84-0C-A7-CD 11 Gbps vEthernet (Nat-switch) 2 Hyper-V Virtual Ethernet Adapter #3 26 Up 00-15-5D-0B-A0-06 10 Gbps # ifindexを指定して、IPアドレスを付与する。NatGatewayのアドレス PS C:\Users\Administrator> New-NetIPAddress -IPAddress 172.16.1.1 -PrefixLength 24 -InterfaceIndex 20 IPAddress : 172.16.1.1 InterfaceIndex : 20 InterfaceAlias : vEthernet (nat-switch) 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 : 172.16.1.1 InterfaceIndex : 20 InterfaceAlias : vEthernet (nat-switch) AddressFamily : IPv4 Type : Unicast PrefixLength : 24 PrefixOrigin : Manual SuffixOrigin : Manual AddressState : Invalid ValidLifetime : Infinite ([TimeSpan]::MaxValue) PreferredLifetime : Infinite ([TimeSpan]::MaxValue) SkipAsSource : False PolicyStore : PersistentStore # Nat設定 PS C:\Users\Administrator> New-NetNat -Name nat-switch -InternalIPInterfaceAddressPrefix 172.16.1.0/24 Name : nat-switch ExternalIPInterfaceAddressPrefix : InternalIPInterfaceAddressPrefix : 172.16.1.0/24 IcmpQueryTimeout : 30 TcpEstablishedConnectionTimeout : 1800 TcpTransientConnectionTimeout : 120 TcpFilteringBehavior : AddressDependentFiltering UdpFilteringBehavior : AddressDependentFiltering UdpIdleSessionTimeout : 120 UdpInboundRefresh : False Store : Local Active : True # Nat設定を確認 PS C:\Users\Administrator> Get-NetNat Name : nat-switch ExternalIPInterfaceAddressPrefix : InternalIPInterfaceAddressPrefix : 172.16.1.0/24 IcmpQueryTimeout : 30 TcpEstablishedConnectionTimeout : 1800 TcpTransientConnectionTimeout : 120 TcpFilteringBehavior : AddressDependentFiltering UdpFilteringBehavior : AddressDependentFiltering UdpIdleSessionTimeout : 120 UdpInboundRefresh : False Store : Local Active : True # Nat利用状態を動的に確認 PS C:\Users\Administrator> Get-NetNatSession NatName : nat-switch InternalRoutingDomainId : {b1062982-2b18-4b4f-b3d5-a78ddb9cdd49} CreationTime : 2020/10/22 17:13:26 Protocol : 1 InternalSourceAddress : 172.16.1.2 InternalSourcePort : 1334 InternalDestinationAddress : 192.168.11.1 InternalDestinationPort : 1334 ExternalSourceAddress : 192.168.11.160 ExternalSourcePort : 1000 ExternalDestinationAddress : 192.168.11.1 ExternalDestinationPort : 1000 |