在window環境下(windows server2008/vista及以上版本)中,綁定了輔助IP後,主動外訪時有可能不再走主IP。
導緻後果:往往表現為主機綁了輔助IP後主動外訪不通,但外網IP被通路時是通的。
因為外網IP經常是綁在主内網IP上,如果當對外發送流量不再選擇走主内網IP,而是選擇沒有綁外網IP的輔助IP的時候,網絡當然不通。
這與我們的期望不符,我們往往認為網絡流量會預設從主IP出去。
示例案例:
primary IP:10.10.20.163 -> 綁定了外網IP:123.206.21.201
secondary IP:10.10.20.30 (後來綁上去的)
gateway:10.10.20.1
微軟官方鏡像的IP選擇政策發生了變化:windows server08/Vista之前的版本,會預設從第一個add到網卡的IP出去。
而windows server2008/Vista 及其之後的版本(包括windows server2008、windows server2012、windows server2016、windows 7等),會遵循以下方式:
Rule 1: Prefer same address (applies)
Rule 2: Prefer appropriate scope (applies)
Rule 3: Avoid deprecated addresses (applies)
Rule 4: Prefer home addresses - does not apply to IP v4
Rule 5: Prefer outgoing Interfaces (applies)
Rule 6: Prefer matching label - does not apply to IP v4
Rule 7: Prefer public addresses - does not apply to IP v4
Rule 8: Use longest matching prefix with the next hop IP address.
根據規則8,如果主IP與下一跳IP的 matching prefix(字首比對) 短于輔助IP與下一跳的 matching prefix ,那輔助IP的優先級會高于主IP,packet 就會由輔助IP發送。
本示例案例中,輔助IP(10.10.20.30)與下一條(即網關10.10.20.1)的 matching prefix 更長,是以流量不再走主IP。

使用标志位skipAsSource:用 netsh 指令添加IP時,把skipAsSource标為true。
server 2008:
netsh int ipv4 add address < Interface Name > < ip address > < subnet mask > skipassource=true
server 2012:
netsh int ipv4 add address < Interface Name > < ip address > skipassource=true
本示例案例中,對應的指令為:
<code>netsh int ipv4 add address "以太網" 10.10.20.30/24 skipassource=true</code>