How to setup Firewall using GUFW in Ubuntu 16.04.

To setup Firewall using GUFW in Ubuntu 16.0

Setting up iptables firewall can be difficult for Linux beginners. Ubuntu has made it a little bit easier. GUFW, aka uncomplicated firewall, is the front end for iptables. Gufw on the other hand is the graphical front-end for UFW and it’ s one of the easiest firewalls in the world. It is so simple to setup firewall using GUFW in Ubuntu 16.0

Setting Up Firewall

To install Gufw, just open up a terminal and run the following command.

root@linuxhelp:~# apt-get install gufw
Reading package lists... Done
Building dependency tree      
.
Setting up gufw (16.04.1-0ubuntu1.1) ...

Now you can launch gufw in Unity Dash. By default, you have 3 different profiles: public, office and home. Here Home is chosen.

The most basic setup for a home computer is denying all incoming traffic and allowing all outgoing traffic. You will be able to surf the Internet. To achieve this, you just need to switch status from off to on.

To add your own firewall rules, click on the Rules tab then click on the plus sign. (You need to switch status on in order to add your own rules).

You can add firewall rule for a specific application such as 0 A.D. or a protocol such as SSH.


Let’ s say you want to disable SSH login on your Ubuntu 16.04 desktop, i.e. you don’ t allow other computers to SSH into your Ubuntu machine but at the same time you want to SSH into another computer from you Ubuntu 16.04 desktop, all you need to do is set policy to Deny, select In as the direction, select Network in category, select Services in subcategory, selectSSH in application and click the Add button.

You will see a new firewall in the Rules tab.

If you like to play with the command line, here’ s the command to check ufw status.

root@linuxhelp:~# ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     DENY        Anywhere                  
22/tcp (v6)                DENY        Anywhere (v6)     

To enable Gufw on system startup, enter this command.

root@linuxhelp:~# ufw enable


Firewall is active and enabled on system startup.

Overall, UFW is able to protect your VPS against the most common hacking attempts. Of course, your security measures should be more detailed than just using UFW. However, it is a good (and necessary) start.

FAQ
Q
Is SSH a TCP or UDP?
A
SSH needs port 22/tcp. You're asking if opening 22/tcp and 22/udp presents a security vulnerability. The answer is "no" if nothing is listening to 22/udp.
Q
What is Dport in firewall?
A
--dport stands for DESTINATION port. This matches against the target port of the connection. --sport stands for SOURCE port. This is the port on which the packet originated. For example, all http connections have DPORT 80 for packets from client->server, and SPORT 80 for server->client.
Q
What is iptables Linux?
A
iptables is a user-space utility program that allows a system administrator to configure the tables provided by the Linux kernel firewall (implemented as different Netfilter modules) and the chains and rules it stores.The term iptables is also commonly used to inclusively refer to the kernel-level components.
Q
What is UFW Ubuntu?
A
The default firewall configuration tool for Ubuntu is ufw. Developed to ease iptables firewall configuration, ufw provides a user friendly way to create an IPv4 or IPv6 host-based firewall. By default UFW is disabled. Gufw is a GUI that is available as a frontend
Q
After installing ufw also my 80 port is not accessible ?
A
you have to allow it in ufw using following command

# UFW allow 80