Skip to content

Instantly share code, notes, and snippets.

@scottydelta
Last active December 29, 2025 22:17
Show Gist options
  • Select an option

  • Save scottydelta/b9869c4c082fec5a893cd39651cb1f3f to your computer and use it in GitHub Desktop.

Select an option

Save scottydelta/b9869c4c082fec5a893cd39651cb1f3f to your computer and use it in GitHub Desktop.
ufw default rules

Default settings

sudo ufw default deny incoming

sudo ufw default allow outgoing

Allow from particular IP (VPN Private IP) to all ports

sudo ufw allow from X.X.X.X

Allow from particular IP to particular port

sudo ufw allow from X.X.X.X to any port 22

Allow to particular port from all IP

sudo ufw allow 443

Enable firewall

sudo ufw enable

UFW with docker

Standard ufw rules don't work well with Docker because Docker manipulates iptables directly. Use ufw-docker to fix this: https://github.com/chaifeng/ufw-docker

sudo wget -O /usr/local/bin/ufw-docker \
  https://github.com/chaifeng/ufw-docker/raw/master/ufw-docker
sudo chmod +x /usr/local/bin/ufw-docker
sudo ufw-docker install

Restart UFW

sudo systemctl restart ufw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment