Networking

具有私有和外部 IP 的 WinNAT

  • July 2, 2019

我已經使用 Microsoft guide設置了 WinNAT 。在我嘗試將192.168.33.20專用網路的第二個本地 IP 地址添加到同一個 NIC 之前,一切正常。

當我從帶有 IP 的 VM192.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

我沒有看到您為 Microsoft 指南提供的連結中列出了您的方案。正確的設置需要您添加額外的 NIC 並為其分配您想要使用的私有 IP 地址,而不是使用一個具有多個 IP 地址的 NIC。

引用自:https://serverfault.com/questions/973591