
我有一個 Windows Server 2012R2 虛擬機,有 3 個 IP 位址:4.70、4.17 和 4.18
4.70 是屬性表中輸入的第一個 IP 位址,4.17 和 4.18 在進階對話方塊中輸入。
如你在路由列印中看到的,windows綁定了4.17作為預設IP,我想強制windows使用4.70作為預設IP。 4.17/4.18 用於 IIS,並且存在一些重要的防火牆問題需要解決。同時,我需要盒子上的其餘流量源自 4.70。
ipconfig/全部:
Ethernet adapter Ethernet0:
Description . . . . . . . . . . . : Intel(R) 82574L Gigabit Network Connection
Physical Address. . . . . . . . . : 00-50-56-9B-33-55
DHCP Enabled. . . . . . . . . . . : No
IPv4 Address. . . . . . . . . . . : 192.168.4.17(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.254.0
IPv4 Address. . . . . . . . . . . : 192.168.4.18(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.254.0
IPv4 Address. . . . . . . . . . . : 192.168.4.70(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.254.0
Default Gateway . . . . . . . . . : 192.168.4.1
路線列印:
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.4.1 192.168.4.17 266
答案1
和這個:http://www.confusedamused.com/notebook/source-ip-address-preference-with-multiple-ips-on-a-nic/
很快,在 netsh 位址設定中,對所有非主 IP 使用 SkipAsSource=true 標誌
答案2
您可以輕鬆地使用 PowerShell 來執行此操作:
Set-NetIPAddress -IPAddress 192.168.1.221 -SkipAsSource:$true
對介面上您不想設為預設的所有 IP 位址執行此操作。留下一個 IP,其中 SkipAsSource = False。該 IP 最終將成為預設 IP。
答案3
我在這裡找到了一篇文章,其中包含有關如何定義主要 IP 輸出的非常詳細的範例:
https://www.sysadmit.com/2018/12/windows-configurar-ip-primaria-salida.html
從前面的連結中提取的範例:
假設我們要在同一網路介面中設定下列 IP 位址:172.17.0.2、172.17.0.3 和 172.17.0.10,但輸出的主 IP 位址是:172.17.0.10 而不是 172.17.0.2。
我們刪除目前的 TCP/IP 配置並執行以下命令:
netsh int ipv4 add address "Ethernet0" 172.17.0.2/16 SkipAsSource = true
netsh int ipv4 add address "Ethernet0" 172.17.0.3/16 SkipAsSource = true
netsh int ipv4 add address "Ethernet0" 172.17.0.10/16 SkipAsSource = false
如果我們看一下前兩行,我們表明 172.17.0.2 和 172.17.0.3 都被忽略作為輸出的主 IP 位址,因此 IP 位址 172.17.0.10 將被視為輸出。