Secure AWS EC2 Ubuntu Instance through UFW Configuration

To secure AWS EC2 Ubuntu Instance through UFW first you need to check if UFW is enabled or not, if not then enable it and add rules, it’s not necessary it is to be enabled before adding rules, you can add up rules and can enable it later. In this post we will explain what exactly is UFW and how you can add security rules.

What is UFW ?

It is called as uncomplicated firewall. By uncomplicated it means its simple to configure. It is also called as host based firewall which acts as frontend for iptables. After the network based rules on AWS Security group UFW layer rules are evaluated for traffic transmission.

How to check if UFW is enabled or not ?

You can use below command to check if UFW is enabled or not:

$ sudo ufw status

If it is not enabled then status will be shown as inactive. If it is active then status will be shown as active.

UFW-Status

To enable UFW use below command:

$ sudo ufw enable

How to add rules in UFW configuration?

Its easy to add rules in UFW configuration, please read below steps to see how you can up different rules in configuration as per your usecase.

To allow all incoming http:

$ sudo ufw allow http

OR

$ sudo ufw allow 80

To allow all incoming https:

$ sudo ufw allow https

OR

$ sudo ufw allow 443

To allow all incoming ssh:

$ sudo ufw allow ssh

OR

$ sudo ufw allow 22

To allow incoming ssh from a fixed ip range:

$ sudo ufw allow from 10.11.12.0/24 to any port 22

To allow incoming on mysql port 3306 from a fixed ip range:

$ sudo ufw allow from 10.11.12.0/24 to any port 3306

To block all connections from a particular ip:

$ sudo ufw deny from 8.9.10.11

To block outbound connections on port 25:

$ sudo ufw deny out 25

How to check rules you have added?

For checking rules you added, you can check them using below command in a serial order.

$ sudo ufw status numbered

How to delete any rule?

For deleting any rule check its number through above command, and simply use below command:

$ sudo ufw delete 2

This will delete rule number 2, if you have to delete any other rule, please check ufw status numbered again as the rule numbers have changed their position due to rule number 2 deletion.

Help us Grow

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code