Skip to main content

IPv6 Source Address Selection on Linux

May 11, 2009 by davidc

Sometimes it is desirable to have the outgoing IPv6 address on an interface selected deterministically. All else being equal, Linux will default to using the latest address added to the interface as the source address. This is generally not what you would expect or want. This article describes how to influence the source address selection under Linux.

Selection algorithm

Linux implements RFC 3484, "Default Address Selection for Internet Protocol version 6 (IPv6). Briefly, the algorithm involves building a candidate list of potential source addresses, then following these rules in order:

  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.

"If the eight rules fail to choose a single address, some unspecified tie-breaker should be used." Linux chooses to use the latest address added.

Influencing the algorithm

It is necessary therefore to break any tie by influencing one of these rules. The solution is to mark unwanted source addresses as "deprecated", causing them to fail rule 3.

The method to implement this under Linux is to set preferred_lft to 0, thus causing the address to be marked as deprecated. Note that deprecation doesn't make the address invalid, so you can still receive packets destined for that address, but it just won't be used as source adddres.

Changing an existing address

For an address already added to the interface, use ip addr change. See the example below.

root@netman1:~# ip -6 addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
    inet6 2a01:550:8000::11/128 scope global
       valid_lft forever preferred_lft forever
    inet6 2a01:550:8000:10a::1/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::221:5aff:fe45:9956/64 scope link
       valid_lft forever preferred_lft forever
root@netman1:~# lynx -dump 'http://www.ipv6.org/' | grep "You are using"
                  You are using IPv6 from 2a01:550:8000::11
root@netman1:~# ip -6 addr change 2a01:550:8000::11/128 dev eth0 preferred_lft 0
root@netman1:~# ip -6 addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
    inet6 2a01:550:8000::11/128 scope global deprecated
       valid_lft forever preferred_lft forever
    inet6 2a01:550:8000:10a::1/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::221:5aff:fe45:9956/64 scope link
       valid_lft forever preferred_lft forever
root@netman1:~# lynx -dump 'http://www.ipv6.org/' | grep "You are using"
                You are using IPv6 from 2a01:550:8000:10a::1
root@netman1:~#

Adding a new address

Simply set preferred_lft when adding your address, e.g.:

ip addr add 2a01:550:8000::11 dev eth0 preferred_lft 0

Example use in Debian interfaces file:

iface eth0 inet6 static
        address 2a01:550:8000:10a::1
        netmask 64
        gateway 2a01:550:8000:10a::ff
        up ip addr add 2a01:550:8000::11 dev eth0 preferred_lft 0

Example in Gentoo configuration file:

 config_eth0=(
       "10.1.1.1/24" "2001:0db8::1/64"
       "10.1.1.2/24" "2001:0db8::2/64 preferred 0"
 )

Credit

This page is based on a mailing list post by Chris Caputo to ipv6-ops:

Comments

The solution is to mark

May 24, 2016 by robinjack, 8 hours 38 min ago
Comment: 2018

The solution is to mark unwanted source addresses as "deprecated", causing them to fail rule 3.cameo silhouette

private tours

May 24, 2016 by zander, 10 hours 8 min ago
Comment: 2016

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this articl private tours

The Best strategy for binary option trading 

May 24, 2016 by zander, 15 hours 37 min ago
Comment: 1991

Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work The Best strategy for binary option trading

Change the world !!!

May 23, 2016 by jackparker, 1 day 10 hours ago
Comment: 1981

Thank you for another essential article. Where else could anyone get that kind of information in such a complete way of writing? I have a presentation incoming week, and I am on the lookout for such.
tips dan cara berhenti merokok dalam waktu 7 hari ( 1 minggu )
I am very happy to find this site. I wanted to thank you for this immense read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post.

Oh now its clear its video

May 22, 2016 by robinjack, 2 days 8 hours ago
Comment: 1967

Oh now its clear its video game.First time i was confuse what is it.Thanks for inform us video game . ajmer to jaipur cab

instant payday network video

May 22, 2016 by zander, 2 days 15 hours ago
Comment: 1953

I enjoyed reading your post and found it to be informative and to the topic. Thank you for not rambling on and on just to fill the page. Thanks. instant payday network video

instant payday network video

May 22, 2016 by zander, 2 days 16 hours ago
Comment: 1952

I enjoyed reading your post and found it to be informative and to the topic. Thank you for not rambling on and on just to fill the page. Thanks. instant payday network video

truc tiep bong da

May 21, 2016 by zander, 3 days 14 hours ago
Comment: 1903

This is cool post and i enjoy to read this post. your blog is fantastic and you have good staff in your blog. nice sharing keep it up truc tiep bong da

Keep strong

May 20, 2016 by jackparker, 4 days 6 hours ago
Comment: 1899

For how many months Ive been searching for this is the coolest site i ever knew. So keep this site strong and still thanks or your comments and post.
suplemen obat dan vitamin terbaik untuk patah tulang
I am extremely grateful to you for delivering this article. I was in dire need of some information on this topic and I could not find any information on this topic. But, then I got to your article and now I have the information that I needed. Thank you very much, once again, for writing this.

There is so much in this

May 20, 2016 by alikhan_095, 4 days 12 hours ago
Comment: 1895

There is so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way. Car Service CT to NYC

software reuse

May 19, 2016 by zander, 5 days 8 hours ago
Comment: 1884

I enjoyed reading your post and found it to be informative and to the topic. Thank you for not rambling on and on just to fill the page. Thanks software reuse

jobs in dhaka

May 19, 2016 by zander, 5 days 15 hours ago
Comment: 1878

t’s appropriate time to make some plans for the future and it is time to be happy. jobs in dhaka

Introduce tu nombre y tu

May 18, 2016 by jackman10, 6 days 2 hours ago
Comment: 1873

Introduce tu nombre y tu contraseña en los espacios habilitados para ello. A continuación haz clic en 'Iniciar sesión'. Listo, ya puedes trabajar con tu email. Ashy Bines

Free Recharge Offers

May 18, 2016 by zander, 6 days 12 hours ago
Comment: 1855

Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. Free Recharge Offers

t downloading images from the

May 17, 2016 by jackman10, 1 week 2 hours ago
Comment: 1849

t downloading images from the web and image cropping are not supported, and you have to set the output size numerically (number of pages wide/high) rather than using a fancy drag handle. The results are exactly the same.dog storage locker man

tainiesonline

May 17, 2016 by zander, 1 week 12 hours ago
Comment: 1832

Cool you write, the information is very good and interesting, I'll give you a link to my site. tainiesonline

Watches

May 16, 2016 by zander, 1 week 1 day ago
Comment: 1802

It is delighted to read this post and i get many useful point through this post. Please keep posting such kind of post. Watches

Fifa Autobuyer

May 15, 2016 by zander, 1 week 2 days ago
Comment: 1780

Cool you write, the information is very good and interesting, I'll give you a link to my site. Fifa Autobuyer

David

May 15, 2016 by thomasq, 1 week 2 days ago
Comment: 1778

فريق عمل “شبكة 365 Day News الإخبارية ” هو فريقٌ لا يتبع لأي أحزابٍ سياسية أو متعصب لأي طائفة دينية، ننقل الحدث والكلمة والصورة للمواطن العربي دون أن نُلوثه بكذبات السياسة والتحزب . الخطوط السعودية

The Best strategy for binary option trading 

May 15, 2016 by zander, 1 week 2 days ago
Comment: 1775

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. The Best strategy for binary option trading 

REIMAIN

May 15, 2016 by ha91070, 1 week 2 days ago
Comment: 1771

If you set out to make me think today; mission accomplished! I really like your writing style and how you express your ideas. Thank you. Language of Desire

jocuri noi gratuite

May 14, 2016 by zander, 1 week 3 days ago
Comment: 1763

There is so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way. Thank you for your clear information. jocuri noi gratuite

tchat coquin

May 13, 2016 by zander, 1 week 4 days ago
Comment: 1752

Cool you write, the information is very good and interesting, I'll give you a link to my site.tchat coquin

chat sexe

May 12, 2016 by zander, 1 week 5 days ago
Comment: 1744

Superb posts with lots of information!!! This is really the most miraculous blog site dude chat sexe

tchatche

May 12, 2016 by zander, 1 week 5 days ago
Comment: 1734

Cool you write, the information is very good and interesting, I'll give you a link to my site.tchatche

Toti ne dorim o dantura

May 11, 2016 by jackman10, 1 week 6 days ago
Comment: 1720

Toti ne dorim o dantura frumoasa si sanatoasa. Ceea ce putini stiu insa este ca pentru acest lucru nu trebuie sa depunem mult efort. Sunt suficiente stock trading

jhonwattson

May 11, 2016 by alikhann, 1 week 6 days ago
Comment: 1711

I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy.  video conference

jhonwattson

May 11, 2016 by alikhann, 1 week 6 days ago
Comment: 1707

Your site has grown a one-stop find as much as possible tutorial authoring. Thanks for your time in the very good get the job done. As i tested the online sites one preferred and even On the net which will best-dissertation.pores and skin look though. Ones own get the job done is kind of exemplary. kancer koze

looks at how their social

May 16, 2016 by BlackMen, 1 week 1 day ago
Comment: 1809

looks at how their social nature may actually result in the lion being under greater threat than many people think. Cialis

This really is truly

May 11, 2016 by robinjack, 1 week 6 days ago
Comment: 1704

This really is truly fantastic report. express appreciation you for dispersing it with us! I have a great fat removal product. If you want it so please visit our site. delhi airport to jaipur

chat roulette skyblog

May 11, 2016 by zander, 1 week 6 days ago
Comment: 1695

This is a decent post. This post gives genuinely quality data. I'm unquestionably going to investigate it chat roulette skyblog

Work never stop !!!

May 11, 2016 by jackparker, 1 week 6 days ago
Comment: 1691

sharing this Superb article.I

May 10, 2016 by jackman10, 2 weeks 2 hours ago
Comment: 1687

sharing this Superb article.I utilize this Article to demonstrate my task in college.it is helpful For me Great Worsilicone breast implant

Tchatche Webcam

May 10, 2016 by zander, 2 weeks 7 hours ago
Comment: 1676

It’s appropriate time to make some plans for the future and it is time to be happy. Tchatche Webcam

Sap Certification

May 10, 2016 by zander, 2 weeks 15 hours ago
Comment: 1669

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.Sap Certification

travel the world

May 9, 2016 by zander, 2 weeks 1 day ago
Comment: 1651

You said in post is too great and can be exceptionally valuable. I will remember it, a debt of gratitude is in order for sharing the data continue upgrading, looking forward for more posts.Thanks travel the world

Marketing Fieristico

May 8, 2016 by zander, 2 weeks 2 days ago
Comment: 1638

This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like thisMarketing Fieristico

webpage to icon

May 8, 2016 by zander, 2 weeks 2 days ago
Comment: 1635

I invite you to the page where you can read with interesting information on similar topics webpage to icon

This is generally not what

May 12, 2016 by BlackMen, 1 week 5 days ago
Comment: 1739

This is generally not what you would expect or want. free business calls

Thanks.

May 7, 2016 by khachlamat, 2 weeks 3 days ago
Comment: 1623

jhonwattson

May 7, 2016 by alikhann, 2 weeks 3 days ago
Comment: 1616

I appreciate your comments.  Instead of complaints, I feel you sounded realistic.  An enjoyable profession, that like any other, has it's stressful times best web design firms

Make A Coupon Leader

May 7, 2016 by jackparker, 2 weeks 3 days ago
Comment: 1615

I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog.
kidney care capsule
Your method in authoring ones own blogging is certainly important. Used to do not even comprehend you can nothing on at most of the most beneficial varieties as a result readily. This was an amazing guideline.

NJ Limo Rental

May 7, 2016 by zander, 2 weeks 3 days ago
Comment: 1595

I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog. NJ Limo Rental

Ottawa Prom Limos

May 6, 2016 by zander, 2 weeks 4 days ago
Comment: 1582

I would really prefer so as to add one other webpage into the endorsed styles everyone provided a while back. Ottawa Prom Limos

dark circles under eyes treatment

May 4, 2016 by zander, 2 weeks 6 days ago
Comment: 1561

I truly cherished perusing your web journal. It was extremely all around created and straightforward.dark circles under eyes treatment

The best trading winning strategy for binary option

May 4, 2016 by zander, 2 weeks 6 days ago
Comment: 1551

It is fine, nonetheless evaluate the information and facts around this correct.

jhonwattson

May 3, 2016 by alikhann, 3 weeks 6 hours ago
Comment: 1537

Your method in authoring ones own blogging is certainly important. Used to do not even comprehend you can nothing on at most of the most beneficial varieties as a result readily. This was an amazing guideline. Challenge Coin Manufacturer

Gateway Business Solutions

May 3, 2016 by zander, 3 weeks 18 hours ago
Comment: 1526

I will probably be coming back to your weblog for more soon what to text your ex girlfriend to get her back Gateway Business Solutions

David

May 2, 2016 by thomasq, 3 weeks 1 day ago
Comment: 1514

Delight maintain this approach awesome succeed and additionally Document wait for a great deal more on your stunning blog posts. read more

Blackmart alpha

May 2, 2016 by zander, 3 weeks 1 day ago
Comment: 1502

useful information on topics that plenty are interested on for this wonderful post.Admiring the time and effort you put into your.Blackmart alpha