-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-wireguard.sh
More file actions
executable file
·86 lines (72 loc) · 2.01 KB
/
make-wireguard.sh
File metadata and controls
executable file
·86 lines (72 loc) · 2.01 KB
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
80
81
82
83
84
85
86
#!/bin/bash
#Edit these varaibles as needed
#ENDPOINT=your_server_ip:your_server_port
ENDPOINT=
#SERVERPUB=your_wireguard_servers_public_key
SERVERPUB=
#CLIENTIPADDR=the_internal_wireguard_ip_address_your_client_will_have
CLIENTIPADDR=
#CLIENTDNS=the_ip_address_of_the_dns_server_your_client_will_user
CLIENTDNS=
#No need to edit anything below here
if [ -z "$ENDPOINT" ]; then
echo "Please edit this file and specify your server endpoint IP and port in format 1.2.3.4:1234"
exit 1;
fi
if [ -z "$SERVERPUB" ]; then
echo "Please edit this file and specify your wireguard server public key"
exit 1;
fi
if [ -z "$CLIENTIPADDR" ]; then
echo "Please edit this file and specify the private IP of your new client"
exit 1;
fi
if [ -z "$CLIENTDNS" ]; then
echo "Please edit this file and specify the DNS server the client should use"
exit 1;
fi
if ! command -v wg &> /dev/null
then
echo "Please install wireguard-tools first"
exit
fi
if ! command -v qrencode &> /dev/null
then
echo "Please install qrencode"
exit
fi
if [ "$EUID" -ne 0 ]
then echo "Please run as root in order to make and mount a ramfs to ensure no keys are kept on disk"
exit
fi
WORKDIR=$(mktemp -d)
mount -t ramfs -o size=2m ramfs $WORKDIR
CLIENTKEY=$(wg genkey)
CLIENTPUB=$(echo $CLIENTKEY | wg pubkey)
PSKEY=$(wg genpsk)
/bin/cat <<EOF > $WORKDIR/client.conf
[Interface]
PrivateKey = $CLIENTKEY
Address = $CLIENTIPADDR/32
DNS = $CLIENTDNS
[Peer]
PublicKey = $SERVERPUB
AllowedIPs = 0.0.0.0/0
Endpoint = $ENDPOINT
PreSharedKey = $PSKEY
EOF
qrencode -t ansiutf8 < $WORKDIR/client.conf
echo
echo "Please scan the above on your client device"
echo "Please add the following to your server wireguard config and reload server wireguard config"
echo
echo "[Peer]"
echo "PublicKey = $CLIENTPUB"
echo "AllowedIPs = $CLIENTIPADDR/32"
echo "PreSharedKey = $PSKEY"
rm -r $WORKDIR/*
umount $WORKDIR
rm -r $WORKDIR
echo
read -p "Once you have set up the device and installed the server [Peer] entry, please press enter to blank the screen"
clear