我已经使用 Microsoft 设置了 WinNAT指导一切工作正常,直到我尝试将192.168.33.20
专用网络的第二个本地 IP 地址添加到同一个 NIC。
当我从具有 IP 的 VM 向外部网络发出请求时192.168.0.2
,NAT 只是使用第二个添加的 IP 192.168.33.20
,而不是我的正确的外部 IP 11.22.33.20
。
如何让 NAT 转换ExternalSourceAddress
为正确的外部 IP 地址并忽略本地私有 IP?
PS C:\Users\Administrator> Get-NetNatSession
NatName : NATNetwork
InternalRoutingDomainId : {b1062982-2b18-4b4f-b3d5-a78ddb9cdd49}
CreationTime : 7/1/2019 10:18:50 AM
Protocol : 6
InternalSourceAddress : 192.168.0.2 # VM IP
InternalSourcePort : 33114
InternalDestinationAddress : 64.233.161.113
InternalDestinationPort : 24531
ExternalSourceAddress : 192.168.33.20 # NAT translates to incorrect local private IP
ExternalSourcePort : 50825
ExternalDestinationAddress : 64.233.161.113
ExternalDestinationPort : 24531
PS C:\Users\Administrator> Get-NetNat
Name : NATNetwork
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
PS C:\Users\Administrator> route print
===========================================================================
Interface List
11...00 d8 61 33 6d 52 ......Intel(R) I211 Gigabit Network Connection
31...00 15 5d b3 28 07 ......Hyper-V Virtual Ethernet Adapter
8...00 d8 61 33 6d 53 ......Intel(R) Ethernet Connection (7) I219-V
1...........................Software Loopback Interface 1
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 11.22.33.1 11.22.33.20 281
11.22.33.0 255.255.255.0 On-link 11.22.33.20 281
11.22.33.20 255.255.255.255 On-link 11.22.33.20 281
11.22.33.255 255.255.255.255 On-link 11.22.33.20 281
192.168.0.0 255.255.255.0 On-link 192.168.0.1 5256
192.168.0.1 255.255.255.255 On-link 192.168.0.1 5256
192.168.0.255 255.255.255.255 On-link 192.168.0.1 5256
192.168.33.0 255.255.255.0 On-link 11.22.33.20 281
192.168.33.20 255.255.255.255 On-link 11.22.33.20 281
192.168.33.255 255.255.255.255 On-link 11.22.33.20 281
224.0.0.0 240.0.0.0 On-link 1 331
224.0.0.0 240.0.0.0 On-link 11.22.33.20 281
224.0.0.0 240.0.0.0 On-link 192.168.0.1 5256
255.255.255.255 255.255.255.255 On-link 1 331
255.255.255.255 255.255.255.255 On-link 11.22.33.20 281
255.255.255.255 255.255.255.255 On-link 192.168.0.1 5256
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 11.22.33.1 Default
===========================================================================
PS C:\Users\Administrator> Get-NetNatExternalAddress
ExternalAddressID : 19
NatName : NATNetwork
IPAddress : 11.22.33.20
PortStart : 50299
PortEnd : 50398
Active : True
ExternalAddressID : 20
NatName : NATNetwork
IPAddress : 11.22.33.20
PortStart : 64012
PortEnd : 64111
Active : True
ExternalAddressID : 27
NatName : NATNetwork
IPAddress : 192.168.33.20
PortStart : 50796
PortEnd : 50895
Active : True
ExternalAddressID : 28
NatName : NATNetwork
IPAddress : 192.168.33.20
PortStart : 59684
PortEnd : 59783
Active : True
PS C:\Users\Administrator> ipconfig
Windows IP Configuration
Ethernet adapter Ethernet:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Ethernet adapter vEthernet (NATSwitch):
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::5d32:dd47:60a3:9184%31
IPv4 Address. . . . . . . . . . . : 192.168.0.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter Ethernet 2:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::9592:ef20:9c15:b759%8
IPv4 Address. . . . . . . . . . . : 11.22.33.20 # external IP
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.33.20 # local private IP
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 11.22.33.1
答案1
我没有看到您提供的 Microsoft Guide 链接中列出了您的方案。正确的设置需要您添加额外的 NIC 并为其分配您想要使用的私有 IP 地址,而不是使用一个具有多个 IP 地址的 NIC。