Skip to content

UFW rules check and protocol, comment, limit improvement #136

@Awlskiy

Description

@Awlskiy

ufw allow from $PANEL_IP to any port 2222 > /dev/null 2>&1

ufw allow from $PANEL_IP to any port 2222 proto tcp comment 'Panel Connection' > /dev/null 2>&1

if ! ufw allow 22/tcp comment 'SSH' || ! ufw allow 443/tcp comment 'HTTPS' || ! ufw --force enable; then

if ! ufw limit 22/tcp comment 'SSH' || ! ufw allow 443/tcp comment 'HTTPS' || ! ufw --force enable; then

Plus check for SSH ufw rule:
SSH_PORT=$(grep '^Port' /etc/ssh/sshd_config | awk '{print $2}' || :)

if [ -z "$SSH_PORT" ]; then
SSH_PORT=22
fi

if ! sudo ufw status numbered | grep -qw "$SSH_PORT"; then
ufw limit "$SSH_PORT"/tcp comment "SSH" >& /dev/null
fi

By the same logic, I propose to implement a presence check for all other rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions