-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path02_gen_configs.sh
executable file
·59 lines (46 loc) · 1.2 KB
/
02_gen_configs.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
#!/bin/bash
# generates bay_srv.conf and client configs
if [ -d configs ]; then
echo "./configs dir already exists, remove it and restart"
exit 1
fi
mkdir -p configs
if ! cd configs; then
echo "failed to change dir to configs"
exit 1
fi
# detect external ip
IP=`curl -s https://ipinfo.io/ip`
if [[ ! $IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "No external IP detected, exiting"
exit 1
fi
NET="10.161.0"
PORT=5353
SRV_PRIV_KEY=`wg genkey`
SRV_PUB_KEY=`echo "$SRV_PRIV_KEY"|wg pubkey`
# write initial config
echo "[Interface]
PrivateKey = $SRV_PRIV_KEY
ListenPort = $PORT
PostUp = iptables -t nat -A POSTROUTING -s ${NET}.0/24 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s ${NET}.0/24 -j MASQUERADE
PostUp = sysctl net.ipv4.ip_forward=1
" > bay_srv.conf
for i in {2..255}; do
CLT_PRIV_KEY=`wg genkey`
CLT_PUB_KEY=`echo "$CLT_PRIV_KEY"|wg pubkey`
echo "[Peer]
PublicKey = $CLT_PUB_KEY
AllowedIPs = ${NET}.${i}/32
" >> bay_srv.conf
echo "[Interface]
PrivateKey = $CLT_PRIV_KEY
Address = ${NET}.${i}/24
DNS = 8.8.8.8
[Peer]
PublicKey = $SRV_PUB_KEY
Endpoint = $IP:$PORT
AllowedIPs = 0.0.0.0/0" > bay_clt_$i.conf
done
echo "Configs are generated, see ./configs dir"