#!/bin/sh
ip route add 169.254.42.42 dev eth0 2>/dev/null
serverinfo=$(curl -s -X GET "http://169.254.42.42/conf?format=json")
ipv6info=$(echo $serverinfo | grep -Eo '"ipv6": {[^}]+}')
address=$(echo $ipv6info | sed -r 's/^.*"address": "([^"]+)".*$/\1/g')
gateway=$(echo $ipv6info | sed -r 's/^.*"gateway": "([^"]+)".*$/\1/g')
netmask=$(echo $ipv6info | sed -r 's/^.*"netmask": "([^"]+)".*$/\1/g')
if [ -n "$address" ] && [ -n "$gateway" ] && [ -n "$netmask" ]; then
ip addr flush dev eth0
ip addr add $address/$netmask dev eth0
ip -6 route add $gateway dev eth0
ip -6 route add default via $gateway
fi
然后修改/etc/network/interfaces的内容为如下:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
up sh /root/network.sh