[CentOS] IPv6 addresses order (CentOS6)

Wed May 31 08:09:29 UTC 2017
James Hogarth <james.hogarth at gmail.com>

On 30 May 2017 at 08:26, Walter H. <walter.h at mathemainzel.info> wrote:
> Hello,
> in /etc/sysconfig/network-scripts/ifcfg-eth0 I have this
> <ifcfg-eth0>
> ...
> IPV6INIT=yes
> IPV6ADDR=prefix::5
> IPV6ADDR_SECONDARIES="prefix::2 prefix::3 prefix::4"
> IPV6_DEFAULTGW=prefix::1
> </ifcfg-eth0>
> when I enter ifconfig the IPv6 addresses are in a different order
> <ifconfig>
> eth0 Link encap:Ethernet HWaddr ...
> inet addr:... Bcast:... Mask:...
> inet6 addr: fe80::.../64 Scope:Link
> inet6 addr: prefix::4/64 Scope:Global
> inet6 addr: prefix::3/64 Scope:Global
> inet6 addr: prefix::5/64 Scope:Global
> inet6 addr: prefix::2/64 Scope:Global
> </ifconfig>
> is there a way to influence the order?
> or how can I tell e.g. ssh to use a specific IPv6 address?
> (as it seems ssh uses the first one listed in ifconfig and not the one
> defined with IPV6ADDR)

Okay so the other comments appear to be directing you towards
unhelpful territory.

It would be of help if you provided more detail about what you are after.

Is this EL6 or EL7?

Either way stop using ifconfig and start with ip - especially in ipv6 territory.

There is no "order" as you seem to think, outside of the slight
differentiation between primary and secondary.

The primary address on an interface is the one that will be used as
the source address for an application, with the secondary addresses
being there to accept traffic.

When you mention ssh to you mean ssh the client application or ssh the
daemon server? If the latter then you can set ListenAddress to the IP
to listen to.

If the client then you need to use '-b' to define the address to
connect from, if wanting something other than what `ip route get` (or whatever destination address it is) lists as the src

In principle you could use `ip rule` to set up rules directing to a
secondary routing table with a different src, but that's more complex.

If you want this address persistent for one or more hosts without
always having to add '-b ::' to define the source address then you can
use BindAddress in your /etc/ssh/ssh_config at a system level or
~/.ssh/config at a user level to always use that set source address.

man ssh and man ssh_config will help you here ... assuming this is
just about ssh