fix(ufw): Fix ufw insert error

fix ufw error when inserting rules with an empty chain
This commit is contained in:
4s3ti 2022-09-17 15:10:15 +02:00
parent 955f268db2
commit 8603013fc3
No known key found for this signature in database
GPG key ID: AC2D3B898F96BC51

View file

@ -3178,21 +3178,25 @@ confNetwork() {
fi fi
fi fi
# Insert rules at the beginning of the chain # Checks for any existing UFW rules and
# insert rules at the beginning of the chain
# (in case there are other rules that may drop the traffic) # (in case there are other rules that may drop the traffic)
${SUDO} ufw insert 1 \ if ${SUDO} ufw status numbered | grep -E "\[.[0-9]{1}\]" > /dev/null; then
allow "${pivpnPORT}/${pivpnPROTO}" \ ${SUDO} ufw insert 1 \
comment "allow-${VPN}" > /dev/null allow "${pivpnPORT}/${pivpnPROTO}" \
${SUDO} ufw route insert 1 \ comment "allow-${VPN}" > /dev/null
allow in on "${pivpnDEV}" \
from "${pivpnNET}/${subnetClass}" \
out on "${IPv4dev}" to any > /dev/null
if [[ "${pivpnenableipv6}" -eq 1 ]]; then
${SUDO} ufw route insert 1 \ ${SUDO} ufw route insert 1 \
allow in on "${pivpnDEV}" \ allow in on "${pivpnDEV}" \
from "${pivpnNETv6}/${subnetClassv6}" \ from "${pivpnNET}/${subnetClass}" \
out on "${IPv6dev}" to any > /dev/null out on "${IPv4dev}" to any > /dev/null
if [[ "${pivpnenableipv6}" -eq 1 ]]; then
${SUDO} ufw route insert 1 \
allow in on "${pivpnDEV}" \
from "${pivpnNETv6}/${subnetClassv6}" \
out on "${IPv6dev}" to any > /dev/null
fi
fi fi
${SUDO} ufw reload > /dev/null ${SUDO} ufw reload > /dev/null