#!/usr/bin/env bash # usage: # wg-genconf.sh [ [ []]] set -e # exit when any command fails set -x # enable print all commands # clients' count clients_count=${1:-10} # dns ip dns_ip=${2:-10.0.0.1} # server ip server_ip=${3} if [ -z "$server_ip" ]; then server_ip=$(hostname -I | awk '{print $1;}') # get only first hostname fi server_private_key=$(wg genkey) server_public_key=$(echo "${server_private_key}" | wg pubkey) server_config=wg0.conf # The older code was directly referencing eth0 as the public interface in PostUp&PostDown events. # Let's find that interface's name dynamic. # If you have a different configuration just uncomment and edit the following line and comment the next. # #server_public_interface=eth0 # # thanks https://github.com/buraksarica for this improvement. server_public_interface=$(route -n | awk '$1 == "0.0.0.0" {print $8}') echo Generate server \("${server_ip}"\) config: echo echo -e "\t$(pwd)/${server_config}" # # server configs # cat > "${server_config}" < "${client_config}" <> "${server_config}" <