Skip to content

Instantly share code, notes, and snippets.

@BobCHub
Last active September 26, 2022 18:28
Show Gist options
  • Save BobCHub/8d424952242eff564e84b7217247fb33 to your computer and use it in GitHub Desktop.
Save BobCHub/8d424952242eff564e84b7217247fb33 to your computer and use it in GitHub Desktop.
ufw reference
Firewall with UFW 
sudo apt-get install ufw -------- Install ufw
sudo Vim /etc/default/ufw ------- Edit UFW configuration
sudo ufw reset ------------------ reset ufw rules
sudo ufw default deny incoming -- To set the defaults
sudo ufw default allow outgoing
sudo ufw allow https ------------ port 443 -- HTTPS connections, which is what encrypted web servers
sudo ufw allow ssh -------------- port 22 -- Configure your server to allow incoming SSH connections
sudo ufw allow 22
sudo ufw enable ------------------------------------------------------Enable UFW
sudo ufw status ------------------------------------------------------check the status of the firewall
sudo ufw status verbose ----------------------------------------------check the status of UFW --- Display Rules
sudo ufw logging on --------------------------------------------------enable logging use
sudo ufw logging off -------------------------------------------------disable logging use
sudo ufw show raw
sudo ufw allow <service name> ----------------------------------------Allow by Service Name
sudo ufw deny <service name> -----------------------------------------Deny by Service Name
sudo ufw allow 22 ----------------------------------------------------Allow SSH Connections
ufw allow 22/tcp -----------------------------------------------------allow incoming connections on port 22 for TCP only
sudo ufw allow from 15.15.15.51 --------------------------------------Allow Specific IP Addresses
sudo ufw allow from 15.15.15.51 to any port 22 -----------------------specific port that the IP address is allowed to connect
sudo ufw allow from <target> to <destination> port <port number> -----Allow by specific port and IP address
sudo ufw allow in on eth0 to any port <22 > --------------------------public network interface called eth0
sudo ufw allow in on eth1 to any port <22> ---------------------------private network interface eth1
sudo ufw allow from 15.15.15.0/24 ------------------------------------allow a subnet of IP addresses, you can do so using CIDR notation to specify a netmask
sudo ufw deny http ---------------------------------------------------deny HTTP connections
sudo ufw deny from 15.15.15.51 ---------------------------------------deny all connections from 15.15.15.51
sudo ufw status numbered ---------------------------------------------list of your firewall rules
sudo ufw delete 2 ----------------------------------------------------delete rule 2
sudo ufw delete allow http -------------------------------------------remove the "allow http" rule
sudo ufw disable -----------------------------------------------------Disable UFW
sudo ufw reset -------------------------------------------------------Reset UFW Rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment