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

David

May 2, 2016 by thomasq, 8 hours 6 min 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, 16 hours 29 min 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

Work again !!!

May 2, 2016 by jackparker, 20 hours 27 min ago
Comment: 1500

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work
cordyceps plus capsule
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

warehouse for rent in sharjah

May 1, 2016 by zander, 1 day 10 hours ago
Comment: 1491

Good to become visiting your weblog again, it has been months for me. Nicely this article that i've been waited for so long.warehouse for rent in sharjah

ca do euro 2016

April 30, 2016 by zander, 2 days 16 hours ago
Comment: 1428

It's really nice and meanful. it's really cool blog. Linking is very useful thing.ca do euro 2016

Incredible post!

April 30, 2016 by jackparker, 2 days 20 hours ago
Comment: 1425

The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
kidney care capsule
Incredible post! I am really getting prepared to over this data, is extremely useful my companion. Likewise extraordinary blog here with the greater part of the important data you have.
Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

Carpet Cleaning Champaign IL

April 29, 2016 by zander, 3 days 17 hours ago
Comment: 1417

I do have a vast knowledge about the birds found in Pakistan. How can I write in your site? Tell me. Carpet Cleaning Champaign IL

So every time you write Momma

April 28, 2016 by robinjack, 4 days 14 hours ago
Comment: 1399

So every time you write Momma Jude it warms my heart because I know it is written with such affection. Salvia for sale

ali

April 26, 2016 by alikhann, 6 days 4 hours ago
Comment: 1353

Thanks for this great post, i find it very interesting and very well thought out and put together. I look forward to reading your work in the future.  antlerxreviews.com

ALI

April 26, 2016 by alikhann, 6 days 5 hours ago
Comment: 1348

Ski boots for ladies function similarly as it will be possible ski boot footwear do. But its composition plus designing methods are usually different. Girls ski boot footwear are marginally leaner around cuff levels, contouring and get thick pillow for improved foothold. Stock alerts

I encourage you to read this

April 25, 2016 by alikhan_095, 1 week 2 hours ago
Comment: 1330

I encourage you to read this text it is fun described ... locksmiths near me

David John

April 26, 2016 by David John, 6 days 4 hours ago
Comment: 1351

You've displayed your information very well. The font used matches with the theme and tone of the article. for more

Packing and Moving Services

April 25, 2016 by kudeepaklal, 1 week 9 hours ago
Comment: 1322

Best Relocation Services

April 25, 2016 by kudeepaklal, 1 week 9 hours ago
Comment: 1321

Keep work hard

April 25, 2016 by jackparker, 1 week 14 hours ago
Comment: 1313

Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.
penyakit gagal ginjal pada anak - gejala, penyebab dan pengobatan

alikhann

April 24, 2016 by alikhann, 1 week 1 day ago
Comment: 1306

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

ali

April 24, 2016 by alikhann, 1 week 1 day ago
Comment: 1304

There are several dissertation internet sites on-line because you get evidently reported as part of your web site.  free instagram followers hack

I am impressed by the

April 24, 2016 by alikhan_095, 1 week 1 day ago
Comment: 1303

I am impressed by the information that you have on this blog. It shows how well you understand this subject. gilbert blinds

cigarette electronique

April 23, 2016 by zander, 1 week 2 days ago
Comment: 1293

I haven't any word to value this post.....Really i am awed from this post....the individual who make this post it was an incredible human..thanks for imparted this to us. http://www.kelklope.com

aftabak

April 22, 2016 by aftabak, 1 week 3 days ago
Comment: 1270

I want to for you to thanks a lot just for this wonderful go through!! My spouse and i surely savoring every single small the idea along with We've anyone added to view brand-new goods anyone article. Buy Backlinks Manually Work Unique Domains

I would recommend my profile

April 22, 2016 by alikhan_095, 1 week 3 days ago
Comment: 1269

I would recommend my profile is important to me, I invite you to discuss this topic. How to pass Asvab Exam

I really enjoy simply reading

April 22, 2016 by alikhan_095, 1 week 3 days ago
Comment: 1266

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful. Chandler Electrician

I discovered your site ideal

April 20, 2016 by aftabak, 1 week 5 days ago
Comment: 1224

I discovered your site ideal for me. It consists of wonderful and useful posts. I've read many of them and also got so much from them. In my experience, you do the truly amazing.Truly i'm impressed out of this publish. Buy Backlinks Manually Work Unique Domains

David John

April 21, 2016 by David John, 1 week 4 days ago
Comment: 1239

Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging. charcoal for odors

as well as a newly developed

April 20, 2016 by aftabak, 1 week 5 days ago
Comment: 1223

as well as a newly developed X-mode control system that is designed for drivers to easily navigate on tough roads, handle slippery surfaces or steep hills with just one switch. Fiverr 30 Niche Relevant Approved Blog-Commenting

Be smart

April 20, 2016 by jackparker, 1 week 5 days ago
Comment: 1200

eye care softgel
His is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.

aftabak

April 19, 2016 by aftabak, 1 week 6 days ago
Comment: 1198

I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post. Fiverr 30 Niche Relevant Approved Blog-Commenting

David John

April 24, 2016 by David John, 1 week 1 day ago
Comment: 1301

With valuable information to work with.Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging. http://n4g.com/user/home/savesterms
probiotic benefits weight loss

Wonderful posting, Thanks a

April 19, 2016 by sargaso, 1 week 6 days ago
Comment: 1189

Wonderful posting, Thanks a ton to get spreading The following awareness. Wonderfully authored posting, doubts all of blog owners available precisely the same a higher standard subject material just like you, online has got to be improved site. I highly recommend you stay the best!
http://www.voiceblog.jp/ferisuke
http://www.kiwibox.com/danielstrife/blog
http://tavani.hatenablog.com

David John

April 20, 2016 by David John, 1 week 5 days ago
Comment: 1208

I wanna thanks to a great extent for providing such informative and qualitative material therefore often. smelling shoes

Let's work hard !!!

April 19, 2016 by jackparker, 1 week 6 days ago
Comment: 1173

Keep up the good work, and post more articles like the one you have posted above. Very interesting and also informative.
Things are very open and intensely clear explanation of issues.
obat stroke
Someone Sometimes with visits your blog regularly and recommended it in my experience to read as well. The way of writing is excellent and also the content is top-notch. Thanks for that insight you provide the readers!
http://www.ahlinyaobatherbal.com/obat-stroke-herbal-terbaik/
Thanks for your great information, the contents are quiet interesting. I will be waiting for your next post....
eye care softgel

alikhann

April 18, 2016 by alikhann, 2 weeks 6 hours ago
Comment: 1167

I appreciate your comments.  Instead of complaints, I feel you sounded realistic.  An enjoyable profession, that like any other, has it's stressful times black car service in atlanta 

Everything will change

April 18, 2016 by jackparker, 2 weeks 20 hours ago
Comment: 1143

Had visited the sites you had posted and it was nice. Thanks for sharing it
eye care softgel
Keep up the good work, and post more articles like the one you have posted above. Very interesting and also informative.
Things are very open and intensely clear explanation of issues.
gastric health tablet

Call it weakness leaving your

April 18, 2016 by alex12, 2 weeks 9 hours ago
Comment: 1161

Call it weakness leaving your body or no pain no gain or whatever cliché keeps you in motion, but sign, sign, sign. Sign.www.seosubmit.com

alikhann

April 17, 2016 by alikhann, 2 weeks 1 day ago
Comment: 1134

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

Hy, I'am new >>>

April 15, 2016 by jackparker, 2 weeks 3 days ago
Comment: 1096

Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing...
cara menyembuhkan alergi gatal kulit secara alami dan cepat
I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

This is very well written and

April 16, 2016 by alex12, 2 weeks 2 days ago
Comment: 1109

This is very well written and your points are well-expressed. Please, don’t ever stop writing. forskolin diet

Note that deprecation doesn't

April 15, 2016 by alex12, 2 weeks 3 days ago
Comment: 1098

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.Airlines

aftabak

April 14, 2016 by aftabak, 2 weeks 3 days ago
Comment: 1095

Welcome to OPY World School, a school set up with the objective of holistic development of students. We are a school with a difference, offering a unique learning experience; a modern school with eternally relevant value systems. Milton barbarosh

alikhann

April 14, 2016 by alikhann, 2 weeks 4 days ago
Comment: 1093

There are several dissertation internet sites on-line because you get evidently reported as part of your web site.  http://finance.yahoo.com/news/cogniflex-reviewed-healthy-nutritions-secret-195900546.html

amir

April 14, 2016 by thomasqq, 2 weeks 4 days ago
Comment: 1092

This is usually a wonderful recommendations primarily so that you can all those a novice to blogosphere, limited plus genuine information… With thanks to get spreading brussels. Very important learn posting. รับทํารั้วสแตนเลส

alikhann

April 14, 2016 by alikhann, 2 weeks 4 days ago
Comment: 1089

That can job short-term, however , it’s no possible long-term choice meant for individuals who want to get the real key an individual exceptional girlfriend these can’t avoid wondering about. http://bevhillsmdreviews.co

Male Extra

April 14, 2016 by MaleExtra, 2 weeks 4 days ago
Comment: 1088

Male Extra™is one of the natural male enhancement pills that really work by aiding your erection size, controlling your ejaculations.Read complete user reviews here http://www.maleextrareviewguide.com/

alikhann

April 14, 2016 by alikhann, 2 weeks 4 days ago
Comment: 1085

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

amir

April 13, 2016 by thomasqq, 2 weeks 5 days ago
Comment: 1064

You might be allowed to submit brands, however, not back links, except if they may be accepted and also about matter. 咲水化粧水

alikhann

April 13, 2016 by alikhann, 2 weeks 5 days ago
Comment: 1053

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