Home > bash, linux > set up your firewall with UFW

set up your firewall with UFW

You have a Digital Ocean VPS with Ubuntu and you want to set up a firewall on it. However, iptables is too complicated. What to do?

Use UFW, the Uncomplicated Firewall. Say you want to open the SSH port and you have a webapp running on a specific port that you want to make accessible. Here is a basic setting:

#!/usr/bin/env bash

sudo ufw reset
sudo ufw disable

# SSH is on a custom port
sudo ufw allow 12345/tcp
# the webapp is listening here
sudo ufw allow 1234/tcp

sudo ufw default deny incoming
sudo ufw default allow outgoing

sudo ufw enable

sudo ufw status verbose

Warning! Make sure to add your SSH port! Otherwise you won’t be able to log in anymore!

Outgoing connections are allowed. Incoming connections are blocked except: 1) port 12345, and 2) port 1234.


Categories: bash, linux Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: