Windows

為具有兩個網路適配器的特定網路適配器設置靜態路由

  • June 24, 2019

我有一個帶有 2 個虛擬網路適配器的虛擬 Windows Server 2008 r2,一個是域的一部分,另一個不是。當我 ping 到屬於域的特定 PC 時,它通過第二個網路適配器(不在域中的那個)連接到它,我嘗試使用靜態路由更改它:

ROUTE ADD -P <target PC's IP> MASK <Subnet mask from ipconfig> <Default Gateway of the adapter in the domain> if <tried it with all possible interfaces>

不幸的是,這不起作用,所以我很樂意幫助我了解如何製作這個靜態路由,以便我的伺服器通過域中的網路適配器連接到域中的 PC?

路由列印和 ipconfig 的輸出:

C:\Users\user>route print

========================================

Interface List

18...00 15 5d 80 0f 47 ......Microsoft Virtual Machine Bus Network Adapter #2

11...00 15 5d 80 0f 1a ......Microsoft Virtual Machine Bus Network Adapter

 1...........................Software Loopback Interface 1

12...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter

21...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2

IPv4 Route Table

=========================================================================== 

Active Routes: Network Destination        Netmask          Gateway    Interface  Metric

         0.0.0.0          0.0.0.0  192.168.128.254   192.168.128.13      5

         0.0.0.0          0.0.0.0    192.168.137.1   192.168.137.15      5

       127.0.0.0        255.0.0.0         On-link         127.0.0.1    306

       127.0.0.1  255.255.255.255         On-link         127.0.0.1    306

 127.255.255.255  255.255.255.255         On-link         127.0.0.1    306

   192.168.128.0    255.255.255.0         On-link    192.168.128.13    261

  192.168.128.13  255.255.255.255         On-link    192.168.128.13    261

 192.168.128.255  255.255.255.255         On-link    192.168.128.13    261

   192.168.137.0    255.255.255.0         On-link    192.168.137.15    261

  192.168.137.15  255.255.255.255         On-link    192.168.137.15    261

 192.168.137.255  255.255.255.255         On-link    192.168.137.15    261

       224.0.0.0        240.0.0.0         On-link         127.0.0.1    306

       224.0.0.0        240.0.0.0         On-link    192.168.128.13    261

       224.0.0.0        240.0.0.0         On-link    192.168.137.15    261

 255.255.255.255  255.255.255.255         On-link         127.0.0.1    306

 255.255.255.255  255.255.255.255         On-link    192.168.128.13    261

 255.255.255.255  255.255.255.255         On-link    192.168.137.15    261

=========================================================================== 
Persistent Routes:   

Network Address       Netmask  Gateway Address Metric

192.168.128.8       255.255.255.0  192.168.128.254    1

===========================================================================

IPv6 Route Table

=========================================================================== 

Active Routes:

If Metric Network Destination      Gateway

18    261 ::/0                     fe80::f427:d7d8:4ec2:fd5

 1    306 ::1/128                  On-link

11    261 fe80::/64                On-link

18    261 fe80::/64                On-link

11    261 fe80::8ce7:a7a5:d7c0:faf1/128 On-link

18    261 fe80::a8c7:ee26:b1bb:fd77/128 On-link

 1    306 ff00::/8                 On-link

11    261 ff00::/8                 On-link

18    261 ff00::/8                 On-link

===========================================================================
Persistent Routes:   None

C:\Users\user>ipconfig

Windows IP Configuration

Ethernet adapter Local Area Connection 2:

  Connection-specific DNS Suffix  . :

  Link-local IPv6 Address . . . . . : fe80::a8c7:ee26:b1bb:fd77%18

  IPv4 Address. . . . . . . . . . . : 192.168.137.15

  Subnet Mask . . . . . . . . . . . : 255.255.255.0

  Default Gateway . . . . . . . . . : fe80::f427:d7d8:4ec2:fd5%18

                                      192.168.137.1

Ethernet adapter Local Area Connection:

  Connection-specific DNS Suffix  . : domainName.com

  Link-local IPv6 Address . . . . . : fe80::8ce7:a7a5:d7c0:faf1%11

  IPv4 Address. . . . . . . . . . . : 192.168.128.13    

  Subnet Mask . . . . . . . . . . . : 255.255.255.0

  Default Gateway . . . . . . . . . : 192.168.128.254

Tunnel adapter isatap.domainName.com:

  Media State . . . . . . . . . . . : Media disconnected

  Connection-specific DNS Suffix  . : domainName.com

Tunnel adapter isatap.{5364A7C9-95AE-4753-98A3-8D60A49D43D5}:

  Media State . . . . . . . . . . . : Media disconnected   

  Connection-specific DNS Suffix  . :

部分問題是您有 2 個預設網關,這違反了預設網關的含義。僅將預設網關放在一個介面上。然後使用靜態路由,引導您想要通過另一個介面的流量。

例如,LAN1 192.168.123.13 遮罩 255.255.255.0 和 GW 192.168.128.254。這將使所有流量都流向 192.168.123.x,而任何其他網路的流量都將通過網關定向。

但是然後添加 LAN2 192.168.137.15 Mask 255.255.255.0 沒有任何預設網關。這將自動創建一個路由條目,192.168.137.x 將通過此介面而不是預設網關。現在,如果您希望其他流量通過該介面,您可以創建一個靜態路由,例如:

路線添加 -P 192.168.33.0 遮罩 255.255.255.0 192.168.137.1

這將通過 LAN2 將流量發送到 192.168.33.x,因為 192.168.137.1 與 LAN2 介面位於同一網路中。

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