linutil/src/commands/security/firewall-baselines.sh

49 lines
1.0 KiB
Bash
Raw Normal View History

2024-07-30 20:01:13 +01:00
#!/bin/sh -e
2024-08-02 15:19:20 +01:00
. ./common-script.sh
2024-07-30 20:01:13 +01:00
installPkg() {
echo "Install UFW if not already installed..."
if ! command_exists ufw; then
case ${PACKAGER} in
pacman)
sudo "${PACKAGER}" -S --noconfirm ufw
;;
*)
sudo "${PACKAGER}" install -y ufw
;;
esac
else
echo "UFW is already installed."
fi
2024-08-02 15:19:20 +01:00
}
configureUFW() {
2024-07-30 20:01:13 +01:00
echo -e "${GREEN}Using Chris Titus Recommended Firewall Rules${RC}"
2024-08-02 15:19:20 +01:00
echo "Disabling UFW"
sudo ufw disable
2024-07-30 20:01:13 +01:00
echo "Limiting port 22/tcp (UFW)"
2024-08-02 15:19:20 +01:00
sudo ufw limit 22/tcp
2024-07-30 20:01:13 +01:00
echo "Allowing port 80/tcp (UFW)"
2024-08-02 15:19:20 +01:00
sudo ufw allow 80/tcp
2024-07-30 20:01:13 +01:00
echo "Allowing port 443/tcp (UFW)"
2024-08-02 15:19:20 +01:00
sudo ufw allow 443/tcp
2024-07-30 20:01:13 +01:00
echo "Denying Incoming Packets by Default(UFW)"
2024-08-02 15:19:20 +01:00
sudo ufw default deny incoming
2024-07-30 20:01:13 +01:00
echo "Allowing Outcoming Packets by Default(UFW)"
2024-08-02 15:19:20 +01:00
sudo ufw default allow outgoing
2024-07-30 20:01:13 +01:00
echo -e "${GREEN}Enabled Firewall with Baselines!${RC}"
2024-08-02 15:19:20 +01:00
sudo ufw enable
2024-07-30 20:01:13 +01:00
}
checkEnv
installPkg
2024-08-02 15:19:20 +01:00
configureUFW