-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwg.sh
79 lines (61 loc) · 2 KB
/
wg.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
if [ $# != 2 ]; then
echo "Use ./wg.sh remotepublickey ifname"
exit
fi
#Diese Daten bitte anpassen:
ipv6ll="fe80::XX:XX:XX:XX"
ipv6ula="fd43:5602:29bd:ffff::XX"
ipv4="10.83.252.X"
publicip="11.22.33.44"
portbase=31337
#Ab hier nichts mehr ändern!
port=$portbase
while grep $port /etc/wireguard/*.conf &>/dev/null ; do ((port+=1)); done
echo "Generiere Keys:"
privkey=$(wg genkey); pubkey=$(echo $privkey | wg pubkey)
echo "Privater Key:"
echo "$privkey"
echo "Public Key:"
echo "$pubkey"
echo "Lege wireguard config an:"
echo "[Interface]
PrivateKey = "$privkey"
ListenPort = $port
[Peer]
PublicKey = $1
AllowedIPs = 0.0.0.0/0, ::/0
" | tee /etc/wireguard/$2.conf
echo "Lege Interface an:"
echo "
auto $2
iface $2 inet static
address $ipv4
# initialize wireguard
pre-up ip link add $2 type wireguard
pre-up wg setconf $2 /etc/wireguard/$2.conf
# babeld
pre-up ip link set dev $2 multicast on
pre-up ip -6 addr add $ipv6ll dev $2
pre-up ip -6 addr add $ipv6ula dev $2
# freifunk rule
pre-up ip rule add from all iif $2 lookup fff
pre-up ip -6 rule add from all iif $2 lookup fff
post-down ip rule del iif $2 table fff
post-down ip -6 rule del from all iif $2 lookup fff
# Clamping
post-up iptables -t mangle -A POSTROUTING -p tcp --tcp-flags SYN,RST SYN -o $2 -j TCPMSS --clamp-mss-to-pmtu
post-down iptables -t mangle -D POSTROUTING -p tcp --tcp-flags SYN,RST SYN -o $2 -j TCPMSS --clamp-mss-to-pmtu
# kill Interface
post-down ip link del $2
" | tee /etc/network/interfaces.d/$2
echo "Starte Interface:"
ifup $2
echo "Schreibe Babel config:"
sed -i 's/INTERFACES="/INTERFACES="'$2' /' /etc/default/babeld
#ACHTUNG! Im sed u.U. die Zeilennummer anpassen!
sed -i '4i interface '$2' type tunnel max-rtt-penalty 128' /etc/babeld.conf
echo "Starte babeld neu"
/etc/init.d/babeld restart
echo "Publickey, IP und Port weitergeben an Peeringpartner:"
echo "$pubkey $publicip $port"