From c2626bc09b4204b9d52447df36aa8930bea6be7a Mon Sep 17 00:00:00 2001 From: Pavel Muhortov Date: Mon, 31 Jul 2023 05:58:46 +0300 Subject: [PATCH] add PersistentKeepalive option to wg0.conf --- wg-client-management.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wg-client-management.sh b/wg-client-management.sh index 12d11de..6a911f8 100644 --- a/wg-client-management.sh +++ b/wg-client-management.sh @@ -113,11 +113,14 @@ createcert() { wg genkey | tee "/etc/wireguard/pki/${clientname}-private.key" | wg pubkey > "/etc/wireguard/pki/${clientname}-public.key" clientpublkey=$(cat "/etc/wireguard/pki/${clientname}-public.key") clientprivkey=$(cat "/etc/wireguard/pki/${clientname}-private.key") - wg set wg0 peer "${clientpublkey}" allowed-ips "${clientaddr}/32" + wg set wg0 peer "${clientpublkey}" \ + allowed-ips "${clientaddr}/32" \ + persistent-keepalive 5 { echo -e "[Peer]" echo -e " PublicKey = ${clientpublkey}" echo -e " AllowedIPs = ${clientaddr}/32" + echo -e " PersistentKeepalive = 5" } >> ${servercfgname} ip -4 route add "${clientaddr}/32" dev wg0 } @@ -173,10 +176,15 @@ deletecert() { wg set wg0 peer "${clientpublkey}" remove rm -f "/etc/wireguard/pki/${clientname}-public.key" rm -f "/etc/wireguard/pki/${clientname}-private.key" + # PublicKey = s2=$(grep -n "${clientpublkey}" ${servercfgname} | cut -d":" -f1) + # [Peer] s1=$(( s2 - 1 )) + # AllowedIPs = s3=$(( s2 + 1 )) - sed -i "${s1}d;${s2}d;${s3}d" ${servercfgname} + # PersistentKeepalive = + s4=$(( s2 + 2 )) + sed -i "${s1}d;${s2}d;${s3}d;${s4}d" ${servercfgname} ip -4 route del "${clientaddr}/32" dev wg0 }