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 #!/bin/bash -e
address=$(ip address show dev eth0 scope global | grep -F 'inet ' | perl -pe 's#.*inet (.*?)/.*#$1#') default_routev4=$(ip route list | grep -F 'default')
gateway=$(ip route list dev eth0 default | perl -pe 's#.*via (.*) #$1#')
# $interface differs from the live system because of different naming schemes interface=$(echo "$default_routev4" | perl -pe 's#^.* dev (\w+) .*$#$1#')
# see https://wiki.debian.org/NetworkInterfaceNames for more details macaddress=$(ip address show dev "$interface" | grep -F 'link/ether' | perl -pe 's#^.*link/ether ([a-z0-9:]*) brd .+$#$1#')
interface='enp35s0'
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] echo "[Match]
Name=$interface MACAddress=$macaddress
[Network] [Network]
Gateway=$gateway Gateway=$gatewayv4
Gateway=fe80::1
Address=116.202.199.132/32 Address=116.202.199.132/32
Address=116.202.199.133/32 Address=116.202.199.133/32
Address=116.202.199.134/32 Address=116.202.199.134/32
@ -27,5 +33,8 @@ Address=5.9.203.246/32
Address=5.9.203.247/32 Address=5.9.203.247/32
[Address] [Address]
Address=${address}/32 Address=${addressv4}/32
Peer=${gateway}/32" > "/etc/systemd/network/${interface}.network" Peer=${gatewayv4}/32
[Address]
Address=${addressv6}::1337/64" > "/etc/systemd/network/internet.network"

Loading…
Cancel
Save