forked from areyer/ffs-make-gateway
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_heipv6_ubuntu.sh
60 lines (50 loc) · 1.75 KB
/
setup_heipv6_ubuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
setup_heipv6_config() {
DATEIHE="/usr/local/bin/heipv6"
if [ -f $DATEIHE ]; then
HE_GW_V4=$(head -5 $DATEIHE | grep HE_GW_V4= | cut -d '=' -f2)
HE_IF_V6=$(head -5 $DATEIHE | grep HE_IF_V6= | cut -d '=' -f2)
HE_IP_V6=$(head -5 $DATEIHE | grep HE_IP_V6= | cut -d '=' -f2)
HE_IPS_V6=$(head -5 $DATEIHE | grep HE_IPS_V6= | cut -d '=' -f2)
fi
test -z $HE_GW_V4 && HE_GW_V4="1.2.3.4"
test -z $HE_IF_V6 && HE_IF_V6="he-ipv6"
test -z $HE_IP_V6 && HE_IP_V6="1:2:3:4::2/64"
test -z $HE_IPS_V6 && HE_IPS_V6="5:6:7::/48"
HE_IPS_V6_PRE=$(echo "$HE_IPS_V6" | cut -d ':' -f1-3)
#HE_GW_V4=216.66.84.46
#HE_IF_V6=he-ipv6
#HE_IP_V6=2001:470:1f14:bc4::2/64
#HE_IPS_V6=2001:470:7cf4::/48
cat <<EOF >/usr/local/bin/heipv6
#!/bin/bash
HE_GW_V4=$HE_GW_V4
HE_IF_V6=$HE_IF_V6
HE_IP_V6=$HE_IP_V6
HE_IPS_V6=$HE_IPS_V6
modprobe ipv6
HE_IPS_V6_PRE=$HE_IPS_V6_PRE
# alte tunnel loeschen
for seg in $SEGMENTLIST ; do
ip route del \${HE_IPS_V6_PRE}:4b\${seg}::/64 dev br\$seg
ip route del \${HE_IPS_V6_PRE}:4b\${seg}::/64 dev br\$seg table stuttgart
done
ip addr del $HE_IP_V6 dev $HE_IF_V6
ip tunnel del $HE_IF_V6 mode sit remote $HE_GW_V4 local $EXT_IP_V4 ttl 255
sleep 5
# neuer tunnel aufbauen
ip tunnel add $HE_IF_V6 mode sit remote $HE_GW_V4 local $EXT_IP_V4 ttl 255
ip link set $HE_IF_V6 up
ip addr add $HE_IP_V6 dev $HE_IF_V6
ip route add ::/0 dev $HE_IF_V6
ip addr show dev $HE_IF_V6
# zusatzrouten
for seg in $SEGMENTLIST ; do
ip route add \${HE_IPS_V6_PRE}:4b\${seg}::/64 dev br\$seg
ip route add \${HE_IPS_V6_PRE}:4b\${seg}::/64 dev br\$seg table stuttgart
# lokale Mac anpassen
ip addr del dev br\$seg \$(ip addr show dev br\$seg | grep fe80: | tail -1 | awk '{print \$2}')
ip addr add dev br\$seg scope link fe80::4b\${seg}:a38:$GWLID$GWLSUBID/64
done
EOF
chmod +x $DATEIHE
}