Set primary IPv6 address

Dan

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.

Sander Steffann

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.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to determine if IPv6 address is private?

分類Dev

Allow ipv6 address in Azure firewall

分類Dev

IPv6 address as the domain portion of an email address

分類Dev

IPV6 Unique-local address and site local address

分類Dev

disable IPv6 autoconf (MAC-based) IPv6 address without disabling privacy addresses?

分類Dev

Check if a string contains an IPV6 address in PHP

分類Dev

RewriteRule with an IPv6 IP address does not work

分類Dev

Does openssl understand link-local IPv6 address?

分類Dev

How to get the ipv6 address marked with a specific scope?

分類Dev

Linux - find router IPv6 global address

分類Dev

IPv6 socket creation failed: Address family not supported by protocol

分類Dev

EndPoint Communication Exception with correct DNS IPv6 address but incorrect IPv4 address

分類Dev

Failing to start Jupyter Notebook : 'does not appear to be an IPv4 or IPv6 address'

分類Dev

Ipv6 address stored differently while using Inet type Postgres 10.4

分類Dev

無効なIPv6アドレスに対して有効なInet6Address

分類Dev

set two fields as primary key

分類Dev

Set primary DNS server in 16.04

分類Dev

whois with IPV6 support

分類Dev

IPv6検証

分類Dev

IPV6 Swift Reachability

分類Dev

Ping Adress IPV6

分類Dev

VMware VIM IPv6

分類Dev

VMware VIM IPv6

分類Dev

Using IPv6 with Virtualbox

分類Dev

IPv4, IPv6 and IPTables

分類Dev

How to get the Android device's primary e-mail address

分類Dev

kubelet option to set apiserver address

分類Dev

How to set static IP address?

分類Dev

How to force a mongod to become primary in a replica set?