From 20909b75d2a06b6f5b202e05a961b5349a3e5490 Mon Sep 17 00:00:00 2001 From: lub Date: Sat, 5 Nov 2022 05:07:34 +0100 Subject: [PATCH] implement automatic ipv6 address finding also pin to mac address fixes #7 --- hardware/hetzner_ax51-nvme/network.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/hardware/hetzner_ax51-nvme/network.sh b/hardware/hetzner_ax51-nvme/network.sh index 3ce5913..9f7a965 100755 --- a/hardware/hetzner_ax51-nvme/network.sh +++ b/hardware/hetzner_ax51-nvme/network.sh @@ -1,18 +1,24 @@ #!/bin/bash -e -address=$(ip address show dev eth0 scope global | grep -F 'inet ' | perl -pe 's#.*inet (.*?)/.*#$1#') -gateway=$(ip route list dev eth0 default | perl -pe 's#.*via (.*) #$1#') +default_routev4=$(ip route list | grep -F 'default') -# $interface differs from the live system because of different naming schemes -# see https://wiki.debian.org/NetworkInterfaceNames for more details -interface='enp35s0' +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] -Name=$interface +MACAddress=$macaddress [Network] -Gateway=$gateway +Gateway=$gatewayv4 +Gateway=fe80::1 Address=116.202.199.132/32 Address=116.202.199.133/32 Address=116.202.199.134/32 @@ -27,5 +33,8 @@ Address=5.9.203.246/32 Address=5.9.203.247/32 [Address] -Address=${address}/32 -Peer=${gateway}/32" > "/etc/systemd/network/${interface}.network" +Address=${addressv4}/32 +Peer=${gatewayv4}/32 + +[Address] +Address=${addressv6}::1337/64" > "/etc/systemd/network/internet.network"