Skip to content

Instantly share code, notes, and snippets.

@linuxdevhub
Last active April 22, 2020 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuxdevhub/39d4145a8ac172e31cc8ca0f14d317dd to your computer and use it in GitHub Desktop.
Save linuxdevhub/39d4145a8ac172e31cc8ca0f14d317dd to your computer and use it in GitHub Desktop.
#
# UFW, or Uncomplicated Firewall, is an interface to iptables that is geared towards simplifying
# the process of configuring a firewall. While iptables is a solid and flexible tool, it can be difficult for beginners
# to learn how to use it to properly configure a firewall. If you’re looking to get started securing your network,
# and you’re not sure which tool to use, UFW may be the right choice for you.
#
#This tutorial will show you how to set up a firewall with UFW on Ubuntu 18.04.
#
# Installation
# UFW is installed by default on Ubuntu. If it has been uninstalled for some reason, you can install it with
sudo apt install ufw
# Enabling ufw
sudo ufw enable
# Setup default policy
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Allowing SSH Connections
sudo ufw allow ssh
# or
sudo ufw allow 22
# Allowing Other Connections
sudo ufw allow http
#or
sudo ufw allow 80
# NOTE: if you dont specify tcp/udp, then it will apply on both, but you can setup for tcp/udp only, like this:
sudo ufw allow 80/tcp
sudo ufw allow https
#or
sudo ufw allow 443
# Allow Specific Port Ranges for example
sudo ufw allow 6000:6007/tcp
sudo ufw allow 6000:6007/udp
#Advanced Rules
#To allow connections from an IP address:
sudo ufw allow from 204.61.105.10
#To allow connections from a specific subnet:
sudo ufw allow from 204.61.105.10/24
#To allow a specific IP address/port combination:
sudo ufw allow from 204.61.105.10 to any port 22 proto tcp
# Remove a rule
sudo ufw delete allow 80
# See the rules that are currently set
sudo ufw status verbose
# disable ufw
sudo ufw disable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment