0

On my ubuntu server I configured multiple ipv6 addresses as following with netplan:

network:
version: 2
renderer: networkd
ethernets:
    eth0:
        addresses:
        - xx.xx.xx.xx/22
        - xxxx:xxxx:xx:xx::/64
        - xxxx:xxxx:xx:xx::1/64
        - xxxx:xxxx:xx:xx::2/64
        gateway4: xx.xx.xx.1
        gateway6: fe80::1
        match:
            macaddress: ab:cd:ef:ab:cd:ef
        nameservers:
            addresses:
            - 127.0.0.1
            - ::1
            - xx.xx.xx.xx
            - xx:xx:xx::xxxx

For outgoing ipv6 connection the server always uses the address xxxx:xxxx:xx:xx::2/64 instead of xxxx:xxxx:xx:xx::/64.

How can I permanently set xxxx:xxxx:xx:xx::/64 as default outgoing ip address?

Migster
  • 1
  • 1
  • 4
  • There is actually an RFC covering the address selection (not that Linux necessarily follows the RFCs). It is _[RFC 6724, Default Address Selection for Internet Protocol Version 6 (IPv6)](https://tools.ietf.org/html/rfc6724)_. – Ron Maupin Sep 14 '19 at 14:43
  • I'm confused about what you are asking. For example, if a remote device want to create a TCP connection with this server, then the server must use the IP address to which the remote host sent the connection request. For TCP, you cannot have a connection that uses one IP address for inbound traffic, and a different IP address for outbound traffic. The TCP connection depends on those being the same address, else a connection will never be formed. – Ron Maupin Sep 14 '19 at 14:51
  • 2
    You should avoid using the first address in an IPv6 /64 for a host (where the host part is all zeroes). This is the subnet-router anycast address, and should be assigned to the subnet's routers, or not assigned at all. – Michael Hampton Sep 14 '19 at 18:20

1 Answers1

0

Set lifetime: 0 on the non preferred addresses. From man netplan(5):

lifetime (scalar) – since 0.100

Default: forever. This can be forever or 0 and corresponds to the PreferredLifetime option in systemd-networkd’s Address section. Currently supported on the networkd backend only.

Updating your example to include this:

network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            addresses:
            - xx.xx.xx.xx/22
                lifetime: 0
            - xxxx:xxxx:xx:xx::/64
            - xxxx:xxxx:xx:xx::1/64
                lifetime: 0
            - xxxx:xxxx:xx:xx::2/64
                lifetime: 0
            gateway4: xx.xx.xx.1
            gateway6: fe80::1
            match:
                macaddress: ab:cd:ef:ab:cd:ef
            nameservers:
                addresses:
                - 127.0.0.1
                - ::1
                - xx.xx.xx.xx
                - xx:xx:xx::xxxx
Kim
  • 101