Set primary IPv6 address

Linux下选择IPv6主地址是按照一定规则来的 #RFC3484 (davidc)

  1. Prefer same address. (i.e. destination is local machine)
  2. Prefer appropriate scope. (i.e. smallest scope shared with the destination)
  3. Avoid deprecated addresses.
  4. Prefer home addresses.
  5. Prefer outgoing interface. (i.e. prefer an address on the interface we're sending out of)
  6. Prefer matching label.
  7. Prefer public addresses.
  8. 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

转载于:https://www.cnblogs.com/msg7086/archive/2012/05/12/debian_set_primary_ipv6_address.html

 

I've got a /64 of IPv6 addresses available to one of my servers (Ubuntu 12.04). I'm binding them like this:

auto eth0
    iface eth0 inet static
    address xxx.xxx.xxx.82
    netmask 255.255.255.248
    network xxx.xxx.xxx.80
    broadcast xxx.xxx.xxx.255
    gateway xxx.xxx.xxx.81

    iface eth0 inet6 static
    address xxxx::2
    netmask 64
    gateway xxxx::1

    pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/autoconf
    pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra
    pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra_defrtr
    pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra_pinfo
    pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra_rtr_pref

    up /sbin/ifconfig eth0 inet6 add xxxx::3/64
    # ... snip ...
    up /sbin/ifconfig eth0 inet6 add xxxx::25/64

This works, but applications are all using xxxx::25 for their outgoing requests unless specifically told otherwise. If I add xxxx::26 in my /etc/network/interfaces, they all start using that. It seems like they just use whatever the highest number is.

How do I specify a certain address to be used as the default? In my case, I happen to want to use the lowest address (xxxx::2), but I'd really like to know how to specify a particular one, should the need arise in the future.

12.04 networking ipv6

shareimprove this question

asked Mar 22 '14 at 4:16

 

Dan

25111 gold badge55 silver badges1616 bronze badges

add a comment

1 Answer

active oldest votes

3

You can solve this by modifying the default route. Every route in Linux has the option to specify the default source address. If you specify the xxxx::3 address in your route then that one will be used by default:

/sbin/ip -6 route del default
/sbin/ip -6 route add default via xxxx::1 src xxxx::3

If you show the routing table you will see the result:

/sbin/ip -6 route
default via xxxx::1 dev eth0  src xxxx::222  metric 1024

One thing to watch out for is that IPv6 addresses are in a tentative state until duplicate address detection has been performed. Linux will refuse to use a tentative address as the default source address. This means that you might need to add a short sleep before adding this route so that the address has time to come out of the tentative state and become usable.

shareimprove this answer

answered Mar 22 '14 at 11:11

 

Sander Steffann

2,1311111 silver badges1313 bronze badges

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值