L2TP with systemd-networkd
systemd-networkd 242 supports L2TP. Because Documentation is sparse i had to figure it out myself. These are my findings:
this is l2tp.netdev
containing the L2TP tunnel and session configuration (according to the documentation):
[NetDev]
Name=myl2tp
Kind=l2tp
[L2TP]
TunnelId=100
PeerTunnelId=101
#Local=10.0.0.1 # not required. systemd-networkd can autodetect the address from eth0 (see below)
Remote=10.1.0.1
EncapsulationType=udp
UDPSourcePort=6000
UDPDestinationPort=6001 # there is a typo (https://github.com/systemd/systemd/pull/14892) in the official documentation. it says "DestinationPort" there.
[L2TPSession]
Name=l2tpsess
SessionId=10
PeerSessionId=11
this is l2tp.network
containing the network configuration for the L2TP tunnel. i want it connected to a bridge. you can set it up differently of course:
[Match]
Name=l2tpsess
[Network]
DHCP=no
LinkLocalAddressing=no
Bridge=br0
this is eth0.network
containing the network configuration for the physical network interface:
[Match]
Name=eth0
[Network]
DHCP=no
Address=10.0.0.1
Netmkas=255.255.255.0
L2TP=myl2tp # i didn't find any documentation about this option. If it is missing, your Tunnel is never set up
if eth0 is set up via DHCP, systemd-networkd will wait for it to be configured before setting up L2TP.
# systemctl restart systemd-networkd
# networkctl
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 eth0 ether routable configured
3 br0 bridge routable configured
4 l2tpsess l2tpeth enslaved configured
4 links listed.
# ip l2tp show tunnel
Tunnel 100, encap UDP
From 10.0.0.1 to 10.1.0.1
Peer tunnel 101
UDP source / dest ports: 6000/6001
UDP checksum: disabled
# ip l2tp show session
Session 10 in tunnel 100
Peer session 11, tunnel 101
interface name: l2tpsess
offset 0, peer offset 0