#!/bin/bash -e default_routev4=$(ip route list | grep -F 'default') interface=$(echo "$default_routev4" | perl -pe 's#^.* dev (\w+) .*$#$1#') macaddress=$(ip address show dev "$interface" | grep -F 'link/ether' | perl -pe 's#^.*link/ether ([a-z0-9:]*) brd .+$#$1#') addresses=$(ip address show dev "$interface" scope global) gatewayv4=$(echo "$default_routev4" | perl -pe 's#^.* via ([\d.]+) .*$#$1#') addressv4=$(echo "$addresses" | grep -F 'inet ' | perl -pe 's#^.* inet ([\d.]+).*#$1#') addressv6=$(echo "$addresses" | grep -F 'inet6 ' | perl -pe 's#^.* inet6 ([a-z0-9:]+)::[a-z0-9]+.*$#$1#') echo "[Match] MACAddress=${macaddress} Type=ether [Network] Gateway=fe80::1 Gateway=${gatewayv4} [Address] Address=${addressv6}::1337/64 [Address] Address=${addressv4}/32 Peer=${gatewayv4}/32 [Network] VLAN=ingress VLAN=kubernetes" > "/etc/systemd/network/egress.network" echo "[NetDev] Name=ingress Kind=vlan MTUBytes=1400 [VLAN] Id=4000" > "/etc/systemd/network/ingress.netdev" echo "[Match] Name=ingress [Network] Description=\"ingress\" [Route] Gateway=2a01:4f8:fff0:a5::1 Table=4000 [Route] Gateway=157.90.103.81 Table=4000 [RoutingPolicyRule] From=2a01:4f8:fff0:a5::/64 Table=4000 [RoutingPolicyRule] From=157.90.103.80/28 Table=4000 [RoutingPolicyRule] To=2a01:4f8:fff0:a5::/64 Table=4000 [RoutingPolicyRule] To=157.90.103.80/28 Table=4000" > "/etc/systemd/network/ingress.network" echo "[NetDev] Name=kubernetes Kind=vlan MTUBytes=1400 [VLAN] Id=4010" > "/etc/systemd/network/kubernetes.netdev" echo "[Match] Name=kubernetes [Network] Description=\"kubernetes\" Address=10.73.19.fixme/24 Address=fdad:73ce:19db::fixme/48" > "/etc/systemd/network/kubernetes.network"