he.net IPv6 Tunnel with systemd-networkd
/etc/systemd/network/eth0.network tells systemd-networkd how to configure the eth0 interface:
[Match] Name=eth0 [Network] Address=203.0.113.10/24 Gateway=203.0.113.1 Address=2001:db8:a:a::1/64 Tunnel=he0
The Tunnel= line triggers the configuration of an he0@eth0 tunnel.
[Match] [NetDev] Name=he0 Kind=sit #MTUBytes=1280 [Tunnel] Local=203.0.113.10 Remote=198.51.100.1 TTL=255
The empty [Match] section tells systemd-networkd to create the tunnel itself. Otherwise I think it would delay configuration until something else created it.
[Match] Name=he0 [Network] Address=2001:db8:b:b::2/64 [Route] Gateway=2001:db8:b:b::1 Source=2001:db8:a:a::1
The Source= option causes IPv6 packets sent out from the system to use the address assigned to eth0 as their source address. Otherwise, the kernel would prefer to use he0's address.
Actaully, I'm using a version of systemd that is a little bit old, and doesn't support the Source= option. So instead I have no [Route] section and configure the default route at boot with /etc/systemd/system/ipv6-gateway.service:
[Unit] Description=IPv6 default gateway with custom source address After=systemd-networkd.service BindsTo=systemd-networkd.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/bash -c 'until [[ -n $(ip -6 address show dev he0 to 2001:db8:b:b::/64) ]]; do sleep 1; done' ExecStart=/bin/ip route add default via 2001:db8:b:b::1 dev he0 src 2001:db8:a:a::1 TimeoutStartSec=10 [Install] WantedBy=multi-user.target