Docs/BashScripts/install-ufw.sh
2022-12-22 08:25:34 +01:00

41 lines
1.0 KiB
Bash

# Install using: sudo su -c "bash <(wget -qO- /url/to/install-ufw.sh)"
# Make sure script is ran as root
if [[ $EUID -ne 0 ]]; then
exec sudo /bin/bash "$0" "$@"
fi
REALUSER=$(logname)
apt update -qq 2>>install.log
iptables --list >/dev/null 2>&1 && (
echo "Disabling iptables..."
# Accept all traffic first to avoid ssh lockdown via iptables firewall rules #
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# Flush All Iptables Chains/Firewall rules #
iptables -F
# Delete all Iptables Chains #
iptables -X
# Flush all counters too #
iptables -Z
# Flush and delete all nat and mangle #
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -t raw -F
iptables -t raw -X
)
ufw status >/dev/null 2>&1 || (
echo "Installing UFW..."
apt install ufw -y 2>>install.log
ufw default allow outgoing 2>>install.log
ufw default deny incoming 2>>install.log
ufw allow ssh 2>>install.log
ufw enable 2>>install.log
)
echo 'Installation complete'