implement automatic ipv6 address finding

also pin to mac address

fixes #7
master
lub 2 years ago
parent 447f71e8c2
commit 20909b75d2

@ -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"

Loading…
Cancel
Save