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]
|
[Peer]
|
||||||
PublicKey = ${SERVER_PUBLIC_KEY}
|
PublicKey = ${SERVER_PUBLIC_KEY}
|
||||||
AllowedIPs = 10.0.0.0/16
|
AllowedIPs = 10.0.0.0/16
|
||||||
Endpoint = wg.oliveratkinson.net:51820
|
Endpoint = ${ENDPOINT}
|
||||||
PersistentKeepalive = 25
|
PersistentKeepalive = 25
|
||||||
|
@ -1,23 +1,40 @@
|
|||||||
#!/bin/bash
|
#!/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)
|
TEMP_CONF=$(mktemp)
|
||||||
# numbers are exit codes to run command on
|
SERVER_NAME="cs2"
|
||||||
trap "rm -f $TEMP_CONF; export CLIENT_PRIVATE_KEY=" 0 1 2 3 6 9 14 15
|
SERVER_CONF_FILE="./server/${SERVER_NAME}.conf"
|
||||||
|
SERVER_KEYFILE="./server/private.key"
|
||||||
|
export ENDPOINT="wg.oliveratkinson.net:51820"
|
||||||
|
|
||||||
# Add peer to server conf file
|
# Make server
|
||||||
# envsubst < peer.template > $TEMP_CONF
|
if [[ ! -e "${SERVER_KEYFILE}" ]]; then
|
||||||
# wg addconf $SERVER_NAME $TEMP_CONF
|
mkdir server 2> /dev/null
|
||||||
wg set $SERVER_NAME $(wg pubkey < $CLIENT_PRIVATE_KEY) allowed-ips 10.0.0.${IP_ADDR}/16
|
umask 077
|
||||||
ip -4 route add 10.0.0.${IP_ADDR}/16 dev $SERVER_NAME
|
wg genkey > $SERVER_KEYFILE
|
||||||
|
|
||||||
# Generate client conf file
|
if [[ ! -e "${SERVER_CONF_FILE}" ]]; then
|
||||||
envsubst < client.template > client${IP_ADDR}.$SERVER_NAME.conf
|
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]
|
[Peer]
|
||||||
PublicKey = ${SERVER_PUBLIC_KEY}
|
PublicKey = ${CLIENT_PUBLIC_KEY}
|
||||||
AllowedIPs = 10.0.0.${IP_ADDR}/16
|
AllowedIPs = 10.0.0.${IP_ADDR}/16
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[Interface]
|
[Interface]
|
||||||
PrivateKey = ${SERVER_PRIVATE_KEY}
|
PrivateKey = ${SERVER_PRIVATE_KEY}
|
||||||
Address = 10.0.0.0/16
|
Address = 10.0.0.1/16
|
||||||
SaveConfig = true
|
SaveConfig = true
|
||||||
ListenPort = 51820
|
ListenPort = 51820
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user