generated from pavel.muhortov/template-bash
add PersistentKeepalive option to wg0.conf
This commit is contained in:
parent
142a389d26
commit
c2626bc09b
|
@ -113,11 +113,14 @@ createcert() {
|
||||||
wg genkey | tee "/etc/wireguard/pki/${clientname}-private.key" | wg pubkey > "/etc/wireguard/pki/${clientname}-public.key"
|
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")
|
clientpublkey=$(cat "/etc/wireguard/pki/${clientname}-public.key")
|
||||||
clientprivkey=$(cat "/etc/wireguard/pki/${clientname}-private.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 "[Peer]"
|
||||||
echo -e " PublicKey = ${clientpublkey}"
|
echo -e " PublicKey = ${clientpublkey}"
|
||||||
echo -e " AllowedIPs = ${clientaddr}/32"
|
echo -e " AllowedIPs = ${clientaddr}/32"
|
||||||
|
echo -e " PersistentKeepalive = 5"
|
||||||
} >> ${servercfgname}
|
} >> ${servercfgname}
|
||||||
ip -4 route add "${clientaddr}/32" dev wg0
|
ip -4 route add "${clientaddr}/32" dev wg0
|
||||||
}
|
}
|
||||||
|
@ -173,10 +176,15 @@ deletecert() {
|
||||||
wg set wg0 peer "${clientpublkey}" remove
|
wg set wg0 peer "${clientpublkey}" remove
|
||||||
rm -f "/etc/wireguard/pki/${clientname}-public.key"
|
rm -f "/etc/wireguard/pki/${clientname}-public.key"
|
||||||
rm -f "/etc/wireguard/pki/${clientname}-private.key"
|
rm -f "/etc/wireguard/pki/${clientname}-private.key"
|
||||||
|
# PublicKey =
|
||||||
s2=$(grep -n "${clientpublkey}" ${servercfgname} | cut -d":" -f1)
|
s2=$(grep -n "${clientpublkey}" ${servercfgname} | cut -d":" -f1)
|
||||||
|
# [Peer]
|
||||||
s1=$(( s2 - 1 ))
|
s1=$(( s2 - 1 ))
|
||||||
|
# AllowedIPs =
|
||||||
s3=$(( s2 + 1 ))
|
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
|
ip -4 route del "${clientaddr}/32" dev wg0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user