Linux下選擇IPv6主地址是按照一定規則來的 #RFC3484 (davidc)
- Prefer same address. (i.e. destination is local machine)
- Prefer appropriate scope. (i.e. smallest scope shared with the destination)
- Avoid deprecated addresses.
- Prefer home addresses.
- Prefer outgoing interface. (i.e. prefer an address on the interface we're sending out of)
- Prefer matching label.
- Prefer public addresses.
- Use longest matching prefix.
如果你有一個/64的段,并且為網卡分配了多個同段地址的時候,Linux會自動選擇最后添加的地址作為主地址。
要設定個性化主地址,可以在添加非主地址的時候加上[lifetime]屬性,將preferred_lft設為0。Linux將自動地把這些地址排除在主地址選擇范圍之外。
例:
1 ip addr -6 add xx:xx:xx:xx::8888/xx dev eth0 #?這個地址將包括在主地址選擇中
2 ip addr -6 add xx:xx:xx:xx::A/xx dev eth0 preferred_lft 0 #?這個地址不會當做主地址
Works Cited:
1. ?davidc, "IPv6 Source Address Selection on Linux" May 11, 2009, Retrieved from http://www.davidc.net/networking/ipv6-source-address-selection-linux