I`m trying to have a workstation with (at least) 2 IPv6 addresses. One address would be a static manually configured IPv6 address and the other would be an auto-generated one from SLAAC (there could be more of these).
I succeeded to achieve this through the /etc/network/interfaces file by setting the interface on auto but adding another IP address with this line:
up ip -6 addr add 2001:db8::10/64 dev enp0s3(Intentionally used the documentation address space, not the actually used ULA.)
Now I can access my inner infrastructure with the ULA address and the internet with the SLAAC one. This works fine.
However, I want to achieve this with the GUI settings, because I will now have to create another connection for the user at the workstation, so that he can switch the connection on will by a couple of clicks.
If I create the secondary connection, it works. When I create the above-described connection I cannot add a static address to it with the GUI.
How would I go about having 2 interchangeable connections of which one would have Auto IPv6 address acquisition together with a static IPv6 address?
51 Answer
I have managed to resolve the issue myself.
I was looking around for various ways to add extra addresses to a connection via Network Manager configuration files. I was unable to find any way to properly do this, but there was a deprecated configuration option for the ipv6 scope in the connection configuration file located in the /etc/NetworkManager/system-connections folder. The "addresses" configuration directive, which was allegedly used for setting a list of addresses to add to the interface. The value is supposed to be an array of IPv6 address structures, which each in turn is a structure of 3 properties. A byte array containing the address, a uint32 number containing the mask and another byte array containing the gateway address. This is described in "nm-settings" man page. Unfortunately I was unable to find any examples of the required format and was unable to get this to work, so I gave up on finding a solution via Network Manager configuration.
Next I looked at the option to run post-up scripts, while still using network manager. This is supposed to be done by scripts in the /etc/network/if-up.d/ directory, but as it is not fully integrated with Network Manager and might reveal inconsistencies (according to some sources), I was forced to keep looking. That is when I found this post! It explains, how one can run scripts with the Network Manager built in dispatcher. Then another problem was beginning to show. The custom dispatcher scripts that are supposed to be located in the /etc/NetworkManager/dispatcher.d/ directory can be run at various Phases of Network Managers doings and their execution order is controlled by the 2 digits in the beginning of the filename, but they are always run in the given phase. So if I had a script that is supposed to be run post-up (or at the up phase according to Network Manager), it would always execute at the "up" phase of Network Manager. So, whichever connection I would click on in the GUI, the Network Manager would end up running the script. This is not what I was looking for because I am required to only add an extra IPv6 address to one of the connections I have to set up and not the rest. Since the script would be run always, I had to find a way to determine which connection this script is being called for, where the "NetworkManager" man page came in handy. It says that the custom dispatcher scripts are being passed 2 arguments (interface/device and action/phase), but that the environment contains extra variables. One of which is the "CONNECTION_UUID" variable. This contains the uuid of the connection this script is being called for and the uuid of the connection can be found in the connection configuration file in the "/etc/NetworkManager/system-connections/" directory. So within my dispatcher script I only have to check whether the variable contains the uuid of my desired connection and if so, only then execute the required command.
Example connection configuration file for a connection not requiring the extra address "/etc/NetworkManager/system-connections/regular_connection" :
[802-3-ethernet]
duplex=full
mac-address=00:00:00:11:11:11
[connection]
id=regular_connection
uuid=12345678-90ab-cdef-0123-4567890abcde
type=802-3-ethernet
[ipv6]
method=auto
[ipv4]
method=autoThe special connection requiring the extra static IPv6 address on top of the SLAAC generated ones would have a configuration file similar to the regular one, but the uuid part is to be noted for usage in the dispatcher script. Exmaple configuration file for clarity purposes "/etc/NetworkManager/system-connections/extra_static_ipv6_connection" :
[802-3-ethernet]
duplex=full
mac-address=00:00:00:11:11:11
[connection]
id=extra_ipv6_con
uuid=88888888-4444-4444-4444-cccccccccccc
type=802-3-ethernet
[ipv6]
method=auto
[ipv4]
method=autoThe next step would be to create the dispatcher script. Example dispatcher script "/etc/NetworkManager/dispatcher.d/99_super_connection_post_up_script":
#!/bin/sh -e
# Script to add static local IPv6 address when connected to super network
# Runs a single command on appropriate circumstances
# $0 is command. $1 is interface. $2 is action. $UUID is the uuid of current connection.
if [ -z "$1" ]; then echo "$0: called with no interface" 1>&2 exit1;
fi
# Set reader friendly environment
export IFACE="$1"
# Check for action and on "up" action (post-up) add IPv6 address if connection uuid matches
case "$2" in up) if [ "$CONNECTION_UUID" = "88888888-4444-4444-4444-cccccccccccc" ]; then ip -6 addr add 2001:db8::10/64 dev $IFACE fi; ;; *) echo "$0: called with unknown action \'$2'" 1>&2 exit 1 ;;
esacNow one can just switch the active connection in the GUI top right corner network connection drop-down list (Ubuntu 14.04 specific location in GUI). Whenever the "extra_ipv6_con" connection will be selected, after getting the auto configuration of both IPv4 and IPv6, the post-up/up phase Network Manager dispatcher script will be run and an extra/static IPv6 address will be assigned to the interface. If any of the other connections would be clicked, the network configuration will change to the selected one and the dispatcher script will be run again, but have no effect because of the mismatch in the UUID.
TLDR:
One can have Network Manager execute a script located in "/etc/NetworkManager/dispatcher.d/" directory whenever a connection is enabled with a click in GUI. This can serve as a post-up script or any other type TBH and only have effect on a single connection that is selected by matching the connection UUID. This script can contain the command mentioned in the question and therefor add the IPv6 address.
1