updates
This commit is contained in:
parent
fa84855297
commit
eaa62c07ca
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/server
|
||||
/clients
|
@ -5,5 +5,5 @@
|
||||
[Peer]
|
||||
PublicKey = ${SERVER_PUBLIC_KEY}
|
||||
AllowedIPs = 10.0.0.0/16
|
||||
Endpoint = wg.oliveratkinson.net:51820
|
||||
Endpoint = ${ENDPOINT}
|
||||
PersistentKeepalive = 25
|
||||
|
@ -1,23 +1,40 @@
|
||||
#!/bin/bash
|
||||
printf "Run as sudo\nPress any key to continue..."
|
||||
read
|
||||
printf "Make sure interface is up.\nPress any key to continue..."
|
||||
read
|
||||
|
||||
export IP_ADDR="10"
|
||||
export SERVER_PUBLIC_KEY=$(wg pubkey < /etc/wireguard/private.key)
|
||||
export CLIENT_PRIVATE_KEY=$(wg genkey)
|
||||
SERVER_NAME="cs2"
|
||||
TEMP_CONF=$(mktemp)
|
||||
# numbers are exit codes to run command on
|
||||
trap "rm -f $TEMP_CONF; export CLIENT_PRIVATE_KEY=" 0 1 2 3 6 9 14 15
|
||||
SERVER_NAME="cs2"
|
||||
SERVER_CONF_FILE="./server/${SERVER_NAME}.conf"
|
||||
SERVER_KEYFILE="./server/private.key"
|
||||
export ENDPOINT="wg.oliveratkinson.net:51820"
|
||||
|
||||
# Add peer to server conf file
|
||||
# envsubst < peer.template > $TEMP_CONF
|
||||
# wg addconf $SERVER_NAME $TEMP_CONF
|
||||
wg set $SERVER_NAME $(wg pubkey < $CLIENT_PRIVATE_KEY) allowed-ips 10.0.0.${IP_ADDR}/16
|
||||
ip -4 route add 10.0.0.${IP_ADDR}/16 dev $SERVER_NAME
|
||||
# Make server
|
||||
if [[ ! -e "${SERVER_KEYFILE}" ]]; then
|
||||
mkdir server 2> /dev/null
|
||||
umask 077
|
||||
wg genkey > $SERVER_KEYFILE
|
||||
|
||||
# Generate client conf file
|
||||
envsubst < client.template > client${IP_ADDR}.$SERVER_NAME.conf
|
||||
if [[ ! -e "${SERVER_CONF_FILE}" ]]; then
|
||||
export SERVER_PRIVATE_KEY=$(cat $SERVER_KEYFILE)
|
||||
envsubst < server.template > $SERVER_CONF_FILE
|
||||
fi
|
||||
fi
|
||||
export SERVER_PUBLIC_KEY=$(wg pubkey < $SERVER_KEYFILE)
|
||||
|
||||
create_client() {
|
||||
mkdir clients 2> /dev/null
|
||||
umask 077
|
||||
CPRK="/tmp/cprk"
|
||||
CPUK="/tmp/cpuk"
|
||||
wg genkey | tee $CPRK | wg pubkey > $CPUK
|
||||
#export CLIENT_PRIVATE_KEY=$(cat $CLIENT_PK_FILE)
|
||||
export CLIENT_PRIVATE_KEY=$(cat $CPRK)
|
||||
export CLIENT_PUBLIC_KEY=$(cat $CPUK)
|
||||
export IP_ADDR=$1
|
||||
|
||||
envsubst < client.template > clients/client${IP_ADDR}.$SERVER_NAME.conf
|
||||
envsubst < peer.template >> $SERVER_CONF_FILE
|
||||
rm $CPUK $CPRK
|
||||
}
|
||||
# create clients
|
||||
for i in {2..5}; do
|
||||
create_client $i
|
||||
done
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
[Peer]
|
||||
PublicKey = ${SERVER_PUBLIC_KEY}
|
||||
AllowedIPs = 10.0.0.${IP_ADDR}/16
|
||||
PublicKey = ${CLIENT_PUBLIC_KEY}
|
||||
AllowedIPs = 10.0.0.${IP_ADDR}/16
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Interface]
|
||||
PrivateKey = ${SERVER_PRIVATE_KEY}
|
||||
Address = 10.0.0.0/16
|
||||
Address = 10.0.0.1/16
|
||||
SaveConfig = true
|
||||
ListenPort = 51820
|
||||
|
Loading…
Reference in New Issue
Block a user