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
| #!/usr/bin/with-contenv bash
echo "**** installing inotify-tools ****"
apt-get update && apt-get install inotify-tools -y
echo "**** installing config ****"
echo '
[Interface]
Address = '$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')'.1
ListenPort = 51820
PrivateKey = '$(cat /config/server/privatekey-server)'
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
' > /config/wg0.conf
echo '
{
"address": [
"'$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')'.1/24"
],
"listenPort": 51820,
"mtu": 0,
"privateKey": "'$(cat /config/server/privatekey-server)'",
"publicKey": "'$(cat /config/server/publickey-server)'",
"endpoint": "'${SERVERURL}:${SERVERPORT}'",
"persistentKeepalive": 16,
"dns": [
"'$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')'.1"
],
"allowedips": [
"'${ALLOWEDIPS}'"
],
"preUp": "echo WireGuard PreUp",
"postUp": "iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE",
"preDown": "echo WireGuard PreDown",
"postDown": "iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE",
"updatedBy": "",
"created": "'$(date +%Y-%m-%dT%H:%M:%S.%NZ)'",
"updated": "'$(date +%Y-%m-%dT%H:%M:%S.%NZ)'"
}
' > /config/server.json
COREDNSID='44d338ce-e383-11eb-b7fa-0b1c92374c21'
echo '
{
"id": "'$COREDNSID'",
"name": "CoreDNS",
"email": "CoreDNS@example.com",
"enable": false,
"ignorePersistentKeepalive": false,
"presharedKey": "",
"allowedIPs": [
"'${ALLOWEDIPS}'"
],
"address": [
"'$(echo "$INTERNAL_SUBNET" | awk 'BEGIN{FS=OFS="."} NF--')'.1/32"
],
"tags": [],
"privateKey": "",
"publicKey": "",
"createdBy": "",
"updatedBy": "",
"created": "'$(date +%Y-%m-%dT%H:%M:%S.%NZ)'",
"updated": "'$(date +%Y-%m-%dT%H:%M:%S.%NZ)'"
}
' > /config/$COREDNSID
|