Thursday, November 12, 2020

how to use ufw firewall in ubuntu linux

 UFW is a frontend for managing firewall rules in Arch Linux, Debian, or Ubuntu. UFW is used through the command line (although it has GUIs available), and aims to make firewall configuration easy (or, uncomplicated).

Note : If you are running Docker, by default Docker directly manipulates iptables. Any UFW rules that you specify do not apply to Docker containers.


1) Install UFW firewall.


$ sudo apt-get update

$ sudo apt-get install ufw

$ sudo ufw status

$ sudo ufw enable


2) Allow and deny any service in ufw firewall, use the following command's.

  • allow ssh via service name

$ sudo ufw allow ssh   

  • allow ssh via port number

$ sudo ufw allow 22

  • deny ssh via service name

$ sudo ufw deny ssh

  • deny ssh via port number

$ sudo ufw deny 22

3) you can also allow packets based on TCP or UDP

$ sudo ufw allow 80/tcp

$ sudo ufw allow http/tcp


$ sudo ufw allow 1725/udp


4)  To allow connections from an IP address:


$ sudo ufw allow from 192.168.7.32

  • To allow connections from a specific subnet

$ sudo ufw allow from 198.51.100.0/24

 

5) To allow a specific IP address/port combination:


$ sudo ufw allow from 198.51.100.0 to any port 22 proto tcp


If you have a complex rule then there is a simple way to identify and delete the rule by its rule ID. Run the following command to get a list of all rules with their ID's:

 

$ sudo ufw status numbered

$ sudo ufw delete choose_number

1) Allow port  range

sudo ufw allow 10:6670/tcp

sudo ufw allow 10:6670/udp


2) Disable UFW firewall


$ sudo ufw disable


 If you want to turn off UFW completely and delete all the rules, you can use "reset" command:


$ sudo ufw reset

No comments:

Post a Comment

testing