Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
This works great! Thanks for the tip about tentative addresses, too; that would have probably taken me a while to figure out why it would work when run manually but not on system boot. –  Dan Mar 22 at 12:06
1  
I just wrote a script that waits for given addresses to leave the tentative state. Might be useful in init scripts: pastebin.com/sAgRxbPY –  Sander Steffann Mar 22 at 17:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.